How to make Python-Telegram_bot send a message without getting a commad?

Viewed 5667

I'm Making a telegram bot using Python-Telegram-bot. I wanna make it send a message to one specific user (myself in this case) to select an option. after that, it should take that option as a command and work as usual. but after 30 min... it should send me the same message making me choose an option just like before. How can I make i work?

def start(update: Update, context: CallbackContext) -> None:
    user = update.message.from_user.username
    print(user)
    context.bot.send_message(chat_id=update.effective_chat.id, text= "Choose an option. ('/option1' , '/option 2', '/...')")


def main():

    updater = Updater("<MY-BOT-TOKEN>", use_context=True)

    updater.dispatcher.add_handler(CommandHandler('start', start))

    updater.start_polling()
    updater.idle()


if __name__ == '__main__':
    main()

I want this to run without getting the /start command (the update). but after this... there will be normal functions that'll get updates and after 30 min I wanna run this "start" function again without getting an update.

1 Answers

You can get the bot object either from the updater or the dispatcher:

updater = Updater('<bot-token>')
updater.bot.sendMessage(chat_id='<user-id>', text='Hello there!')

# alternative:
updater.dispatcher.bot.sendMessage(chat_id='<user-id>', text='Hello there!')
Related