telegram - 如何通过网站 Telegram 向登录的用户发送消息?

标签 telegram telegram-bot

网站telegram如何给登录用户发送消息?

Telegram Login for Websites

Telegram bots are a powerful communication tool, but until today they couldn't start a conversation. Even if you wanted them to reach out to you, you had to chat them up first.

Bot API 3.6

Added the new field connected_website to Message. The bot will receive a message with this field in a private chat when a user logs in on the bot's connected website using the Login Widget and allows sending messages from your bot.

登录用户后,我的机器人无法使用 user_id 发送消息,即使 OnMessage 事件也未触发。

如何通过机器人发起对话?

感谢。

最佳答案

你在这里自己回答了你的问题:

Added the new field connected_website to Message. The bot will receive a message with this field in a private chat when a user logs in on the bot's connected website using the Login Widget and allows sending messages from your bot.

更多说明: 用户使用 Telegram 登录小部件登录后,您应该等待更新事件(假设您正在为 Telegram Bot 使用 Webhook 方法)。更新正文应该是这样的:

{
"update_id": 290285,
"message": {
    "message_id": 12,
    "from": {
        "id": 117854,
        "is_bot": false,
        "first_name": "",
        "last_name": "",
        "language_code": "fa"
    },
    "date": 1549829158,
    "chat": {
        "id": "you need this to start conversation",
        "type": "private",
        "first_name": "user_firstname",
        "last_name": "user_last name"
    },
    "connected_website": "the domain mapped to your bot"
}

从填写的“connected_website”可以看出这是第一次登录的用户并保存聊天ID以在以后开始下一次对话。 PS:我想知道为什么在 Telegram 中没有关于此的文档,或者至少我没有找到任何东西。

关于telegram - 如何通过网站 Telegram 向登录的用户发送消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49073980/

相关文章:

python - 相当于 dart 中的 python with 语句

Telegram:如何查找群聊 ID?

java - 如何在 telegram bot 中看到来自 java web 应用程序的传入 POST 请求

php - Telegram 机器人奇怪的错误 : Bad Request: wrong file identifier/HTTP URL specified

telegram - 尝试发送长 Markdown 消息时出现 "telegram.error.BadRequest: Entities_too_long"错误。最大字符串长度限制是多少?

尝试编辑消息 : "Bad Request: message not found" 时出现 Telegram Bot API 错误

node.js - 在 Telegram Bot 之间共享消息

java - Autowire 在使用 Spring Boot 的 telegram 应用程序中不起作用

telegram - 如何在不向其发送消息的情况下获取 Telegram channel ID

python-telegram-bot错误 'CallbackContext'对象没有属性 'message'