[英]python-telegram-bot send message without using update and context
当我在计算机上处于活动状态时,我希望我的机器人向电报聊天发送消息。 我编写了其他使用此功能发送消息的功能。
# Function to send messages back to chat
def sendmessage(update, context, message):
context.bot.send_message(chat_id=update.effective_chat.id, text=message)
然而,这使用来自调度程序和处理程序的更新和上下文。
我想发送消息的 function 在单独的线程中运行,并且不使用调度程序或处理程序。 因此我不能使用上面的 function。 如果不使用更新和上下文,我似乎无法弄清楚如何发送消息。
我现在拥有的:
def user_returned():
row_list = []
with open('log.csv') as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
for row in csv_reader:
row_list.append(row)
last_line = row_list[-1]
second_to_last_line = row_list[-2]
print(last_line['active'], second_to_last_line['active'])
if last_line['active'] == 'True' and second_to_last_line['active'] == 'False':
message = 'user is back'
context.bot.send_message(chat_id=update.effective_chat.id, text=message)
else:
message = 'still gone'
context.bot.send_message(chat_id=update.effective_chat.id, text=message)
import telegram
bot=telegram.Bot(token=bot_token)
chat=123456
bot.sendMessage(chat, msg)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.