I'm trying to get the title of a group chat but it always pass me Undefined array key "chat"
This is the code I'm using:
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$title = $update['chat']['title'];
I'm probably doing something wrong with the bot APIs, this is the result of /getChat?chat_id=telegram_id
{"ok":true,"result":{"id":TELEGRAM_ID,"title":"NAME","type":"supergroup",...}}
Here's a minimal example:
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$title = $update['chat']['title'];
$chatid = $update['message']['chat']['id'];
if ($chatType == 'supergroup'){
sendMessage($chatid, "The chat is: $title")
}
function sendMessage($chatid, $text){
$url = "api.telegram.org/botBOT_TOKEN/sendMessage?chat_id=$chatid&parse_mode=HTML&text=" . urlencode($text);
file_get_contents($url);
}