View the Project on GitHub IBM/customized-voice-text-bot-for-whatsapp-telegram
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.
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.
To proceed in this tutorial, kindly ensure that you have the following components:
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:
$ python3 -m venv <name_of_virtualenv>
$ pip install -r requirements.txt
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:
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 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.
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.
With the previous steps being concluded successfully, open the terminal in the project main folder and execute the following commands:
$ ibmcloud login
$ ibmcloud login --sso
. $ ibmcloud target -g Default
ibmcloud resources
$ ibmcloud cr login
ibmcloud plugin install cr
.$ ibmcloud cr namespace-add <my-namespace>
<image-link>
: <registry-address>/<my-namespace>/<my-repository>:<my-tag>
$ docker build --tag <image-link> .
$ docker push <image-link>
Done! Now you are ready to deploy the web application to Code Engine.
Once we logged on IBM Cloud CLI previously, these are the main steps to deploying the app to CE:
$ ibmcloud ce proj create -name <proj-name>
$ ibmcloud iam api-key-create <api_key_name> --file <file_name_to_save.txt>
apikey
value from the json.$ ibmcloud ce proj select --name <proj-name>
$ ibmcloud ce registry create --name <registry-access> --server <registry-address> --username iamapikey --password <paste apikey>
$ ibmcloud ce app create --name <app-name> --image <image-link> --registry-secret <registry-access>
$ ibmcloud ce app get --name <app-name> --output url
$ ibmcloud ce app update --name <app-name> --env TELEGRAM_WEBHOOK_URL=<paste URL>
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.
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.