Telegram based bot to manage interactions with users. Current version supports predefined set of questions that users can ask by pressing the respective buttons. Responses to users can be provided both in text and image formats. This tool can be easily extended to other advanced use cases like user queries, backend API integrations, database persistence etc.
Telegram bot can be coded in many languages. tgbot tool uses Nodejs. Please refer to https://github.com/hosein2398/node-telegram-bot-api-tutorial for the NPM package used in this code and other ways the package can be implemented.
This is a farily simple process. Telegram has a user called @BotFather. This is the quickest way to create your chat bot user. You can refer to https://core.telegram.org/bots#6-botfather for all details. Below are the exact things you need to do:
- Start a session in your Telegram App and send a Hi note to @BotFather
- Click /newbot in the response message
- Provide a name to the bot. Like "My good bot" :)
- Then choose a username ending with "_bot"
- Note down the HTTP API access token that @BotFather returns. This token is the only thing you will need in the code to send and receive messages from users interacting with the bot.
- Clone this code to your local machine
- npm install
- node server.js
- Provide the API key in .env file
- Provide all messages in the messages input file
- Formats of both the files is available in Samples folder
npm installnode server.js- If you are running this on a EC2 or other Linux host, make sure the process keeps running even after SSH session terminated. Use "setsid" whicl starting
- Other option is to use a Docker image
sudo yum install -y dockersudo systemctl start dockersudo docker build -t vkivaturi/tgbot ~/tgbot/sudo docker run --env-file ~/tgbot/.env -v /home/ec2-user:/home/ec2-user -d vkivaturi/tgbot
- Setup standard messages in the input file. File format is row
tiledescription. Tiles will appear in the chat window keyboard layout - Images are also supported in response to user input.
- External API calls are also supported. In this current code, Cowin website of Indian Government is called to fetch list of centers where vaccination slots are available.
- Admin users can upload the messages file directly to the chat box. This upload will update the messages file.