skip to Main Content

I want to read user names from receiving updates however but I face an special issue.

For some users, $message['from']['username'] contains a Telegram User Name however for some users this parameter is not defined.

How can I reliably receive user names ( get username field), using Telegram Bot API?

2

Answers


  1. It’s not mandatory to have a username, so there are users with no username.

    Login or Signup to reply.
  2. Simply use this code:

    if(!$username){
    $parameters = array("chat_id" => $chatId, "text" => "Set a username to use this bot!nSettings > Username");
    }
    

    When a user have no username it can’t use the bot.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search