J
J
Jjran2021-08-26 09:36:17
Python
Jjran, 2021-08-26 09:36:17

How can a bot send a message if the user hasn't entered anything?

I have a question from a bot

mes = bot.send_message(call.chat.id, text="Введите запрос:")
bot.register_next_step_handler(mes, get_data_func)

How to make it so that if the user has not entered anything for example for 10 hours, then a message is sent to him? Where to tie if here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-08-26
@Jjran

You can't do this with the standard tools of this library.
I can offer an alternative:
When registering register_next_step_handler , pass one more parameter, which will be equal to the date of the message mes.date , and pass this parameter to the get_data_func function. In the get_data_func itself, check the difference between the date of the user's new message and the date of the previous message. If more than 10 hours - break the current script and issue a new message.

...
    mes = bot.send_message(call.chat.id, text="Введите запрос:")
    bot.register_next_step_handler(mes, get_data_func, mes.date)
...
def get_data_func(message, date):
    if message.date-date > 36000: # 10 часов в секундах
        <тут уже ваши действия>

The disadvantage of this approach is that if the user scores on the bot, no message will come to him.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question