Create a Serverless, Watson-Powered Chatbot for Your Business

Add a conversation widget to your web page that handles questions for you

Imagine you have a small business, like a restaurant or a hotel. What are the most common enquiries that you get?

  • What are your opening times?
  • Do you have a Facebook page?
  • Can I make a booking?

Many companies are now creating chat bots that can answer such questions. The human has an interactive conversation with the bot on the company website and information is passed to the customer in a very natural way:

Concierge chatbot, in three stages.

The Watson Conversation service gives you the tools to program your own custom chatbot, but I’ve provided a helper script to get you started more quickly: the concierge-chatbot. It creates a chatbot for you using your business information and gives you the HTML code that you need to run the chatbot in your own company website.

You can try a demo chatbot here.

Pre-requisites

Before you can build your own chatbot, you must sign up for some accounts and install some tools on your machine.

  • Node.js — if you haven’t got Node.js on your machine already, then visit the Node.js homepage and install it
  • Bluemix — sign up for a Bluemix account. There’s nothing to install on your machine as Bluemix hosts its services for you in the cloud.
  • OpenWhisk — In your Bluemix dashboard, visit the OpenWhisk page to download and configure the wsk command-line tool using those instructions. OpenWhisk is IBM's serverless computing platform that lets you host code in the cloud without paying for dedicated computing power to run it.
  • Watson Conversation — In your Bluemix dashboard, find the Watson Conversation service in the catalog and sign up for an account. Make a note of the username and password of your service — you’ll need that shortly.
  • Concierge Chatbot — run npm install -g concierge-chatbot to install the chatbot generation script. You may need to prefix that command with sudo depending on how Node.js is configured on your machine.

Now that you have the software, you can make some chatbots!

Roll your own chatbot

To create a chatbot, simply run concierge-chatbot from the command line. You're prompted for your Watson Conversation credentials and details about your business (ignore the questions about Cloudant for now):

The concierge-chatbot script creates a Watson Conversation service, publishes an OpenWhisk action to provide a web front-end for it, and generates some HTML customised for your business. Cut and paste this HTML snippet into the bottom of your website's code to see it in action. It's that simple. (Make sure you have jQuery present on your web page)

If you make a mistake, you can run concierge-chatbot again - it remembers your previous answers: just modify the data and it creates another one for you.

The free Watson Conversation plan lets you configure up to three bots at once. If you run out, just delete the unwanted ones from the Watson Conversation dashboard, which is linked from your service in the Bluemix dashboard.

How does this work?

There’s lots going on here, so take a breath and see what you’ve created.

The code that you pasted into your website generates the pop-up Concierge widget in your web page. Every time someone uses it, a message is sent to your OpenWhisk service which sends it on to your Watson Conversation service together with the service credentials. The reply from Watson Conversation is sent back to your website.

Storing your conversations

If you would like to store the conversations that your widget has then you need to add a database. You’re going to spin up a Cloudant NoSQL database and ask the OpenWhisk action to store the conversation data as it happens.

  1. In the Bluemix dashboard, add a Cloudant NoSQL DB service and make a note of the Cloudant URL. It should look something like https://MYUSERNAME:MYPASSWORD@MYHOST.cloudant.com
  2. In the Cloudant service’s dashboard, create a new database called “concierge” (or whatever you like)
  3. Re-run the concierge-chatbot supplying the Cloudant URL and database name when prompted

Your chatbot data is now saved in the database!

Free and open-source

All of the code described here is free for you to use and modify yourself:

If you want to modify the chatbot yourself, then feel free to copy the code and build on it. It is open-sourced here:

If you want to contribute to the concierge-chatbot source code, I’d love to see your enhancements. Pull requests welcome! And please ♡ this article to recommend it to other Medium readers.