1

I'm trying telegram bot of Webhook ex. new user join check database not my membership to kick user!

<?php
$API_KEY = 'token';
define('API_KEY', $API_KEY);

function bot($method,$datas=[]){
$url = "https://api.telegram.org/bot" . API_KEY . "/" . $method;
$ch  = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$res = curl_exec($ch);
if (curl_error($ch)) {
    var_dump(curl_error($ch));
} else {
    return json_decode($res);
}
}

$update     = json_decode(file_get_contents('php://input'));
$message    = $update->message;
$text       = $message->text;
$chat_id    = $message->chat->id;
$from_id    = $message->from->id;
$new_member = $message->new_chat_member->id;
$memberid   = file_get_contents('whitelist.txt'); //put userid in whitelist.txt
$whitelist  = explode("\n", $memberid);

if ($new_member) {
    if (!in_array($chat_id, $whitelist)) {
           bot('kickChatMember',[
          'chat_id'=>$chat_id,
          'user_id'=>$message->new_chat_member->id]);
    }
}
?>

I tried it gave me error results "Array" something wrong format json this code?

1 Answers1

0

You could try $update["message"] instead of $update->message; and use the same syntax for remaining variables too. For me, it's working perfectly fine.

Brian B
  • 80
  • 1
  • 9