This is the simplest telegram bot that answers with the phrase you sent him. The Chat Bot is a component of a Smart Home. We will therefore execute this code on our home Raspberry Pi. The code of this bot can be modified for your projects, for example, such as Internet radio. First, find the @BotFather on Telegram and get the token to access the HTTP API for your bot from it by following the instructions.  The best way is to put the bot code in a separate directory using the Python virtual environment.

install python virtual environment

sudo pip3 install virtualenv
mkdir /home/pi/bot && cd /home/pi/bot
python3 m venv env

activate the virtual environment

source env/bin/activate

install telegram bot library

pip install python-telegram-bot

create a file with bot settings

touch ./settins.py

write to the file this line

TELEGRAM_API_KEY = <your token to access the HTTP API>

Full echo-bot code is under the spoiler. Write cod to the file echo-bot.py .

Spoiler

 

run echo bot

python ./echo-bot.py

Dialog with echo bot.

Remember your chat_id.

This code will be the basis for creating our other bots, which I will describe in this section.

 

Leave a Reply