Telegram-bot-sdk: Many replies to callback

Created on 31 May 2017  路  12Comments  路  Source: irazasyed/telegram-bot-sdk

$keyboard = Keyboard::make()
->inline()
->row(
    Keyboard::inlineButton(['text' => 'Btn 1', 'callback_data' => 'test']),
    Keyboard::inlineButton(['text' => 'Btn 2', 'callback_data' => 'data_from_btn2'])
);
$response = $telegram->sendMessage([
    'chat_id' => $chat_id, 
    'text' => 'Hello World',
    'reply_markup' => $keyboard
]);
$update = $telegram->getWebhookUpdate();
    if ($update->isType('callback_query')) {
        $query = $update->getCallbackQuery();
        $data  = $query->getData();
        $chid = $query->getFrom()->getId();
        $telegram->sendMessage([ 'chat_id' => $chid, 'text' => $data]);
    }

screenshot_1

All 12 comments

@Troodi

I've got some problems on importing the keyboard class, could you show me your complete code?

Use 3.x-dev version

use Telegram\Bot\Api;
use Telegram\Bot\Keyboard\Keyboard;

Sad to see, I tried to use it inside laravel, but it seems like the dev version is buggy as hell for laravel :/.

if ($result->isType('callback_query')) {
        $query = $result->getCallbackQuery();
        $data  = $query->getData();
        $chid = $query->getFrom()->getId();
        $json = json_decode($query->getMessage(), true);
        $telegram->sendMessage([ 'chat_id' => $chid, 'text' => '孝械褋褌懈褉芯胁邪薪懈械' ]);
        exit;
    }

It helped, but how to remove the time icon?
screenshot_1
The message was sent, but it still hangs.

@Troodi When you use webhook, you need to send header status code 200. If you don't do that, then Telegram assumes your server has not accepted their update.

You can just return something like "ok". And it should automatically send 200 code.

Thx, but clock icon not hide.

@ja-heller Sorry that you think that.

It really isn't. I'm using it live here for weeks and it's very stable. It is however undocumented, because so much changed in the code and so your 2.xx code just isn't going to work.

Either wait until 3 is released fully with docs, or install it dig into the code until we get it done.

@jonnywilliamson

Take a look into this this.

Has anyone solved the problem with the clock icon?

@illiamorkva you have to call answerCallbackQuery and pass callback_id to it

 $update = Telegram::getWebhookUpdates();
 $query = $update->getCallbackQuery();
 $this->callback_id = $query->getId();

Telegram::answerCallbackQuery([
    'callback_query_id' => $this->callback_id
]);

Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mccarlosen picture mccarlosen  路  3Comments

Enelar picture Enelar  路  3Comments

dswtech picture dswtech  路  4Comments

realtebo picture realtebo  路  4Comments

maminbajand picture maminbajand  路  4Comments