defstudio / telegraph

Telegraph is a Laravel package for fluently interacting with Telegram Bots
MIT License
658 stars 117 forks source link

Answer in webhook request #609

Open g1n-ru opened 1 month ago

g1n-ru commented 1 month ago

Hello, telegram can receive messages and other methods in request:

https://core.telegram.org/bots/faq#how-can-i-make-requests-in-response-to-updates

Can I send messages without new http request?

For example in native php (webhook script):

    header("Content-type: application/json");
    echo json_encode([
        'method' => 'sendMessage',
        'chat_id' => $chat_id,
        'text'=> $message,
        'parse_mode'=>'Markdown',
        'reply_markup' => json_encode($menu)
     ]);
fabio-ivona commented 1 month ago

I think we can do it, let me code a POC for this in the next days

g1n-ru commented 1 month ago
    #[NoReturn] public function instantReply($text): void
    {
        $payload = [
            'method' => 'sendMessage',
            'chat_id' => $this->chat->chat_id,
            'text' => $text,
            'parse_mode' => 'HTML',
            ...$this->keyboard(),
        ];

        header('Content-Type: application/json');

        exit(json_encode($payload));
    }

I use this now. But I think, this best way for fast answer without additional http queries. Bot work very fast with this.

Thank You Friend for you work!

g1n-ru commented 2 days ago

any news? Please... )))

fabio-ivona commented 1 day ago

it is planned in our developments