<?php

// to set a webhook https://api.telegram.org/bot{token}/setWebhook?url={url}
// Get the incoming JSON payload from Telegram
$update = file_get_contents('php://input');
$update = json_decode($update, true);
$token = "7701439773:AAEWk1o6Jhe0znSvEjRj1fDxbTOO8XhRZmI";


// Check if a message exists in the payload
if (isset($update['message'])) {
    $chat_id = $update['message']['chat']['id']; // Extract the chat ID

    // Check if the message contains the word "hello"
    if (stripos($update['message']['text'], 'hello') !== false) {
        // Respond with the chat ID
        $response = [
            'chat_id' => $chat_id,
            'text' => "Hello to you 2",
        ];

        // Send the response back to Telegram
        file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($response));
    }

       // Check if the message contains the word "hello"
       if (stripos($update['message']['text'], 'my name is') !== false) {
        // Respond with the chat ID
        $response = [
            'chat_id' => $chat_id,
            'text' => "DUMBASS",
        ];

        // Send the response back to Telegram
        file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($response));
    }

    if (stripos($update['message']['text'], '/chatid') !== false) {
        // Respond with the chat ID
        $response = [
            'chat_id' => $chat_id,
            'text' => "The current chat ID is: $chat_id",
        ];

        // Send the response back to Telegram
        file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($response));
    }

    if (stripos($update['message']['text'], '/help') !== false) {
        // Respond with the chat ID
        $response = [
            'chat_id' => $chat_id,
            'text' => "TO GET THE CHAT ID: type /chatid \n TO GET A HELLO MESSAGE: type /hello",
        ];

        // Send the response back to Telegram
        file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($response));
    }



}
?>