@DTPlayer

Как решить проблему c телеграмм ботом на php?

$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'}
    );
}

Ошибка:
[09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$last_name in * on line 95 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$new_chat_member in on line 96 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$left_chat_member in on line 97 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 101 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'id' of non-object in on line 101 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 102 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'data' of non-object in on line 102 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 103 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'message' of non-object in on line 103 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'chat' of non-object in on line 103 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'id' of non-object in on line 103 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 104 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'from' of non-object in on line 104 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'id' of non-object in on line 104 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 105 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'from' of non-object in on line 105 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'username' of non-object in on line 105 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 106 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'from' of non-object in on line 106 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'first_name' of non-object in on line 106 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 107 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'from' of non-object in on line 107 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'last_name' of non-object in on line 107 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 108 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'message' of non-object in on line 108 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'message_id' of non-object in on line 108 [09-Jun-2020 21:12:23 UTC] PHP Notice: Undefined property: stdClass::$callback_query in on line 109 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'message' of non-object in * on line 109 [09-Jun-2020 21:12:23 UTC] PHP Notice: Trying to get property 'text' of non-object in *** on line 109

Что делать?
  • Вопрос задан
  • 117 просмотров
Пригласить эксперта
Ответы на вопрос 2
@ar2rsoft
PHP-developer
Проверить тип запроса, перед обработкой - message/callback
Проверить свойство на наличие, перед его использованием
Ответ написан
Комментировать
@transformagency
Может быть тут есть ответ? https://transformagency.com/
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
Бюро Цифровых Технологий Санкт-Петербург
от 120 000 до 180 000 ₽
03 мая 2024, в 16:26
3000 руб./за проект
03 мая 2024, в 16:09
1200 руб./за проект
03 мая 2024, в 16:06
3000 руб./за проект