Answer the question
In order to leave comments, you need to log in
Error in Telegram PHP Bot?
The code
$data = json_decode(file_get_contents('php://input'));
if (isset($data)) {
$message = Array(
'chat_id' => $data->{'message'}->{'chat'}->{'id'},
'message_id' => $data->{'message'}->{'message_id'},
'text' => $data->{'message'}->{'text'},
'from' => $data->{'message'}->{'from'}->{'id'},
'username' => $data->{'message'}->{'from'}->{'username'},
'firstname' => $data->{'message'}->{'from'}->{'first_name'},
'lastname' => $data->{'message'}->{'from'}->{'last_name'},
'new_chat_member' => $data->{'message'}->{'new_chat_member'},
'left_chat_member' => $data->{'message'}->{'left_chat_member'}
);
$callback = Array(
'id' => $data->{'callback_query'}->{'id'},
'type' => $data->{'callback_query'}->{'data'},
'chat_id' => $data->{'callback_query'}->{'message'}->{'chat'}->{'id'},
'from' => $data->{'callback_query'}->{'from'}->{'id'},
'username' => $data->{'callback_query'}->{'from'}->{'username'},
'firstname' => $data->{'callback_query'}->{'from'}->{'first_name'},
'lastname' => $data->{'callback_query'}->{'from'}->{'last_name'},
'message_id' => $data->{'callback_query'}->{'message'}->{'message_id'},
'message_text' => $data->{'callback_query'}->{'message'}->{'text'}
);
}
Answer the question
In order to leave comments, you need to log in
what is the problem - says the interpreter. accessing non-existent properties of an object. these fields did not come to json.
100% working...
$callbackData = file_get_contents(" php://input ");
$ac = json_decode($callbackData, true);
if (isset($ac["message"]))
{
//Information about the sender of the command
$idMessage = $ac['message']['message_id'];
$fromGroup = (empty($ac['message']['chat']['id'])) ? 0 : $ac['message']['chat']['id'];
$fromUser = $ac['message']['from']['id'];
$from = ($fromGroup != 0) ? $fromGroup : $fromUser;
$user_info = $ac['message']['from'];
$command = $ac['message']['text'];
} else if (isset($ac["callback_query"
$fromGroup = (empty($ac['callback_query']['message']['chat']['id'])) ? 0 : $ac['callback_query']['message']['chat']['id'];
$fromUser = $ac['callback_query']['from']['id'];
$from = ($fromGroup != 0) ? $fromGroup : $fromUser;
$user_info = $ac['callback_query']['from'];
$command = $ac['callback_query']['data'];
$editMessage = true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question