我对我的电报机器人感到左右为难。假设我必须创建一个函数,每周/每月一次向每个连接到机器人的用户询问一个问题:
def check_the_week(bot, update):
reply_keyboard = [['YES', 'NO']]
bot.send_message(
chat_id=update.message.chat_id,
text=report,
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)) # sends the total nr of hours
update.reply_text("Did you report all you working hour on freshdesk for this week?",
ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
if update.message.text == "YES":
update.message.reply_text(text="Are you sure?",
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
# Asks confirmation
if update.message.text == "YES":
update.message.reply_text(text="Thank you for reporting your working hours in time!")
elif update.message.text == "NO":
update.message.reply_text(text="Please, check you time reports and add missing")
elif update.message.text == "NO":
update.message.reply_text(text="Please, check you time reports and add missing")
我希望每周触发此功能。我正在考虑使用JobQueue https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-JobQueue。问题是,在这种情况下,函数应该有两个参数 - bot 和 job_queue,但没有更新:
def callback_30(bot, job):
bot.send_message(chat_id='@examplechannel',
text='A single message with 30s delay')
j.run_once(callback_30, 30)
如何在电报机器人中创建作业调度程序(或任何其他解决方案)以每周触发一次我的功能?
附注请不要使用“while True”+time.sleep() 解决方案。循环永远卡住了,我试过了。