SMS notifications
Level: Intermediate
Keywords: notifications, sms, SMTP, ScriptingAPI
The result: Send SMS via SMTP server
For sending SMS, the SMTP server by the MobilChange service is used, but in general any SMTP server can by used.
SMTP server​
At first, we need to configure the SMTP server. Add following configuration in tenant file ..\lids-bussines-service\tenants\tenantName.json.
{
"email" : {
"type" : "SMTP",
"smtpConfiguration": {
"server" : "{$sms_smtp_server}",
"port" : "{$sms_smtp_port}",
"user" : "{$smtp_user}", // optional
"password" : "{$smtp_password}", // optional
"useSSL" : "{$smtp_useSSL}" // optional
"defaultSubject" : "{$sms_smtp_default_subject}", // optional
"defaultSender" : "{$sms_smtp_default_sender}", // optional
"defaultDomain" : "{$sms_smtp_default_domain}" // optional
}
}
}
Sending using action step​
In the following example, if the action is invoked on an entity instance, we can access the entity instance directly from the data model. We also have access to the environment variables here. In the template, we can then access each attribute of the entity.
{
"type": "sendSMS",
"to": [
"{#request.applicant.phone}@{$sms_smtp_default_domain}"
],
"templateGroup": "test",
"template": "requests/testSMSTemplate"
}
More definition about Send SMS step can be found in Business Server Configuration.
Sending using ScriptingAPI​
In the following example, the message is sent as an SMS using the Scripting API.
api.messages().prepareSendSMS(context)
.addRecipient(context.variables.smsNumberPrefix + profile.at_reqParticipant__phone_number + "@" + context.variables.sms_smtp_default_domain)
.model({
portalUrl: url,
userProfile: userProfile
})
.sender(context.variables.sms_smtp_default_sender)
.template("userRegisteredSMS")
.templateGroup("common")
.send();