A quick start tutorial for setting up an AI chatbot using Wit.ai

Abhishek Raj
Chatbots Life
Published in
5 min readJul 30, 2020

--

In this tutorial, we will learn how to set up a conversational AI Chatbot using Wit.ai and MessengerX.io

Web Demo

https://dev.messengerx.io/witty-jokes

Requirements

  • Golang — Basic
  • Wit.ai
  • Ngrok (local tunnel to your laptop for development purposes)
  • MessengerX Wit template
  • Platform API Token / Key
  • GNU Screen / Terminal
  • Javascript Enabled Browser (Google Chrome)

Today, we will learn how to set up a conversational AI Chatbot using Wit.ai and Machaao Chatbot Template on MessengerX.io platform.

So, assuming we have all the above covered — Let’s get started!

Step 1: Register and Get your FREE API Key

Visit https://portal.messengerx.io/ then login or signup on the platform.

MessengerX.io Login

Fill out the form shown below and create a new chat bot, place None in webhook URL and image URL and then press create.

MessengerX Create App

Click on Settings and copy the API Key, you will need it later.

Now, we need API Token from Wit.ai. So, sign up on Wit.ai.

Wit.ai Create App

Image Source

Click on Create > Your App > Settings then copy the server access token, that is your Wit API Token.

Trending Bot Articles:

1. Conversational AI: Code/No Code

2. Chatbots 2.0: Simplifying Customer Service with RPA and AI

3. Question Answering on Medical conversation

4. Automating WhatsApp with NLP: Complete guide

Step 2: We will use the MessengerX Wit github template

git clone https://github.com/machaao/messengerx-wit-go.gitcd messenger-wit-gols

Step 3: Installing the basic requirements

You can download ngrok from ngrok — download

Download & Install the Go-Lang stable version from here: https://golang.org/dl/

go get github.com/dgrijalva/jwt-gogo get github.com/wit-ai/wit-go

ngrok allows you to expose a web server running on your local machine to the internet.

Step 4: Setup the Sample Chatbot Project & Update the API Key / Token

We will be setting MessengerX.io & Wit.ai API token as environment variable.

# For Linux and Mac OSexport MachaaoApiToken=<YOUR-MESSENGERX-API-TOKEN>export WitApiToken=<YOUR-WIT-API-TOKEN># For Windows (PowerShell)$env:MachaaoApiToken = '<YOUR-MESSENGERX-API-TOKEN>'$env:WitApiToken = '<YOUR-WIT-API-TOKEN>'

OR

You can even directly set the respective API Token in the main.go file.

Step 5: Starting GoLang Chatbot Server Locally

Now, navigate to the working directory messenger-wit-go

Open bot.js in an editor and at line 17 place your API-KEY, copied from MessengerX.io portal.

screengo run main.go

Press ‘Ctrl+a’ then ‘d’ to detach from the screen.

Step 6: Start NGROK server

Note: If you are using VPS then just add PORT 3000 to inbound rules and skip the below step.

screenngrok http 4747

Note: Copy the forwarding url. You will need this.

Press ‘Ctrl+a’ then ‘d’ to detach from the screen.

Step 7: Updating the webhook on MessengerX.io Dev Portal

Log on to https://portal.messengerx.io/ and click on settings to update the chatbot webhook URL.

Paste <FORWARDING-URL>/machaao_hook or paste the VPS domain:4747 and save it.

That’s it.

The Chatbot will also be available on the web.

If everything went well you can see your chatbot at

https://dev.messengerx.io/<chatbot_name> OR https://ganglia-dev.machaao.com/<chatbot_name>

To integrate the chatbot into your website use iframe.

<iframe src=”https://dev.messengerx.io/<chatbot_name>”width=”400" height=”600"></iframe>

Step 8: Training the Chatbot on Wit.ai

We will now use Wit.ai to train our chatbot to understand the input and extract useful information from the user input message. We have to input sample input text and define what type of data we want.

Type the sample text, highlight the sample data you want to capture then select from the entity or create one, then click on Train and Validate.

Entity detects the similar data and captures it.

After training few data headover to settings to test the AI, if it is getting desired value or not.

In the HTTP API section enter your query then send a GET request to the API.

You would get result similar to this.

Curl output

After getting desired entity value, you are good to go.

Conclusion

With Wit.ai and MessengerX.io, you can create and deploy your scalable ChatBot in no time, as we already know the scalability and performance of GoLang.

Github Repo: MessengerX-Wit-Go

Demo: https://dev.messengerx.io/witty-jokes

Checkout my other tutorials too

Happy Coding :)

Abhishek Raj

MessengerX.io | Connecting Bot Developers to App Publishers

Don’t forget to give us your 👏 !

--

--