<?php
$update = json_decode(file_get_contents("php://input"));

if(isset($update->message)) {
    $update_id  = $update->update_id ?? 'none';
    $message    = $update->message ?? 'none';
    $text       = $message->text ?? '';
    $from_id    = $message->from->id ?? 'none';
    $chat_id    = $message->chat->id ?? 'none';
    $chat_type  = $message->chat->type ?? 'private';
    $user_name  = $message->from->username ?? 'none';
    $first_name = htmlspecialchars($message->from->first_name ?? '', ENT_QUOTES, 'UTF-8');
    $message_id = $message->message_id ?? 'none';
}


if(isset($update->callback_query)) {
    $from_id    = $update->callback_query->from->id ?? 'none';
    $chat_id    = $update->callback_query->message->chat->id ?? 'none';
    $data       = $update->callback_query->data ?? '';
    $query_id   = $update->callback_query->id ?? 'none';
    $type       = $update->callback_query->message->chat->type ?? '';
    $first_name = htmlspecialchars($update->callback_query->from->first_name ?? '', ENT_QUOTES, 'UTF-8');
    $user_name  = $update->callback_query->from->username ?? 'ندارد';
    $message_id = $update->callback_query->message->message_id ?? 'none';
}


if(isset($update->chat_member)) {
    $chat_id    = $update->chat_member->chat->id ?? 'none';
    $chat_type  = $update->chat_member->chat->type ?? 'private';
    $from_id    = $update->chat_member->from->id ?? 'none';
    $user_name  = $update->chat_member->from->username ?? 'none';
    $first_name = htmlspecialchars($update->chat_member->from->first_name ?? '', ENT_QUOTES, 'UTF-8');
    $text       = '';
    $message_id = 'none';
}


if(isset($update->my_chat_member)) {
    $chat_id    = $update->my_chat_member->chat->id ?? 'none';
    $chat_type  = $update->my_chat_member->chat->type ?? 'private';
    $from_id    = $update->my_chat_member->from->id ?? 'none';
    $user_name  = $update->my_chat_member->from->username ?? 'none';
    $first_name = htmlspecialchars($update->my_chat_member->from->first_name ?? '', ENT_QUOTES, 'UTF-8');
    $text       = '';
    $message_id = 'none';
}

