Sign inSign up

sydalsitc/telegram-poll-bot

By sydalsitc

Updated about 1 year ago

A small demo telegram bot that creates polls from a predefined list.

Image
0

88

sydalsitc/telegram-poll-bot repository overview

Demo Telegram Bot

An example for a telegram bot written in python and running in a container.

About

For a small project, we needed a bot as member in our telegram group that should create always the same polls if it was asked to. So a bot account was created using the telegram botfather, and some bot code written in python, using the python-telegram-bot library.

Important: you'll need the code from our Github repository to run the bot because the image is designed to mount the local directory with code and configuration and run the bot from there.

How it works

Get the code from https://github.com/SydalsITC/telegram-tools:

git clone https://github.com/SydalsITC/telegram-tools

Change to the demo-bot subfolder:

cd demo-bot

Make sure that the env variable BOTSTELEGRAMTOKEN contains your telegram access token and pass it when starting the bot:

docker run --rm -it -v .:/app:Z --env=BOTSTELEGRAMTOKEN=$BOTSTELEGRAMTOKEN sydalsitc/telegram-poll-bot:0.9.0-amd64

Add the flag "-d" for creating a background process if you like.

The demo-bot directory gets mounted inside the container at /app, making code and config available. Docker then

  • starts entrypoint.sh
  • that runs the python code
  • which loads the config json file.

Telegram token

The bot need a telegram token for authentication. The python code awaits this in an environment variable called BOTSTELEGRAMTOKEN which is passed through from the outside by the docker-compose.yml file.

This way works fine for a small testing setup but is not recommended for production environments. Make sure to use secrets with docker swarm and kubernetes while adapting the code respectively.

Commands

  • /about - tells a short story about the bot itself (which ist defined in the config json file).
  • /version - shows version of bot.py and the config file
  • /hello - just says hello and echoes the name of the calling user
  • /userid - shows the numeric user ID of the calling user - which can be used to secure the /polls call just for admins.
  • /polls - creates the polls which are defined in the config file. This command is restricted. Make sure your numeric user ID is in the field 'bot.authUsers' in the config file.

Tag summary

Content type

Image

Digest

sha256:dc5135f7b

Size

215.6 MB

Last updated

about 1 year ago

docker pull sydalsitc/telegram-poll-bot:0.9.0-amd64