1

I have a telegram bot where the user can send /start command and I will receive this command on my server via web hook. In 99% of cases the request from telegram looks like this:

{
   "update_id":99999999,
   "message":{
      "message_id":9999,
      "from":{
         "id":999999999,
         "is_bot":false,
         "first_name":"first_name",
         "last_name":"last_name",
         "language_code":"code"
      },
      "chat":{
         "id":99999999,
         "first_name":"first_name",
         "last_name":"last_name",
         "type":"private"
      },
      "date":1665383118,
      "text":"/start",
      "entities":[
         {
            "offset":0,
            "length":6,
            "type":"bot_command"
         }
      ]
   }
}

The object is "message" and I have a text "/start" there.

But sometimes from some new users who hasn't used this bot before when they send start the request from telegram look like this:

{
   "update_id":999999999,
   "my_chat_member":{
      "chat":{
         "id":999999999,
         "first_name":"first_name",
         "type":"private"
      },
      "from":{
         "id":999999999,
         "is_bot":false,
         "first_name":"first_name",
         "language_code":"code"
      },
      "date":1665381194,
      "old_chat_member":{
         "user":{
            "id":8888888888,
            "is_bot":true,
            "first_name":"bot_name",
            "username":"bot_name"
         },
         "status":"member"
      },
      "new_chat_member":{
         "user":{
            "id":8888888888,
            "is_bot":true,
            "first_name":"bot_name",
            "username":"bot_name"
         },
         "status":"kicked",
         "until_date":0
      }
   }
}

The object "my_chat_member" and the "start" command was not received from this user.

This happens for users on IPhone, Android, PC, Web. I can't understand why it happens and how to fix.

daewoosh
  • 193
  • 3
  • 11
  • The second request is a status update that says your bot got kicked from a group or blocked by the user in a private chat. Are you sure that is not the case? – Cem Oct 10 '22 at 08:31
  • 1
    @Cem Yes, the user just sends /start command to the bot, but instead of receiving a message, I receive new_chat_member on my server. And this happens only sometimes. In most cases I receive "message". – daewoosh Oct 10 '22 at 08:38

2 Answers2

0

The problem was on my server side. I used int32 for users' and chats' ids but they can be bigger. Using the correct type solved the problem.

daewoosh
  • 193
  • 3
  • 11
0

Message type "my_chat_member" means somebody described as "from" wants to unsubscribe from bot. "status":"kicked" says the same. Here https://core.telegram.org/bots/api you can read Getting updates topic