问题
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