import * as plugins from '../plugins.js'; import { EmailService } from './email.classes.emailservice.js'; import { logger } from '../logger.js'; export class ApiManager { public emailRef: EmailService; public typedRouter = new plugins.typedrequest.TypedRouter(); constructor(emailRefArg: EmailService) { this.emailRef = emailRefArg; this.emailRef.typedrouter.addTypedRouter(this.typedRouter); this.typedRouter.addTypedHandler( new plugins.typedrequest.TypedHandler('sendEmail', async (requestData) => { const mailToSend = new plugins.smartmail.Smartmail({ body: requestData.body, from: requestData.from, subject: requestData.title, }); if (requestData.attachments) { for (const attachment of requestData.attachments) { mailToSend.addAttachment( await plugins.smartfile.SmartFile.fromString( attachment.name, attachment.binaryAttachmentString, 'binary' ) ); } } await this.emailRef.mailgunConnector.sendEmail(mailToSend, requestData.to, {}); logger.log( 'info', `send an email to ${requestData.to} with subject '${mailToSend.getSubject()}'`, { eventType: 'sentEmail', email: { to: requestData.to, subject: mailToSend.getSubject(), }, } ); return { responseId: 'abc', // TODO: generate proper response id }; }) ); } }