问题
How to send a message to the user who logged in through the telegram in website?
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.
and
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.
After login user,my bot can not send message with use user_id,Even the OnMessage event is not fired.
How start a conversation by bot?
Thankful.
回答1:
You answered your question yourself here :
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.
More descriptions: After the user logged in with telegram login widget,you should wait for an update event (assuming you'r using Webhook method for your telegram bot). the update body should be something like this:
{
"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"
}
from the "connected_website" filled you can realize this is a user logged in for the first time and save the chat id to start next conversations in future. PS : I wonder why there is no documentation about this at telegram or at least I didn't found anything.
来源:https://stackoverflow.com/questions/49073980/how-to-send-a-message-to-the-user-who-logged-in-through-the-telegram-in-website