A Telegram bot to answer messages with predetermined responses.
165
Source code available on GitHub
A Telegram bot to answer messages with predetermined responses.
The answers are defined in the config.json file, and support the response to be triggered by either a normal user or an admin. For ease of use, the docker compose will mount a local directory with such file. The config file can be reloaded at any time with the /reload command.
More responses can be added either via the /addcommand bot command in a private chat with the bot or by editing the config file. To be able to use /addcommandyou need to first /claim the bot in a private chat with it, or provide your Telegram ID as an environment variable in the compose file.
Be sure to use a compose file, you can find an example at the bottom.
compose.yaml file in the desired directory. (Example at the bottom of this page.)
compose.yaml file as an environment variablecompose.yaml file as an environment variable. This will give you ownership of the bot.config.json file in your local mounting point. (Example at the bottom of this page.)docker compose up -d (-d option for detached mode; the container will run in the background).Commands with a checkmark in the Owner or Admin columns require you to be either an admin or the owner.
Commands with a checkmark in the Private only work in a private chat with the bot.
Admins are able to trigger user registered commands in a private chat with the bot, for everyone else they only work in a group chat.
| Owner | Admin | Private | Notes | |
|---|---|---|---|---|
/addadmin | ✔️ | ❌ | ❌ | Gives a user admin privileges for the bot. If used in private the bot will ask to forward a message from the user to be added as an admin; if used in a group the command will need to be used in reply to a message of the user to be added as an admin. |
/deladmin | ✔️ | ❌ | ✔️ | Removes admin privileges from a user. Provides a list of current admins through an Inline Keyboard. |
/reload | ✔️ | ❌ | ✔️ | Reloads the config.json file (Only needed when said file is manually edited). |
/addcommand | ✔️ | ✔️ | ✔️ | Starts the process of adding a new command via chat. An optional parameter reset can be sent along (/addcommand reset) to reset the process. |
/delcommand | ✔️ | ✔️ | ✔️ | Deletes an existing command. Provides a list of commands through an Inline Keyboard. |
/commandlist | ✔️ | ✔️ | ❌ | Replies with a list of user registered commands divided into admin and user commands. |
/claim | ❌ | ❌ | ✔️ | Provides ownership of the bot to the first user using the command. Can only be used once, and only if no OWNER_ID has been provided in the compose.yaml file. |
/start | ❌ | ❌ | ✔️ | Replies with a standard greeting and a link to this documentation. |
/help | ❌ | ❌ | ❌ | Replies with the list of native commands, short description of their purpose and a link to this documentation. |
This is a base config file.
Responses in the admin section will only be sent if the command is triggered by an admin.
Responses in the user section will be triggered by anyone.
Just add more commands as you please by adding to the JSON dictionary. The key will be the /command the bot will respond to, the value will be the actual response.
Responses must abide by Telegram Markdown V2 Style rules if added manually to this file, or they won't work.
{
"admin": {
"example1": "example 1"
},
"user": {
"example2": "example 2"
}
}
This is an example of the docker compose file you can use to run the bot.
Make sure to put your config.json in the mounted directory, or the container will not start.
If you wish to provide the OWNER_ID, make sure to remove the comment.
services:
bot:
image: "torkd/simple-reply-bot"
volumes:
- ./config/:/bot/config/
environment:
BOT_TOKEN: <BOT_TOKEN>
#OPTIONAL OWNER_ID: <OWNER_ID>
Content type
Image
Digest
sha256:aed0140b4…
Size
35.2 MB
Last updated
almost 3 years ago
docker pull torkd/simple-reply-bot