Creating a Webex Chatbot — Part 2

Andre Botta
Chatbots Life
Published in
4 min readAug 6, 2019

--

Introduction

In part 1 of this series, we created our bot and our room for testing. In this tutorial, we will create a web server that receives messages from a Webex Webhook and sends a pre-defined message back to the room.

Python Web Server

Our web server will be extremely simple. It has a POST endpoint that receives the Webhook event and process it. We will use VS Code Remote Development for this purpose, this way you don’t need to change anything on your machine (considering that you already have VS Code and Docker installed on your machine). For simplicity, I already created an image with all the necessary tools installed, as you can see on the .devcontainer.json file bellow:

Top 4 Bot Tutorials

1. How we wrote a Wirecutter-like bot with Reply.ai in just a few hours

2. How to Create a Facebook Messenger Bot with Ruby on Rails

3. DialogFlow(formerly API.AI): Let’s create a Movie ChatBot in minutes

4. Chatbot Conference in San Francisco

The web server has only one endpoint at the root path and it is a POST method, which will receive and process the Webhook message:

Ok, now we have a web server that will receive a message and send a message back to the room. We now need to POST a message to our web server every time a new message is sent to our Bot. The webhook’s API will came handy now :)

The full Web Server Code can be found here:

Webhook API

A webhook is simply an HTTP callback. Every time an event happens, a POST is performed and notifies you. From the API you will notice that to create a webhook we have to provide four mandatory parameters:

  • name;
  • targetUrl — IP Address of our server (we will talk more about this soon);
  • resource, in our case: “messages”;
  • event, in our case: “ created”.

So, in order to create our webhook, we need to pass all these parameters. The ‘name ’ is an arbitrary string to identify our Webhook. The targetUrl needs a bit more attention: while developing, you may not have a public IP Address to receive the Webhook Post. For that matter, we will use ngrok. If you are not familiar with ngrok, it basically will let you point a public URL to your localhost :)
Just follow the instructions here and make sure that you point the ngrok server to the right port: 9999 (unless you changed the Python Server port).

Back to our webhook, there is one more parameter that is important: ‘filter’. This parameter, as the name suggests, will let us filter the events that trigger the webhook. We will use two queries for this parameter: roomId, from our previous tutorial and, because we are using a Bot, we also need to specify the ‘mentionedPeople’ query (you can find the explanation here). The code below will create our webhook. You can use the same project structure from Part 1.

Now, it is time to start our server. Once it is up and running, we can go to our room and send a message to our Bot (you need to mention the Bot on the message!) and, if everything goes as expected, the Bot should post a message to the same room with the message: “hello there”.

On the next tutorial, we will give our Bot a bit more of “intelligence”.

Don’t forget to give us your 👏 !

--

--