IBM Research

View the Project on GitHub IBM/customized-voice-text-bot-for-whatsapp-telegram


Learn more about

Deploying to IBM Cloud and others
Telegram
WhatsApp
Running locally
Telegram
WhatsApp

Setup Watson Services
Setup Data Storage
Customizing Text-to-Speech
Customizing Speech-to-Text


Instructions for Running Locally Telegram Bot Application

To execute the Telegram Bot application on your local machine, kindly follow the subsections below in the specified order.


Necessary Components

To locally run the app successfully, please ensure that you have these components ready:

ngrok

ngrok is a third-party software that can be used to expose "local servers to the public internet over secure tunnels" (ngrok documentation). Basically, ngrok provides a random public url that can forward requests to a local host.

Environment Set-up

After acquiring the necessary components and cloning our GitHub repository, you would need to create a Python 3 virtual environment (using virtualenv for example), and install the dependencies. Below you can see how to do these steps:

In the src directory, you should also create a .env file. This will store the API keys and the code will search for them.

In the .env file, you can store API keys with these exact names. We do this to protect sensitive information, namely, API keys and other IDs. STT, TTS, Watson Assistant, COS and Cloudant API keys can be found on the IBM Cloud website (by going to Resource List and then opening each service). For the Watson Assistant ID, you first have to launch Watson Assistant (this can be done from the resource list) and create an assistant. After that, under Assistant Settings the assistant ID will be there.

These are the API keys that you will need to run the app:

The following image is an example of how the .env file should be formatted - without the variables values, of course:



Running the App

First, run the command for your respective OS on the command line (in the folder ngrok were installed):

After this, an ngrok interface, similar to this, should appear:

See ../src/images/ngrok_interface.jpg

There would be two "Forwarding" sections of the interface - you can copy the https://____.ngrok.io/ url, and store this as TELEGRAM_WEBHOOK_URL in your .env file.

After this is done you are prepared to run the app and send messages.

It is time to run the application. In the src/ folder:

Congratulations! The application is ready to receive requests. You now should be able to interact with the bot on Telegram. Yeeey!

You can monitor bot activity through Cloudant database and access the media files sent and received by the bot in the Cloud Object Storage bucket you create.

Of course, there should also be a working Watson Assistant dialog skill attached to your Watson Assistant assistant (that correlates with WATSON_ASSISTANT_ID) in order for you to receive sensible responses from the app.

Handling Errors

The code has try-except blocks in many places, so as to catch specific errors from the services. Most errors should produce a debug output within the terminal.