Setup a custom dialogflow chatbot on your website

In this tutorial, We are going to learn how one can create a chat app using DialogFlow and MessengerX.io.

We can easily create our logic pipeline (like how and what our chatbot will respond) and connect it in our website, deploy if required on play store or on MessengerX.io Platform and monetize it! (applicable for consumer bots)

Prerequisite

  1. Python 3.6+
  2. MessengerX.io FREE Auth Token
  3. DialogFlow

Getting Started

First we will clone the template which contains the starter code

git clone https://github.com/machaao/machaao-dialogflow-template.git

cd machaao-dialogflow-template

Getting DialogFlow Auth Key

We will follow this doc created by google to enable the DialogFlow API and create the Auth Key.

Quickstart: Dialogflow API Setup

Training the DialogFlow AI

Visit https://dialogflow.cloud.google.com/

  1. Click on Create Intent

2. Enter Name and Training Phrases

3. Add some more Intents like this

Now, your NLP Engine is ready to rock.

Getting MessengerX.io Auth Token

Get your free token, by signing up @ portal.messengerx.io

Creating .env File

Firstly you will need to create a .env file which will store all of our secrets required by our chatbot.

Create a .env file in project root directory

MESSENGERX_API_TOKEN = <Your-MessengerX-Token>
MESSENGERX_BASE_URL = https://ganglia-dev.machaao.com
FLASK_DEBUG = true
PROJECT_ID= <YOUR-DIALOGFLOW-PROJECT-ID>
GOOGLE_APPLICATION_CREDENTIALS = <Path-To-Credential-json-File>

Starting the Server

Now you only need to start the server.

machaao run -p 5000 -t <Your-MessengerX-Token>

If you see any error, you can alternatively try

python chatbot.py

# In another terminal
machaao tunnel -p 5000 -t <Your-MessengerX-Token>

Check out the Dialogflow Sample Chatbot below:

https://dev.messengerx.io/dialogflow-test

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

AI Chatbot using RASA and MessengerX.io

In this tutorial, we will learn to build and run a custom AI chatbot in Python using RASA and MessengerX.io

Basic AI Chatbot Demo

figure

https://dev.messengerx.io/rasa.sample

Requirements

1. Get your FREE MessengerX.io Chatbot API Token

  1. Login/Signup at MessengerX.io Portal
  2. Create a new app by clicking the New App
  3. Fill in the blank details, then click Create.
  4. Open settings of the ChatApp.
  5. Copy the Token.

2. Clone the Chatbot Starter Repository

Next, Lets clone the open source sample rasa chatbot template as shown below

git clone https://github.com/machaao/rasa-sample-nlu-bot.git

cd rasa-sample-nlu-bot

3. Install the Dependencies/Requirements

Here, We will be installing Rasa 2.2.0, Machaao Python Module – 0.2.0 and PyYAML (Optional)

Note: Might take some time depending on your internet speed.

pip install -r requirements.txt 
pip install -U PyYAML 

4. Replace the API Key

Now, we need to paste the Chatbot API Token which we copied from MessengerX.io Portal and the Chatbot API Token will be able to securely send messages with the server and user.

Use a text editor to open config/credentials.yml

connectors.MachaaoConnector.MachaaoInputChannel:
    api_token: <YOUR API-TOKEN>
    base_url: "https://ganglia-dev.machaao.com"

5. Starting RASA Action Server Locally

Here, we need to run the Action server, it is used for predicting the response for users. If you want to learn more about RASA Action Server, you can visit this page.

Open a terminal/powershell.

rasa run actions --actions actions

This command will start the action server, if you see any warning, don’t get bothered.

6. Starting Rasa Core Locally

Open another terminal/powershell.

The server should start at PORT 5005.

rasa run -m models --debug --endpoints config/endpoints.yml --credentials config/credentials.yml --enable-api --cors β€œ*” --connector "connectors.MachaaoConnector.MachaaoInputChannel"

7. Start Tunnel Server

Tunnel server is used for exposing your port to web. We will be using the FREE machaao tunnel server.

Open another terminal/powershell.

machaao tunnel -p 5005 -t <Chatbot-Api-Token>

8. Updating the Webhook URL on MessengerX.io Portal

Update your bot Webhook URL on MessengerX.io Portal with the url provided as shown below.

Webhook Url: <TUNNEL-URL>/webhooks/machaao/incoming

You can test your new AI chatbot by visiting, https://dev.messengerx.io/<chatbot-name>

Congrats, your shiny new sample AI chatbot is ready.

Checkout https://blog.messengerx.io for more tutorials on AI and Chatbots

Happy Coding and Happy New Year!

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