<?php
namespace app\components;

class TelegramHelper
{
    public static function sendMessage($chatId, $message)
    {
        $token = '8259095090:AAFNqxsm6Jnov2LyybLRAZ4eufZL9ry-O3I'; // Твой токен
        $url = "https://api.telegram.org/bot$token/sendMessage";

        $data = [
            'chat_id' => $chatId,
            'text' => $message,
            'parse_mode' => 'HTML',
        ];

        $options = [
            'http' => [
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data),
            ],
        ];

        $context  = stream_context_create($options);
        file_get_contents($url, false, $context);
    }
 public static function sendMessageWithKeyboard($chatId, $message, $keyboard)
{
    $token = '8259095090:AAFNqxsm6Jnov2LyybLRAZ4eufZL9ry-O3I';
    $url = "https://api.telegram.org/bot$token/sendMessage";

    $data = [
        'chat_id' => $chatId,
        'text' => $message,
        'parse_mode' => 'HTML',
        'reply_markup' => json_encode($keyboard),
    ];

    $options = [
        'http' => [
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ],
    ];

    $context  = stream_context_create($options);
    file_get_contents($url, false, $context);
}
public static function sendCallbackAnswer($callback_id, $text)
{
    $token = '8259095090:AAFNqxsm6Jnov2LyybLRAZ4eufZL9ry-O3I';
    $url = "https://api.telegram.org/bot$token/answerCallbackQuery";

    $data = [
        'callback_query_id' => $callback_id,
        'text' => $text,
        'show_alert' => false,
    ];

    $options = [
        'http' => [
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ],
    ];

    $context  = stream_context_create($options);
    file_get_contents($url, false, $context);
}

}
