Build an AI based chatbot for your website or app using Wit.ai

Messengerx.io Wit Demo

In this tutorial, We will show you how you can create a simple chat app (chatbot) using Python , Wit.ai and MessengerX.io.

Requirements

  1. Python
  2. Flask
  3. Wit.ai Server Access Token
  4. MessengerX.io Free Chatbot Token

Clone the wit.ai sample template repository

Here you will need to clone the template repository.

git clone https://github.com/machaao/machaao-wit-template.git
cd machaao-wit-template
pip install -r requirements.txt

Basic Training with Wit.ai

  1. Log on to Wit.ai
  2. Create a new app
  3. Open the chatbot
  4. Open Traits from left sidebar
  5. Click on Add Train
  1. Select “Add built-in traits”
  1. Select “wit/bye” and “wit/greetings”
  1. Open Settings
  2. Copy “Server Access Token”

Creating a Chat App on MessengerX.io

To host the chat app on your website, will need to get a token from MessengerX.io.

Follow this below tutorial to create the same and get an API token.

How to get API Token for MessengerX.io Chat App Marketplace?

Configuring your chat app server

  1. Create “.env” file in root directory of the project
WIT_ACCESS_TOKEN=<YOU-WIT-ACCESS-TOKEN>
MESSENGERX_API_TOKEN=<YOU-MESSENGERX-API-KEY>
MESSENGERX_BASE_URL=https://ganglia-dev.machaao.com
  1. machaao run -p 5000 -t <MESSENGERX API TOKEN>

If every this went good, you chat app will be accessible at https://dev.messengerx.io/<chat-app-name>

Here are some other articles on creating and deploying chat apps on MessengerX.io

  1. AI Chatbot using RASA and MessengerX.io
  2. Create a trivia chatbot with Node.js and Heroku
  3. Build deeply personalized chatbots at production scale

Build deeply personalized chatbots at production scale

Chatbots are now generally agreed upon as one of the fastest gateways into the ever changing field of machine learning.

This tutorial serves as a quick start guide for developers who are interested in the art of building deeply personalized chatbots.


Minimum Requirements

  • Python3 – Basic Understanding
  • Desktop Terminal (Windows / Mac / Linux)
  • Brew / Snap (Mac / Windows)
  • Ngrok
  • Platform API Token / Key
  • Active Internet Connection
  • Javascript Enabled Browser (Chrome / Safari / Firefox)
  • MessengerX Wiki (Reference)

In this tutorial, We will learn how to set up a simple echo bot using machaao python module in less than 10 minutes.

So, assuming we have all the minimal requirements covered.

Let’s get started!


Signup for your FREE API key

Signup via MessengerX.io – Dev Portal

Upon login, you should be able to create a new chatbot and the corresponding FREE API key.

MessengerX.io - Portal - Login / Signup - Chatbots
MessengerX.io – Dev Portal

Create your first chatbot application via portal

Upon login, Please click the fairly prominent “Add New App” button.

You should now see a popup screen as shown below.

Enter a display name for your chatbot.

To continue with the process, you can enter “None” in Webhook URL and Image URL field for now.

Next, Press “Save Changes” to generate a new API key for your bot.

MessengerX.io - Portal - My Chatbots
Create a new chatbot

Let’s proceed by saving the changes.

Next, Click on Settings and note down the API Key, you will need it later during the process.

Install the machaao python module

We will need to install the machaao library module to continue.

To continue, let’s install the module as shown below via PIP

# For Linux/MacOS
pip3 install machaao

# For Windows
pip install machaao

# For Ubuntu
sudo snap install ngrok

# For MacOS
brew install ngrok

# For other OS visit: https://ngrok.com/download

Finally, Let’s install NGROK so that we are done with the basic system requirements.

Create a new chatbot project locally

Once the machaao pip module has been installed on your system / laptop.

You can now create a new chatbot project by running the “machaao” command as shown below.

machaao --start <project_name>
# Creates a folder and copies the chatbot files.

cd <project_name>
# Changes current directory to the project directory

This will create a directory with the specified <project_name>

Next, Open chatbot.py in your favorite python editor and update the API key and base URL as shown below.

# Get the API Token from - https://portal.messengerx.io
MESSENGERX_API_TOKEN = "<API_KEY_FROM_PORTAL>"

# Base URL is used to communicate with either Dev or Prod APIs.
MESSENGERX_BASE_URL = "https://ganglia-dev.machaao.com" [for development purposes]

Run your local chatbot server

Next, Run the chatbot server via command line terminal.

# For Linux/MacOS
python3 chatbot.py

# For Windows
python chatbot.py

Setup your web server for development

Almost there…

Continuing on, let’s run NGROK in the command line terminal as shown below.

# Copy the HTTPS forwarding URL
ngrok http 5000
NGROK
NGROK – Local Tunneling
# Copy the HTTPS NGROK forwarding URL
https://<....>.ngrok.io/

NOTE: Not required on a VPS, Shared Hosting Providers such as Heroku.

Update your Chatbot Webhook URL

Next, Click on the chatbot settings and update your webhook as shown below.

Continuing, Update the webhook as shown here “https://<….>.ngrok.io/machaao/incoming” without quotes and save it.

MessengerX.io - Portal - Update your new chatbot
Update your chatbot settings with the new url

Your echo chatbot is now ready for development

If everything went well, your chatbot should now be ready to receive and process messages to or from users via Web / Android.

Congrats, you are now on your way to a deeper machine learning journey.

Finally, You can now show off your shiny new sample echo bot via https://dev.messengerx.io/<chatbot_name>

#HappyCoding


Get Started with building deeply personalized chatbots today with MessengerX.io

blog.messengerx.io