Davron Valiyevich
Davron Valiyevich

Reputation: 11

Telegram bot response the user requests using telegram-bot-sdk package in Laravel

I am creating a poll. I am using the telegram-bot-sdk package in Laravel. How can I respond to user requests? I want to create a poll using telegram bot and send to the group. First, enter the poll question and enter poll options! Example:

Bot:  Enter a question: 
User: Please rate our foot!
Bot:  Enter the poll options!
User: 1,2,3,4,5 
Bot:  Your poll is created! Do you want to send the poll to group?
User: Yes
Bot:  Your poll is sent! Thank you!

Please help me I am trying this for more than a week !

web.php

Route::post('/webhook', function () {
    $updates = Telegram::commandsHandler(true);
    $update = Telegram::getWebhookUpdate();

    if($update->message->text=='Create poll')
    {
        Telegram::sendMessage([
            'chat_id' => 621766615,
            'text' => 'Enter poll question?',
        ]);
    }
});

StartCommand

public function handle()
    {
        $text = 'Hi dear! Welcome to our bot.'.chr(10).chr(10);
        $update = Telegram::getWebhookUpdates();
        $chat_id = $update->getMessage()->getChat()->getId();

        $keyboard = [
            ['Create poll']
        ];

        $reply_markup = Keyboard::make([
            'keyboard' => $keyboard,
            'resize_keyboard' => true,
            'one_time_keyboard' => true,
        ]);

        if($chat_id=='621766615'){
            Telegram::sendMessage([
                'chat_id' => 621766615,
                'text' => $text,
                'reply_markup' => $reply_markup
            ]);
        }
        else{
            Telegram::sendMessage([
                'chat_id' => $chat_id,
                'text' => $text,
            ]);
        }
    }

telegram bot

telegram bot

It is my telegram bot.

Upvotes: 1

Views: 185

Answers (0)

Related Questions