Create Your First Bot
Introduction
In this tutorial, you will learn how to setup a chatbot that will qualify leads and sign them up to your Mailchimp contact list.
At the end of this tutorial, here is what you will be able to:
Get information from the end-user
Subscribe this user to an existing Mailchimp contact list
Ask users for feedback on their experience, and send a custom answer based on their response
Writing your CSML flow
A CSML flow always starts in the start step, in this step, we introduce the chatbot.
Note that Typing(2000) needs to be preceded by the say keyword, this will show the three little jumping dots on the screen, suggesting the chatbot is typing, this action will last 2 seconds (2000 milliseconds).
start:
say Typing(2000)
say "Hi π€, I just need a few informations in order to add you to my mailing list."
goto firstnameWe can then move on to the next step in which we will start asking for user informations.
Asking questions and remembering answers
With CSML, in order to wait for the user to reply to a question (or anything else for that matter), we use the keyword hold, the chatbot then waits for the user to reply. After answering, the user input will be placed in the event variable.
Note: the event variable is scoped to the current step, which basically means that event will be wiped off the memory once the chatbot goes out of the current step.
In order to remember what the user said, we can ask the chat to remember nlFirstname = event, and nlFirstname will then be accessible anywhere, anytime.
Let's move to the next step : lastname
First let's have a look at the Button(...) component: it has two parameters, a title="" that represents what will be displayed inside the button, and an accept=[] parameter that is a list of all the words that correspond to this button. This way, if a user types "NA", CSML will understand it as being the same as a click on this button. Lastly, we set this button as variable btnLastname.
Now that our button is saved, we then create a Question component, add the preset button and hold.
As the user answers, we check if the input matches the button or what it accepts ans remember the appropriate nlLastname.
The same goes with the email, only this time we're checking if the user input contains a @, if it doesn't we start the step again, otherwise we remember the email and move on to save everything.
Sending data to Mailchimp
Thanks to our apps directory, you can install the Mailchimp app in a few clicks (you'll just need to get your API Region, API key and contact list ID). The app needs an option parameter that encloses all the informations that Mailchimp needs.
Note that App(...) needs to be used in a do statement.
Now it's time to get some feedback from the user!
NLP coming into play
We want to use the SAP Conversational AI to find out if the user's input is positive, neutral or negative. The API returns this as sentiments. If you want to see the full response from the API, you can print it using say "{{sapcaiResponse}}"
That's it !
You've done it, you've created your first CSML bot from scratch ! Here is the full code:
If you have any question, please come ask us on Slack!
Last updated
Was this helpful?