# @serve.zone/platformservice contains the platformservice container with mail, sms, letter, ai services. ## Install To install `@serve.zone/platformservice`, run the following command: ```sh 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: ```ts 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: ```ts 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: '
This is a test email
', attachments: [] // Optional attachments }); const emailId = await mtaService.send(email); console.log(`Email queued with ID: ${emailId}`); // Check email status const status = mtaService.getEmailStatus(emailId); console.log(`Email status: ${status.status}`); // Set up API for external access const apiManager = new ApiManager(mtaService); await apiManager.start(3000); console.log('MTA API running on port 3000'); } useMtaService(); ``` The MTA provides key advantages for applications requiring: - High-volume email sending - Compliance with email authentication standards - Detailed delivery tracking - Custom email handling logic - Multi-domain email management - Complete control over email infrastructure ### Leveraging AI Services The platform also integrates AI functionalities, allowing for innovative use cases like generating content, analyzing text, or automating responses: ```ts 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, MTA capabilities, and artificial intelligence seamlessly.