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 Deploying the Telegram Bot Web App to IBM Cloud Code Engine

In this tutorial you will learn how to deploy the Telegram Bot Web App to IBM Cloud Code Engine. To ensure successful deployment of the application, please follow the subsections below in the specified order.

Reminder: Deploying on IBM Cloud is a suggestion. You may deploy this application on any cloud application platform using either the source code or the Docker image generated in this tutorial.


IBM Cloud Code Engine Overview

Code Engine (CE) is a PaaS (Platform as a Service) to deploy web applications to the cloud with ease and without the need to manage the underlying infrastructure. Code Engine automatically scales applications based on demand and provides built-in integrations with other IBM Cloud services. Code Engine has a free usage amount that should let us deploy the chatbot for testing purposes.

This tutorial will take you through the deployment process, which will be done mostly with the IBM Cloud CLI (Command Line Interface). For more information you can visit the official CE documentation and the documentation for CE plugin in IBM Cloud CLI.

Necessary Components

To proceed in this tutorial, kindly ensure that you have the following components:

Environment Set-up

Cloning this repository should take care of the files and folders set-up. Locally, you need to create a virtual environment (venv), install the requirements, and set up a .env file in the folder src/.

This is how you can create a venv, activate, and install the requirements:

To create and set up the .env file, you can use VS Code or your favorite terminal text editor. We will need these environment variables to build the Docker Image and deploy the app:

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



Deploying the App

The following content will walk through deploying the app using the CLI. It is loosely based on this tutorial. To facilitate the distribution of the application and it's deployment to Code Engine, it is strongly recommended to containerize the application source code together with all of the related configuration files, libraries, and dependencies required for it to run. Access this IBM page to find more information about containerization.

The first thing to do when you want to generate a image of an application is to choose the tool that you will use to do it. There are many container runtime tools like Docker and Podman. In this tutorial we will going to use Docker.

Docker Overview

Docker is a platform for "developing, shipping, and running applications." (Docker documentation). Docker containers give the ability to package an application and share it with others, without needing too much work on setting up environments. Containers can also run on a variety of environments, making it suitable for quickly deploying the chatbot on the cloud.

Verifying the Dockerfile configuration

Before proceeding, please ensure that the dockerfile is configured to run the Python application for Telegram as depicted in the image below. If the command line that runs the Telegram application is commented out, please uncomment it and comment out the command line that runs the WhatsApp application.



Building the Docker Image and pushing it to IBM Cloud Container Registry

With the previous steps being concluded successfully, open the terminal in the project main folder and execute the following commands:

Done! Now you are ready to deploy the web application to Code Engine.

Creating the app

Once we logged on IBM Cloud CLI previously, these are the main steps to deploying the app to CE:

Congratulations! You have deployed the application to cloud. 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.

Note: The deployment can be made by IBM Cloud console, if you prefer.

Handling Errors

In case of any problem with the deployed application, first stop the Code Engine application, then run it again. You can check the application logs in your terminal, as this tutorial shows, to verify if any exception was raised or error occurred.