Create templates for Telegram bots from a config file
- Create a bot using @BotFather
- Set your bot parameters in
config/conf.yml
- Run
make_bot.py
to createbot.py
- Run
python bot.py
to run your bot
bot_token : [str] # token generated by @BotFather
private : [bool] # restrict the access to a list of users
allowed_users : [List] # list of user ids to grant access to in case private==true
inline : [bool] # enable/disable inline mode, if true it must be activated by @BotFather
handlers : [List] # list of handlers that will be generated
# one handler is specified by:
type : [str] # one of "msg","cmd", msg for text, cmd for commands (e.g. /start)
function : [str] # name of the function associated to this handler
content_type : [str] # expected content of the msg, one of "text", "photo", "audio", etc.. See https://core.telegram.org/bots/api#sendmessage
return_content_type : [str] # expected content of the return msg, same as content_type
For more information, take a look at: config/config.example.yml
The generated bot template is in: generated_bot.py
At the moment the bot token is in clear text in bot.py
, this is a dangerous behavior if you want to version your bot. Once you have generated the token, export it in an environment variable and use that in bot.py
.
Example:
.bashrc
export MY_BOT_TOKEN='S0m3HexString'
bot.py
updater = Updater(token=os.environ["MY_BOT_TOKEN"], use_context=True)
- add arg parser
- fix jinja template whitespaces management