Telegram Bot: using offset in getUpdates method
I want to create a telegram bot to subscribe to a channel so that subscribers can receive site updates. But I need the user to start communicating with my bot. I will use deep linking according to this url: https://core.telegram.org/bots#deep-linking (assuming there are 2 users)
- Show below link # 2 https://telegram.me/MyBot?start= $ unique_code
- User # 2 clicks on the link and starts a chat with the bot.
- User # 2 returns to my site and clicks the checkout button.
- The site creates a getUpdates request and finds the chat_id associated with the unique_id for the user.
- The offset will be increased by 1.
Now there is a problem. When the bias has increased, as for user # 1, who starts chatting with the bot immediately in front of user # 2. If # 1 presses the check button after increasing the offset by # 2, the bot will not receive message # 1.
ps I don't want to use ssl and webhook
Sorry for the bad english.
You are almost right about what you are trying to achieve. Two things:
- Step 3 is unnecessary.
- You must store this $ unique_id somewhere, along with the username on your website. Then, when that person clicks on your link with your unique ID, you can associate a user with a userId for the user's user.
So the steps:
- Create a unique code (let's call it $ unique_code). Save this code along with the username currently logged in to your website (call this $ username) into the database.
- Show user # 2 the link to this unique code ( https://telegram.me/MyBot?start= $ unique_code)
- The user clicks on the link, after which your bot receives a message with unique_code $ ('/ start $ unique_code').
- The bot binds $ unique_code to $ username and saves the chat_id of the user who sent the message to the database. (message.chat.id - see https://core.telegram.org/bots/api#message )
Now when you want to send a message to $ username, just find their chat_id in the database and send a message to this chatId ( https://core.telegram.org/bots/api#sendmessage ).