Building your chatbot with Mailchimp
For this tutorial, the first bot we will setup is a Mailchimp chatbot!
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.
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 miliseconds).
We then move 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
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 event as nlFirstname,
nlFirstname will then be accessible anywhere,
Let's move to the next step :
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
Now that our button is saved, we then create a
Question component, add the preset
As the user answers, we check if the input matches the button or what it accepts ans remember the appropriate
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
Sending data to Mailchimp
Thanks to our app store, 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 function needs an option parameter that encloses
all the informations that Mailchimp needs.
Function(...) needs to be used between
Finally, moving on to feedbacks :D
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
That's it !
You've done it, you've created your first CSML bot from scratch !
Here is the full code below:
If you have any question, please come ask us on Slack!