G
G
Gikerven2022-03-19 17:43:28
PHP
Gikerven, 2022-03-19 17:43:28

How to make access to the response message from the bot in the TG bot, only to those users who are registered in the array?

Hello.

It is necessary that the function check the username of the person who wrote with the username that is in the list, and if it matches, it returns the answer in the form of this same username

, so I wrote the condition:

case ($text=='Хочу прогноз погоды' and $username == user_access()):
    $ANSWER = shape(2);
    $keyboard = keyboard();
  break;


and a function to search for a name from a pre-prepared list, please tell me what is missing ..

function user_access(){
    $name = array('Имя1', 'Имя2');
if (in_array($username, $name))
  {
  echo $username;
  }
else
  {
  echo "Match not found";
  }
  return $name;
}


Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gikerven, 2022-03-20
@Gikerven

Thanks a lot for the solution: nokimaro , :

case ($text == 'Хочу прогноз погоды' && user_has_access($username)):
    $ANSWER = shape(2);
    $keyboard = keyboard();
break;

function user_has_access($username) {
    return in_array($username, [
        'user1',
        'имя2',   
        'имя3',
        'имя10',
    ]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question