Telegram bot only allowed to post upon events?

核能气质少年 提交于 2021-01-05 12:47:48

问题


It seems like Telegram bot revolves around the idea of reacting to human events (whether in channel or private messages).

Is there any way to have the Telegram bot post on a channel independently?

Am I really forced to use webhooks for this?

I would like my bot to read blockchain operations and post these on my particular channel regardless of human events.


回答1:


You can use polling (instead webhook) in the Python Telegram Bot framework

updater = Updater('token', use_context=True)

dp = updater.dispatcher
updater.start_polling()

# initiate message from backend
dp.bot.send_message(chat_id='xxxx', text='Hello')

As you notice you need a valid chat_id which you get when there is an incoming message/command or the bot is added to a group. You will need to capture that event and save it.



来源:https://stackoverflow.com/questions/64679299/telegram-bot-only-allowed-to-post-upon-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!