Core: Restrict BOT Access

Created on 7 Jun 2017  路  2Comments  路  Source: php-telegram-bot/core

Required Information

  • Operating system: Windows
  • PHP version: 5.12
  • PHP Telegram Bot version: Latest
  • Using MySQL database: yes
  • MySQL version:
  • Update Method: Webhook
  • Self-signed certificate: yes
  • RAW update (if available):

Expected behaviour

Actual behaviour

Steps to reproduce

Extra details

I want to restrict my BOT to certain groups only. I can do that by checking the chat id against the group id. But the problem is I have too many commands and I don't want to add access code to each of the PHP scripts.
I want to implement the code on a single page, like the hook. But how can I do that in the hook or in any other single page?

Most helpful comment

This should put you in right direction:

$POST = file_get_contents("php://input");
$POST_DATA = json_decode($POST, true);

$user_id = null;
if (isset($POST_DATA['message']['chat']['id'])) {
    $user_id = $POST_DATA['message']['chat']['id'];
}

$allowed = [];

if (!in_array($user_id, $allowed)) {
exit;
}

You will have to modify it a bit to consider other types of updates.

The code should be before handling the webhook in hook script.

All 2 comments

This should put you in right direction:

$POST = file_get_contents("php://input");
$POST_DATA = json_decode($POST, true);

$user_id = null;
if (isset($POST_DATA['message']['chat']['id'])) {
    $user_id = $POST_DATA['message']['chat']['id'];
}

$allowed = [];

if (!in_array($user_id, $allowed)) {
exit;
}

You will have to modify it a bit to consider other types of updates.

The code should be before handling the webhook in hook script.

I like this very much, would be cool to implement this into the manager 馃槆

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mohsenshahab picture mohsenshahab  路  4Comments

Recouse picture Recouse  路  3Comments

irmmr picture irmmr  路  3Comments

vansanblch picture vansanblch  路  3Comments

TheSleepySlee picture TheSleepySlee  路  3Comments