enabling commonly needed services like mail sending, letter sending, phone calling, ai functions for clusters.
Go to file
2024-05-11 12:33:15 +02:00
.gitea/workflows fix(core): update 2024-02-15 20:30:38 +01:00
.vscode fix(core): update 2024-02-15 20:30:38 +01:00
test fix(core): update 2024-03-19 18:37:24 +01:00
ts fix(core): update 2024-05-11 12:33:14 +02:00
.dockerignore fix(core): update 2024-02-15 20:30:38 +01:00
.gitignore fix(core): update 2024-02-15 20:30:38 +01:00
cli.child.ts fix(core): update 2024-02-15 20:30:38 +01:00
cli.js fix(core): update 2024-02-15 20:30:38 +01:00
cli.ts.js fix(core): update 2024-02-15 20:30:38 +01:00
Dockerfile fix(core): update 2024-02-15 20:30:38 +01:00
npmextra.json fix(core): update 2024-05-11 12:33:14 +02:00
package.json 1.0.11 2024-05-11 12:33:15 +02:00
pnpm-lock.yaml fix(core): update 2024-04-01 02:58:27 +02:00
readme.hints.md fix(core): update 2024-05-11 12:33:14 +02:00
readme.md fix(core): update 2024-05-11 12:33:14 +02:00
tsconfig.json fix(core): update 2024-02-15 20:30:38 +01:00

@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