Month: April 2021

  • A multi-tenant chatbot with Dialogflow — Part 2 ( Implementation)

    A multi-tenant chatbot with Dialogflow — Part 2 ( Implementation)

    This article is a follow-up on my previous article on multi-tenant-chatbot with Dialogflow. Here, I am going to describe a step-by-step implementation of a multi-tenant Smart Attendant using Dialogflow described in my previous article.

    Step 0: Clone my Github repo

    maheshmahadevan/multi-tenant-chatbot

    git clone https://github.com/maheshmahadevan/multi-tenant-chatbot

    Step 1: Get a Dialogflow account

    Go and sign up for Dialogflow ES services which offer basic Dialogflow features for free. Details on different offerings, pricing, and link to sign up are present here.

    Step 2: Setup Agent and Intents

    Once you have an account, you will need to set up an Agent, Intents, and Fulfillment webhook to get this working. In this step, we will cover the creation of the Agent and different Intents required for Smart Attendant.

    Create a new agent and name it. This will also create a new GCP project for you which we will need to use in the future to call our agent via API

    Create a new agent and name it.

    Create a New Intent and name it “SmartAttendant”

    Add an outgoing context to this called “smartattendant-level1”. This context will help initiate our follow up intent.

    Fill in an event and training phrase to trigger this Intent. You only need one of them, but for the purposes of this exercise and testing we will add both.

    Add a default response to the Intent, ideally if we pass the right data this response should never be returned. Enable webhook call which will invoke the fulfillment API to add the tenant-specific response to this Intent. Details on how to setup fulfillment API are below.

    Save the Intent. We need to add two more follow-up Intents. This Intent will serve as an entry point for the caller.

    Before creating additional follow-up Intents, let’s create an Entity for Department. Entities are types in Dialogflow that help us extract Parameters from user inputs. In this scenario, we are looking to extract department names such as Sales, Service, etc from user input.

    Next, create another Intent and update the input and output context as shown. Please note the input context for this Intent is same as output context from previous Intent.

    Create two parameters called level1_dept and level2_dept and link them to the entity department we created previously. You can also mark level1_dept as a required field and add a default prompt in case it is not provided by user

    Add few training phrases for this Intent and suggest what the department names could be in those phrases. Also, Enable fulfillment webhook for this Intent

    Create the next Intent to capture second-level departments when needed. Update the input context accordingly. There is no need for an output context here as this is supposedly our final Intent

    Add the Training phrase and parameters. Please note, in order to carry forward the parameters from previous contexts, Dialogflow expects a “special syntax” in the value field as seen in the screenshot below. You can read in detail about this syntax here. Just like previous two Intenets, Enable fulfillment webhook on this Intent as well.

    Trending Bot Articles:

    1. Chatbot Trends Report 2021

    2. 4 DO’s and 3 DON’Ts for Training a Chatbot NLP Model

    3. Concierge Bot: Handle Multiple Chatbots from One Chat Screen

    4. An expert system: Conversational AI Vs Chatbots

    Step 3: Set up Authentication

    Please follow the steps mentioned in this article to setup GCP authentication for the project. This is required to call Dialogflow agent via REST API from your local machine. You can get the name of the project from the Dialogflow agent dashboard.

    Step 4: Set up Fulfillment Webhook

    Enable fulfillment webhook by using the Inline editor checkbox. You can also create a webhook outside of Dialogflow, but this is outside the scope of this article.

    As soon as you enable the Inline Editor on Fulfillment, you will notice a pop-up as illustrated below. What this means is that you will have to set up your billing on the corresponding google cloud project in order to use this functionality. If you only intend to use this project for learning/development purposes, the first 2 million invocations of cloud functions every month are free ( as of 26th March 2021), so you should be covered unless you decide to go beyond that number of invocations. Please refer to their official pricing information page for more details.

    Once the billing is enabled, copy the fulfillment-index.js and package.json from multi-tenant-chatbot/fulfillment-api folder of the cloned repository.

    Press Deploy and wait for it to finish the deployment on the GCP.

    Step 5: Invoke Intent Detection Rest API

    Go to the cloned repository of multi-tenant-chatbot and run npm install command

    Start the server once the npm install command is finished

    > npm install
    ... ** Wait for the install to finish **
    > node server.js
    Started listening at port - 3000

    Call the rest end-point to initiate conversation with SmartAttendant.

    The first call will invoke the Smart Attendant using the event. In addition, you will need to also pass a couple of custom payload information for customer identification and the time of the day when this call is initiated. These payload data are in turn forwarded to fulfillment-api webhook which uses them to identify the correct response to be sent back to the user as per the configuration.

    ---First call to initiate Smart Attendant for customer abc_car during the afternoon time. Feel free to change the time to evening to see the response---
    curl -X POST -H 'Content-Type: application/json' http://localhost:3000/intent/detectintent -d '{ "projectId": "<YOUR_GCP_PROJECT>", "event": "SMART_ATTENDANT", "languageCode" : "en-US", "payload" : { "fields" : { "customer" : { "stringValue": "abc_car", "kind": "stringValue" }, "time" : { "stringValue": "afternoon", "kind": "stringValue" } } } }'
    ---Response---
    {
    "sessionId": "dfeaacwf-6d7f-4a05-ab3e-da2b98f72c2b",
    "responseText": "Welcome to ABC Car Dealership, please say in words where you want to redirect your call , for example , say Sales or Connect me to Service"
    }

    I am sure you might be wondering what is the relevance of sessionId in the response. SessionId field in the Intent Detection API manages and binds the contexts of Intents over multiple calls. In short, we will need to pass this context in our subsequent call for Dialogflow to bind the query to this session. Any contexts and their parameters stored in the session will be available for fulfillment of the query bound with that specific session.

    ---Second call.User wishes to speak to a Sales agent, use the sessionId from first response in the input json. ---
    curl -X POST -H 'Content-Type: application/json' http://localhost:3000/intent/detectintent -d '{ "sessionId": "<SESSION_ID_FROM_PREVIOUS_RESPONSE>", "projectId": "<YOUR_GCP_PROJECT>", "query": "Sales please", "languageCode" : "en-US", "payload" : { "fields" : { "customer" : { "stringValue": "abc_car", "kind": "stringValue" }, "time" : { "stringValue": "afternoon", "kind": "stringValue" } } } }'
    --Response. Since this particular Departments has sub-departments, the intent responds back asking to which specific Sales department does User wish to speak---
    {"sessionId":"<SESSION_ID_FROM_PREVIOUS_RESPONSE>",
    "responseText":"BMW , Audi or Mercedes"}
    ---Third Call ... User wishes to speak to a Mercedes agent.---
    curl -X POST -H 'Content-Type: application/json' http://localhost:3000/intent/detectintent -d '{ "sessionId": "<SESSION_ID_FROM_PREVIOUS_RESPONSE>", "projectId": "<YOUR_GCP_PROJECT>", "query": "Mercedes", "languageCode" : "en-US", "payload" : { "fields" : { "customer" : { "stringValue": "abc_car", "kind": "stringValue" }, "time" : { "stringValue": "afternoon", "kind": "stringValue" } } } }'
    --- Final Response and completion of Intent, User will be redirected to Mercedes Sales agent. As you can notice, Dialogflow made use of the session data to fill in the level1_dept i.e "Sales" passed in the previous query, in its response. ---
    {"sessionId":"<SESSION_ID_FROM_PREVIOUS_RESPONSE>",
    "responseText":"Trying to contact someone from Sales in Mercedes"

    That’s all folks. I hope you liked the above implementation and can find some good use-cases for it. Drop me a note or create a GitHub issue if you see any problems or bugs with the above setup. Enjoy !!

    Don’t forget to give us your 👏 !


    A multi-tenant chatbot with Dialogflow — Part 2 ( Implementation) was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.

  • A multi-tenant chatbot with Dialogflow

    Chatbots and natural language conversational engines are quite ubiquitous nowadays. The success or failure of a business to an extent…

  • How you can optimize your business using an AI-powered chatbot for customer service

    Learn the benefits of using AI chatbot and the ways on how to optimize your business using a chatbot.

  • Ecommerce Chatbot

    Ecommerce Chatbot:

    https://www.haptik.ai/blog/tag/ecommerce-chatbot

    Checkout our blog on Ecommerce Chatbot to know why your brand needs a shopping assistant chatbot!

    Request a demo on our website to check out our service, we shall be happy to serve you all

    #ecommerce #chatbots #digitalmarketing #marketing

    submitted by /u/ankita_tandon_haptik
    [link] [comments]

  • Conversational AI in Retail is Transforming the Customer Experience | Enterprise Bot

    With the rise of e-commerce titans like Amazon, eBay, Walmart, the retail industry has witnessed a rapid digital transformation over the…

  • Testing SMS Chatbots with Botium Box

    Botium Box offers two methods to test an SMS Chatbot. It can act as a user sending SMS messages, or can interact with the API behind the chatbot. Sending SMS messages looks like an optimal choice because it covers all the stack, but it has a major drawback, the increased costs.

    For smaller systems sending SMS messages is usually a good decision. It is the all-purpose solution, and it is easier to setup.

    More complex chatbots can have more sophisticated configuration, API-testing all conversation branches, and SMS based testing for checking performance and availability of the full stack for example.

    Tip: If your API delivers NLP information like recognized intent and entity, then in case of API testing you can even use NLP Analytics in Botium Box (depending on license).

    API Testing

    There is no step-by-step solution for API testing. We need a Botium-connector which fits to your API. You can use the suitable generic connector of Botium Box (in most cases Generic HTTP(s)/JSON interface). Or you can write your own.

    SMS testing with Botium Twilio SMS connector

    Botium Box uses Twilio to communicate with any SMS chatbot.

    You’ll need a Twilio account, register a telephone number in Twilio, configure Botium Box for Botium-to-Twilio messages, and Twilio for Twilio-to-Botium messages.

    You can use trial account for Twilio, but there are limitations, and the budget is limited. We use an upgraded account here.

    Please keep in mind that SMS communication has no session. If you have for example development, and production tests, then it is a good practice to register telephone numbers and configure connection in Botium Box for each. Otherwise you can get some random test fails if they are running in parallel.

    Trending Bot Articles:

    1. How Chatbots and Email Marketing Integration Can Help Your Business

    2. Why Chatbots could be the next big thing for SMEs

    3. My Journey into Conversation Design

    4. Practical NLP for language learning

    Twilio account

    Follow the steps start trial and upgrade.

    Register a telephone number

    Navigate to Active Numbers, click on Buy a Number. Consider choosing the same country as the one, where your chatbot’s number is located. And choose ANY or SMS in capabilities, and buy a number.

    Check SMS capability (optional).

    Notice the telephone number, and the credentials (settings, general)

    Configure Twilio in Botium Box

    Now we have to setup Botium Box

    Under the Chatbots list click on the Register new chatbot button.

    Fill the form with the values from the Twilio Dashboard. (Sending SMS to field is the telephone number of your SMS chatbot.)

    Once the form is complete, Botium Box will be able to receive messages. But we can’t test the connection yet. We have to configure Twilio to send messages to Botium Box.

    After you choose an API key, you can see the endpoint for receiving messages on the registration form. Copy the endpoint url.

    Configure the Twilio webhook

    Open the settings for the registered number in Twilio, and paste the endpoint as webhook in the Messaging section (not in the Voice & Fax section!) and save it.

    Test the connection and save it in Botium Box

    Everything is set up. Now we can test it with pushing SAY HELLO (CHECK CONNECTIVITY) button. (We expect that the chatbot responds if we send hello. If it’s not the case, then skip the test. You can test it manually using Live chat feature of Botium Box)

    Everything fine, we can save the form.

    If is not working, then check the error message displayed on the connectivity test, or check Twilio logs on the phone number.

    Disable parallel execution in Botium Box

    If you have more Agents (workers) in Botium Box, and more test cases in a test set, then Botium Box executes the test set parallel. It is good for most of the connectors, but not for Twilio SMS connector as mentioned before.

    We have to set the Parallel Jobs Count to 1 (or choose a dedicated Agent) in project settings to disable parallel execution.

    Use Botium Box

    The connection is configured, you can use all features of Botium Box!

    See this article in spanish here! 🇪🇸

    Don’t forget to give us your 👏 !


    Testing SMS Chatbots with Botium Box was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.