top of page

Building a Chatbot

Updated: Sep 9, 2023


Log into your Twilio account and navigate to the Studio Dashboard, then click to create a 'new flow'.


Call the workflow anything you like;


You’ll be presented with a Trigger widget, which starts the flow when the specified trigger is fired. This can be a phone call, sms or REST API. For this example and map, the trigger is going to be an incoming message, since we want users who text the number to reach the chatbot.


Prompt User for Input


Drag a 'Send & Wait For Reply' widget onto the canvas, and then connect it to the 'Incoming Message' trigger by dragging the red dot to the grey dot in the corner of the new widget. This widget will be used to send an SMS to the user with a prompt to reply to. In this case, I chose to ask the user if they would like a copy of my CV or leave a message and then await a response with one of the options that is specified.


Split Based on Input


You want to make sure that the use receives an option from my list, so in order for that to happen you need to use a 'Split Based On' widget to distinguish valid inputs from other messages. Set the variable to test in the right sidebar. Find the 'Send & Wait For Reply' widget in the dropdown, and select 'inbound.Body' from the list, this will capture the reply to your prompt.


After this you need to declare the choices you’re looking for in those responses. In this case ‘enter options here’ which is a choice of 'CV in word format', 'CV in pdf format' or to 'Leave A Message'.

Tap the red 'New' at the bottom of the Split widget to reveal the 'Transition On...' dropdown menu. Select 'Condition Matches' to create a new Transition.


In the right sidebar, find the new Transition that you have just created, and select 'Matches Any Of' from the dropdown.


You can now go ahead and set the values to anything you like, I chose 'cvWord', 'cvPdf', 'leaveMessage', to include all of your contact options. Save the new transition and it will appear on the widget.


I continued to Map out my journey until it looked like the below.




Triggering The Twilio Function


If the user enters something that the bot recognises;


e.g. starts the process.


it should send a request to our admin system so the request can be fulfilled. The Twilio Function widget will help us do this; drag the widget onto the canvas and connect it to the Transition you just created.


Before you can configure the widget you need to create a Twilio Function. Go to the Manage Twilio Functions section of the Twilio Console and create a new Function with a blank template.


Fulfil Request


So, now you will need to log your request, which you could write at this point to a database for example. Give it a name like “CV request” and a path such as “/create-request”.


Afterwards insert the following code:


exports.handler = function(context, event, callback) {
console.log(event.cirriculumVitae);
callback(null, 'success');
};

Save the Function and go back to the Function widget inside Twilio Studio flow. Pick your Twilio Function in the 'Function URL' dropdown menu in the right sidebar. You can also add a parameter to the request. Scroll down to the section for 'Function Parameters', and create a field called CV.


The value can then be set to the same variable we’re checking in our split above:


{

widgets.request_prompt.inbound.Body

}


where request_prompt matches the name of your initial prompt widget.


The request will then go out to your Admin API and the user will get the CV in the format they requested.


Log showing successful interaction between the User and Admin API can be seen below.











(As of January 3rd The Chatbot Is Pending Review & Article Possible Revision)

0 views0 comments

Recent Posts

See All
bottom of page