SMS notifications¶
It is possible to send SMS messages from the bot to notify users of important events that require attention.
Programmatically sending SMS messages is done using the sms_notify()
function.
Installation¶
Sending SMS messages is integrated via Twilio programmable SMS, so you need a Twilio account set up. Additionally, you need to create an SMS service resource using the Twilio console. This will give you the service ID that you need.
To integrate into DialoX, create a YAML file called twilio
in your
bot, and add the credentials from Twilio:
sms_notify:
account_sid: "ACa70df98e790a87d98a7fd98d79fae876"
service_sid: "MG805ad87f5d907f5e9a875d97a5f70aed"
token: "78ffff87aed07a0d868976a0d896fda8"
Usage¶
After you have set up your bot with the Twilio credentials you can use
the sms_notify()
function. It takes a phone number and a message:
dialog sms_test do
sms_notify("+31641234567", "I have a message for you!")
end
The phone number must be specified in full international format, e.g. +31641345678. The sender of the SMS is configured by your Twilio SMS service.
Linking back to the chat¶
Using the shorten_url()
function combined with chat_link()
, you
can create a link back into the conversation:
dialog sms_test do
url = shorten_url(chat_link("web_pwa", user_id: user.user_id))
sms_notify("+31641234567", "I have a message for you, read it here: #{url}")
end
SMS Call deflection¶
When handling phone calls, it can be useful to temporarily deflect the caller to a web interface to complete certain tasks that are difficult to do over the phone, such as filling out forms or uploading documents. The sms()
function can be used to send the caller a link to continue the conversation on the web, while keeping them on hold.
Here's an example of how to implement call deflection:
# main.yaml
# This is the dialog that handles the phone call and sends the SMS
dialog __main__ when conversation.frontend == "phone" do
say "Hello, I will send you a link"
sms(user.phone, "This is your link: ", chat_link: true)
await input_method("wait",
caption: "Please click the link in the SMS message and fill out the form.",
wait_time: 2,
event: "form_filled"
)
say "You answered: " + event.payload.street + " " + event.payload.city
say "Goodbye"
close
end
# This is the dialog that handles the web form submission
dialog __main__ when conversation.originator do
say "Welcome."
ask "Please enter your address", expecting: input_method("form", @forms.address)
emit "form_filled", answer.data, to: conversation.originator.addr
say "Thanks."
close
end
# forms.yaml
address:
caption: Shipping address
height: tall
schema:
type: object
properties:
street:
type: string
title: Street
city:
type: string
title: City
required: ["street", "city"]
ui_schema:
ui:order:
- street
- city
- "*"
comments:
ui:widget: textarea