Skip to main content

Class: MessagingUtils

Defined in: core/src/MessagingUtils.ts:123

Simple utility class for sending templated messages via e-mail, SMS and more.

Constructors​

Constructor​

new MessagingUtils(): MessagingUtils

Returns​

MessagingUtils

Properties​

slackApps​

protected slackApps: any[] = []

Defined in: core/src/MessagingUtils.ts:124


slackConfigs​

protected slackConfigs: any[] = []

Defined in: core/src/MessagingUtils.ts:126

Methods​

init()​

init(): Promise<void>

Defined in: core/src/MessagingUtils.ts:159

Returns​

Promise<void>


loadTemplate()​

loadTemplate(name): Promise<Template>

Defined in: core/src/MessagingUtils.ts:258

Loads the template with the given name and returns its contents as a string.

Parameters​

name​

string

The name of the template to load.

Returns​

Promise<Template>


sendEmail()​

sendEmail(templateName, templateVars, options?): Promise<any>

Defined in: core/src/MessagingUtils.ts:339

Sends an email using the given template name and variables.

Parameters​

templateName​

string

The name of the email template to send.

templateVars​

any

The map of variables to inject into the template.

options?​

any = {}

The map of additional options to pass into the sendMail function.

Returns​

Promise<any>


sendSlack()​

sendSlack(templateName, templateVars): Promise<any[] | undefined>

Defined in: core/src/MessagingUtils.ts:385

Sends an Slack message using the given template name and variables.

Parameters​

templateName​

string

The name of the Slack template to send.

templateVars​

any

The map of variables to inject into the template.

Returns​

Promise<any[] | undefined>


sendSMS()​

sendSMS(templateName, templateVars, options?): Promise<any>

Defined in: core/src/MessagingUtils.ts:500

Sends an SMS using the given template name and variables.

The provider is chosen by configuration: set sms_provider to twilio or telnyx to select one explicitly, otherwise Twilio is used if configured and Telnyx if not. Both send from from.sms and take the recipient (to) from options. Telnyx messages are sent through its Messaging API.

Parameters​

templateName​

string

The name of the SMS template to send.

templateVars​

any

The map of variables to inject into the template.

options?​

any = {}

The map of additional options to pass to the SMS provider. Must include the recipient as to.

Returns​

Promise<any>

The provider's message resource.


sendWhatsApp()​

sendWhatsApp(templateName, templateVars, options?): Promise<any>

Defined in: core/src/MessagingUtils.ts:555

Sends a WhatsApp message using the given template name and variables, through the WhatsApp Business Cloud API.

The message is sent from the configured whatsapp.phoneNumberId to the recipient given as options.to. If the template defines whatsapp_template an approved WhatsApp message template is sent, whose parameters are rendered with the template variables. Otherwise the whatsapp text is sent as a free-form message, which WhatsApp only delivers within 24 hours of the recipient's last message to you.

Parameters​

templateName​

string

The name of the WhatsApp template to send.

templateVars​

any

The map of variables to inject into the template.

options?​

any = {}

The map of additional options to pass into the request. Must include the recipient as to.

Returns​

Promise<any>

The WhatsApp response (contacts and messages). Delivery is asynchronous; a resolved promise means WhatsApp accepted the message, not that it reached the recipient.