Social Share

Complete On-Premise and Fully Customisable Chat Bot - Part 2 - Agent Building Using Botkit

Welcome back Folks !!

In our part 1 we are reading about the overview of building the chat bot using botkit and the RASA NLU that runs in the premise without having dependency on the cloud services.

Here we will be looking at developing our Chat Bot Agent server using the botkit framework.

Building the Agent

Preparing the environment

We will start with setting up the environment for setting up the agent.

Install the Node. 

  1. You can get the installer from here. Install the node after it gets downloaded. 
  2. Once it gets succesfuly installed, open the command prompt and type.

  1. If the output shows some version number means the installation is success.

Installing the botkit using NPM (Node Package Manager)

  1. Choose some directory and make the following directory structure as follows.

This is going to be the initial directory structure.

  1.  Execute the following commands to move into the Botkit folder
    1. cd Botkit
  2. Initialise the npm package.json using 
    1. npm init
  3. You can see the package.json file created after the wizard.
and the package.json will look like above

  1. Add the botkit package using the command (--save is to save the package to the package.json)
    1. npm install botkit --save
  2. Install the Visual Studio code as the editor for the node js. Download Link
  3. Open the Botkit folder in the visual studio code.
  4. Add a new file named index.js
Now all set for the Agent server. Lets start coding the server.

Once the Visual studio code opens, open the index.js from the file explorer on the left.

1. First lets include the header that is needed to include the needed library.
The above code have the comments that are self explanatory.


2. Create the express server instance and the HTTP server instance. Express server will act as a web server which uses the http server to run on a particular port. Both can be created as follows.


3. Now lets create the Bot kit controller instance by using the Bot kit package that we included as follows. The Bot Kit Controller handles all the incoming and the outgoing connections and also the interfaces to handle the message.


Also after creating the controller, let us tell the controller to use the express and the http server as the web server that it needs to use for the communication.

4. Lets now set the bot into action.

  • controller.openSocketServer(controller.httpserver);
    • This will open the websocket server in the http server port that has been specified.
  • controller.startTicking();
    • This will start the initialize the bot and will set the environment ready to work.


5. Next lets make the Bot to hear to the message the user types in. For that we need to use the controller.hear() method to do it. Hear method takes two parameters, one is the 'expression' of the message that needs to be listened up, other is the function(Bot,message) that handles the incoming message.


6. You can provide the multiple hear methods with different expression to handle the message. But if no hear matches the message then to have a fall back mechanism we need to add the following code.


All things are done. Combining everything following will be the look of the "index.js"



Next our job is to run the bot and talk with the bot. Since we have not created the front end. We will use any web socket client to communicate with our bot.

Start our bot using the following command in the current bot folder.

Command : node index.js

This will start the server in the port 3000.

Lets see how to communicate with the bot in the next post ..Follow the link to communicate with our bot.   :-)

Next >> http://creospiders.blogspot.com/2018/04/CompleteOn-PremiseandFullyCustomisableChatBotpart3.html

Comments

Latest Technology Videos

Popular posts