简体   繁体   English

Python 电报机器人 - 机器人可以发送聊天中的第一条消息吗?

[英]Python telegram bot - can the bot send the first message in chat?

Is it possible to get a bot to send the first message in the chat without running a command like "/Start"?是否可以让机器人在不运行“/Start”之类的命令的情况下发送聊天中的第一条消息?

Maybe it possible to save the chat_id of the requested user in advance and send him a message in the future, thus allowing the bot to send a first message in chat according to a predefined condition that will trigger him?也许可以提前保存请求用户的 chat_id 并在将来向他发送消息,从而允许机器人根据预定义的条件在聊天中发送第一条消息,这将触发他?

I searched for an answer online but could not find one.我在网上搜索了答案,但找不到。 Can you send me a link to a tutorial that explains how to do this?你能给我一个解释如何做到这一点的教程的链接吗? Thanks in advance提前致谢

Yoav Giladi:)约阿夫吉拉迪:)

One solution is to use a Telegram Bot deeplink to provide an entry point to the Chatbot that does not require the users typing the /Start command.一种解决方案是使用 Telegram Bot深层链接为聊天机器人提供入口点,不需要用户键入/Start命令。

After the very first interaction you can the obtain the chat_id which can be stored for using it to initiate a message later:在第一次交互之后,您可以获得可以存储的chat_id ,以便稍后使用它来发起消息:

context.bot.send_message(chat_id, text='Howdy')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM