UNPKG

@sonatel-os/juf

Version:

It's an helpful Javascript Utility Framework to ease application development in SONATEL context.

117 lines (116 loc) 4.04 kB
export default Communication; /** * Communication * @namespace Service\Communication */ /** * @class Communication * @classdesc Provides methods for sending emails and SMS through the Apigee API. * Handles authentication, constructs requests, and processes responses. * * @example * // Initialize the communication service * const commService = Communication.init(); * * // Send an email * communication.sendEmail({ * subject: 'Hello!', * to: 'recipient@example.com', * from: 'sender@example.com', * body: '<p>This is a test email.</p>', * html: true * }); * * // Send an SMS * communication.sendSMS({ * body: 'This is a test SMS.', * to: '+1234567890' * }); */ declare class Communication { /** * Factory method to initialize Communication with the provided configuration. * @method init * @memberof Service\Communication * @returns {Communication} An initialized instance of Communication. */ static init(): Communication; /** * @async * @method sendEmail * @memberof Service\Communication * @description Sends an email through the Apigee API using the provided parameters. * * @param {Object} emailParams - Parameters for the email to be sent. * @param {string} emailParams.subject - The subject of the email. * @param {string} emailParams.to - The email address of the recipient. * @param {string} emailParams.from - The email address of the sender. * @param {string} emailParams.body - The plaintext body of the email. * @param {boolean} [emailParams.html] - The HTML body of the email (optional). * @returns {Promise<{ id: string, status: string } | { message: string, status: 500 }>} The response data and HTTP status from the Apigee API. * * @throws {Promise<{status: number, message: string}>} Throws an error object with status and message if the request fails. * * @example * communication.sendEmail({ * subject: 'Hello!', * to: 'recipient@example.com', * from: 'sender@example.com', * body: '<p>This is a test email.</p>', * html: true * }); */ sendEmail({ subject, to, from, body, html }: { subject: string; to: string; from: string; body: string; html?: boolean | undefined; }): Promise<{ id: string; status: string; } | { message: string; status: 500; }>; /** * @async * @method sendSMS * @memberof Service\Communication * @description Sends an SMS through the Apigee API using the provided parameters. * * @param {Object} smsParams - Parameters for the SMS to be sent. * @param {string} smsParams.body - The message body of the SMS. * @param {boolean} [smsParams.confidential=true] - Whether the message is confidential or not (default is true). * @param {string} [smsParams.scheduledFor] - The scheduled time for the message to be sent (ISO 8601 format). * @param {string} smsParams.senderName - The name of the sender. * @param {string} smsParams.to - The phone number of the recipient. * @returns {Promise<{data: { id: string, status: string }, status: number} | { message: string, status: number }>} The response data and HTTP status from the Apigee API. * * @throws {Promise<{status: number, message: string}>} Throws an error object with status and message if the request fails. * * @example * * communication.sendSMS({ * body: 'This is a test SMS.', * to: '+1234567890' * }); */ sendSMS({ body, confidential, scheduledFor, senderName, to }: { body: string; confidential?: boolean | undefined; scheduledFor?: string | undefined; senderName: string; to: string; }): Promise<{ data: { id: string; status: string; }; status: number; } | { message: string; status: number; }>; #private; }