.gitea/workflows | ||
.vscode | ||
test | ||
ts | ||
.dockerignore | ||
.gitignore | ||
cli.child.ts | ||
cli.js | ||
cli.ts.js | ||
Dockerfile | ||
npmextra.json | ||
package.json | ||
pnpm-lock.yaml | ||
readme.hints.md | ||
readme.md | ||
tsconfig.json |
@serve.zone/platformservice
contains the platformservice container with mail, sms, letter, ai services.
Install
To install @serve.zone/platformservice
, run the following command:
npm install @serve.zone/platformservice --save
Make sure you have Node.js and npm installed on your system to use this package.
Usage
This document provides extensive usage scenarios for the @serve.zone/platformservice
, a comprehensive ESM module written in TypeScript offering a wide range of services such as mail, SMS, letter, and artificial intelligence (AI) functionalities. This service is an exemplar of a modular design, allowing users to leverage various communication methods and AI services efficiently. Key features provided by this platform include sending and receiving emails, managing SMS services, letter dispatching, and utilizing AI for diverse purposes.
Prerequisites
Before diving into the examples, ensure you have the platform service installed and configured correctly. The package leverages environment variables for configuration, so you must set up the necessary variables, including service endpoints, authentication tokens, and database connections.
Initialization
First, initialize the platform service, ensuring all dependencies are correctly loaded and configured:
import { SzPlatformService } from '@serve.zone/platformservice';
async function initService() {
const platformService = new SzPlatformService();
await platformService.start();
console.log('Platform service initialized successfully.');
}
initService();
Sending Emails
One of the primary services offered is email management. Here's how to send an email using the platform service:
import { EmailService, IEmailOptions } from '@serve.zone/platformservice';
async function sendEmail() {
const emailOptions: IEmailOptions = {
from: 'no-reply@example.com',
to: 'recipient@example.com',
subject: 'Test Email',
body: '<h1>This is a test email</h1>',
};
const emailService = new EmailService('MAILGUN_API_KEY'); // Replace with your real API key
await emailService.sendEmail(emailOptions);
console.log('Email sent successfully.');
}
sendEmail();
Managing SMS
Similar to email, the platform also facilitates SMS sending:
import { SmsService, ISmsConstructorOptions } from '@serve.zone/platformservice';
async function sendSms() {
const smsOptions: ISmsConstructorOptions = {
apiGatewayApiToken: 'SMS_API_TOKEN', // Replace with your real token
};
const smsService = new SmsService(smsOptions);
await smsService.sendSms(1234567890, 'SENDER_NAME', 'This is a test SMS.');
console.log('SMS sent successfully.');
}
sendSms();
Dispatching Letters
For physical mail correspondence, the platform provides a letter service:
import { LetterService, ILetterConstructorOptions } from '@serve.zone/platformservice';
async function sendLetter() {
const letterOptions: ILetterConstructorOptions = {
letterxpressUser: 'USER',
letterxpressToken: 'TOKEN',
};
const letterService = new LetterService(letterOptions);
await letterService.sendLetter('This is a test letter body.', {address: 'Recipient Address', name: 'Recipient Name'});
console.log('Letter dispatched successfully.');
}
sendLetter();
Leveraging AI Services
The platform also integrates AI functionalities, allowing for innovative use cases like generating content, analyzing text, or automating responses:
import { AiService } from '@serve.zone/platformservice';
async function useAiService() {
const aiService = new AiService('OPENAI_API_KEY'); // Replace with your real API key
const response = await aiService.generateText('Prompt for the AI service.');
console.log(`AI response: ${response}`);
}
useAiService();
Conclusion
The @serve.zone/platformservice
offers a robust set of features for modern application requirements, including but not limited to communication and AI services. By following the examples above, developers can integrate these services into their applications, harnessing the power of email, SMS, letters, and artificial intelligence seamlessly.
undefined