Schedule push notifications using the Scheduler App
The first step of building a chatbot is obviously to get the chatbot to answer to users, but anyone who deployed a chatbot knows that chatbots should be able to go one step further and send messages to users on their own. This is really useful for use cases like e-commerce, daily quizz, reminder, etc...
At CSML we thought that on the top of broadcasting a bunch of messages to a population at the same time, it'd be nice to get chatbots to send messages at specific time for each users. This is why we created the Scheduler App.
The Scheduler App allows you to:
- Plan a message to be sent at a specific time to a user
- Plan to call a webhook at a specific time
- Cancel previously planed events
How does the Scheduler actually work?
To activate the app, you need to write a line like the one below in your CSML code:
do futureMessage = App("utils/scheduler", action="broadcast", delay="5 hrs", flow_id="Reminder", metadata={"cart":"1 lipstick"})
When the user will talk to your chatbot, and reach out this line, the chatbot will remember that it has to send a send a message to this very user in 5 hours. Actually, rather than a message, an actual flow will be triggered, in this case a flow called Reminder
, and a metadata will be injected.
The interesting thing about this is that each user can then receive a message from the bot 5 hours after reaching this line in the bot.
Let's check out a real life use case!
As said above, this feature makes a lot of sense for e-commerce for instance. Let's review the use case and how the Scheduler solves it.
For a e-commerce chatbot we'd like to:
- When a user put something in his/her cart, we want to plan to send him/her a message 5 hours later
- If the user goes through with the purchase, we want to: cancel the planed message and call a Zapier webhook at 8am, this webhook will notify me in the morning that a purchase was made.
Handling the unfinished purchase reminder
In this case we won't need to write much more than the line above, we're just going to add some actual content.
start:
say QuickReply("What item would you like to purchase?",
buttons=[
Button("Lipstick 💄"),
Button("Sun glasses 🕶")
])
hold
remember cart = event
say "Ok I have added 1 {{event}} to your cart!"
// Once the chatbot add an item in the cart, it will trigger
// the `Reminder` flow 5 hours later if the user leaves
// We keep what the app returns as we'll need it for later if we need to cancel it.
remember futureMessage = App("utils/scheduler",
action="broadcast",
delay="5 hrs",
flow_id="Reminder",
metadata={"cart": cart})
goto flow Payment
What is in the Reminder flow?
The reminder flow should contain messages that get the customer back in the purchase process, here is an exemple:
start:
say "It looks like you have {{_metadata.cart}} in your cart but have not finished your purchase."
say "Let's do it together so you can get you {{_metadata.cart}} as soon as possible!"
goto flow Payment
Handling cancelling an event and calling a webhook
What should happen if the user go through with the payment ? We then cancel the reminder!
start:
say "Thank you for your purchase!"
say "You will receive your item within 3 business day."
say "Have a great day!"
// Let's cancel the reminder here
do App("utils/scheduler", action="cancel", schedule_id=futureMessage)
// And we plan a webhook call to get an email notification in the morning
do App("utils/scheduler", action="webhook", schedule_time="2021-06-14 08:00:00", url="https://my-custom-webhook-to-send-emails.com")
goto end
That's it!
Your chatbot now handles reminders, it can schedule one, cancel it, schedule a webhook call. You won't need to monitor anything, CSML Studio will manage everything for you!
The Scheduler App is part of the free plan so you can use it as much as you want 😇