Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method to send messages to a channel using telegram bot API, python 3 and JobQueue

Basically I'm trying to understand how this API works, by doing the following .I'm not able to get the message to my channel (I'm sending the /test command from my telegram account). Also, how I'm supposed to use JobQueue and send auto-msgs every 3 hours for example? The documentation explanation doesn't works for me.

def test(bot, update):
    update.send_message(chat_id='@channelid', text='this is a test')

def main():
    # Create the EventHandler and pass it your bot's token.
    updater = Updater("457160310:AAFlxrH2uAaOMGrgO0suOXFM2gVKywsUL0E")
    dp = updater.dispatcher

    dp.add_handler(CommandHandler("test", test))

    dp.add_error_handler(error)

    updater.start_polling()

    updater.idle()


if __name__ == '__main__':
    main()
like image 861
user3927607 Avatar asked Jan 29 '26 20:01

user3927607


1 Answers

For the job implementation to send messages on intervals you can read this page that is full of examples. Someone should be the very same thing you want to do.

About the command thing, I think that the library doesn’t get commands from channels so you may consider to:

  • send the command in private chat to the bot and the bot sends the reply to the channel (better thing in my opinion)

  • handle messages from channels (not commands) and checking if the text of the message contains the command

I would suggest the first solution so you can even keep clean the channel

like image 178
91DarioDev Avatar answered Feb 01 '26 13:02

91DarioDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!