Telegram Bot, v1.2
Posted on

Telegram channel bot.
Support a voting for messages.
Change Log
- support a voting for messages:
- support inline keyboards in messages;
- support an update of inline keyboards;
- save a vote to a database.
Features
- publication into a specified channel:
- sending of text messages;
- sending of photo messages;
- voting for messages:
- restrictions (via a remembering in an SQLite database):
- one vote per one user;
- possibility change an own vote (optionally, i.e. may be disabled);
- decor:
- voting by an inline keyboard;
- customizable a buttons text;
- displaying of a voting result on buttons;
- restrictions (via a remembering in an SQLite database):
- working mode:
- run as a web service;
- control via the RESTful API;
- utility for a sending of requests to the API:
- making of a path to a photo absolute.
Usage
$ telegram-bot -v | --version
$ telegram-bot -h | --help
$ telegram-bot
Options:
-v,--version— show the version message and exit;-h,--help— show this help message and exit.
Environment variables:
TELEGRAM_BOT_TOKEN— Telegram API access token;TELEGRAM_BOT_CHANNEL— Telegram channel name;TELEGRAM_BOT_PORT— bot API port (default:4000);TELEGRAM_BOT_ACCEPT_TEXT— text of the accept button (default:Accept);TELEGRAM_BOT_REJECT_TEXT— text of the reject button (default:Reject);TELEGRAM_BOT_DATABASE— path to the SQLite database file (default:./votes.db);TELEGRAM_BOT_CHANGEABLE_VOTE— flag denoting changeability of a vote (allowed:FALSEandTRUE; default:TRUE).
Environment variables can be specified in a .env config in the format:
NAME_1=value_1
NAME_2=value_2
...
See details about the format: https://github.com/motdotla/dotenv#rules.
A .env config will never modify any environment variables that have already been set.
Architecture
UML component diagram in the PlantUML language:
@startuml
skinparam componentStyle uml2
cloud {
() "Telegram Bot API" as TelegramBotAPI
}
package "Main Thread" {
[Web Server] -up- API
[Web Server] .down.> [Bot] : sendMessage
[Web Server] .down.> [Bot] : sendPhoto
[Bot] .down.> TelegramBotAPI : getUpdates
[Bot] .down.> TelegramBotAPI : sendMessage
[Bot] .down.> TelegramBotAPI : sendPhoto
[Bot] .down.> TelegramBotAPI : editMessageReplyMarkup
}
package "Bot Polling Thread" {
database "SQLite" {
[Votes]
}
[Bot Polling Loop] .up.> [Votes] : add a vote
[Bot Polling Loop] .up.> [Votes] : count votes
[Bot Polling Loop] .down.> [Bot] : getUpdates
[Bot Polling Loop] .down.> [Bot] : editMessageReplyMarkup
}
[Sending Utility] .down.> API : message
[Sending Utility] .down.> API : photo
@enduml
Rendered UML component diagram:
Repository
Link: https://github.com/thewizardplusplus/telegram-bot/tree/v1.2.
Content: code.
License: GPL-3.0-or-later.
Screenshots
Run of the web service

Copyrights
- road photo — Pixabay License, Copyright © 2013 Larisa-K, https://pixabay.com/en/road-asphalt-space-sky-clouds-220058/.