core: Don't send message after selecting the button help me please

  • Operating system: Linux srv-plesk20.ps.kz 3.10.0-514.21.2.el7.x86_64 #1 SMP Tue Jun 20 12:24:47 UTC 2017 x86_64
  • PHP version: 7.0.21 (64bit); cgi-fcgi; Linux
  • Using MySQL database: no
  • Update Method: Webhook
  • Self-signed certificate: no

I have 2 commands InfoCallbackqueryCommand.php

<?php

namespace Longman\TelegramBot\Commands\SystemCommands;


use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;

class InfoCallbackQueryCommand extends SystemCommand
{
    protected $name = 'callbackquery';
    /**
     * @var string
     */
    protected $description = 'Reply to callback query';
    /**
     * @var string
     */
    protected $version = '1.1.0';
    /**
     * Command execute method
     *
     * @return \Longman\TelegramBot\Entities\ServerResponse
     * @throws \Longman\TelegramBot\Exception\TelegramException
     */
    public function execute()
    {
        $update            = $this->getUpdate();
        $callback_query    = $update->getCallbackQuery();
        $callback_query_id = $callback_query->getId();
        $callback_data     = $callback_query->getData();

        return Request::editMessageReplyMarkup([
           'chat_id' => $update->getMessage()->getChat()->getId(),
           'message_id' => $this->getMessage()->getMessageId(),
           'text' => 'test'
        ]);
    }
}

and MenuCommand.php

<?php
namespace Longman\TelegramBot\Commands\UserCommands;


use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Request;

class MenuCommand extends UserCommand
{
    protected $name = 'menu';
    protected $description = 'Show inline keyboard';
    protected $usage = '/menu';
    protected $version = '1.0.0';

    public function execute()
    {
        $chat_id = $this->getMessage()->getChat()->getId();

        $inline_keyboard = new InlineKeyboard([
            ['text' => 'Помощь', 'callback_data' => 'callbackquery'],
            ['text' => 'Информация', 'callback_data' => '!info'],
        ], [
            ['text' => 'Начало', 'callback_data' => '!start'],
        ]);

        $data = [
            'chat_id'      => $chat_id,
            'text'         => 'Выберите одну из предложенных команд',
            'reply_markup' => $inline_keyboard,
        ];
        return Request::sendMessage($data);
    }
}

And I do not understand how to as after pressing to send a message to the same chat. my bot @testMnpBot

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

This is my inlineKeyboard:

        $chat_id = $this->getMessage()->getChat()->getId();

        $inline_keyboard = new InlineKeyboard([
            ['text' => 'Prova', 'callback_data' => 'testcallback'],
            ['text' => 'Prova1', 'callback_data' => 'testcallback1'],
            ['text' => 'Prova2', 'callback_data' => 'testcallback2'],
        ]);

        $data = [
            'chat_id'      => $chat_id,
            'text'         => 'Benvenuti nel Bot di Farmaworld, attendiamo la tua scelta',
            'reply_markup' => $inline_keyboard,
        ];

        return Request::sendMessage($data);

and this i put in my CallbackqueryCommand.php

    public function execute()
    {
        $callback_query    = $this->getCallbackQuery();
        $callback_query_id = $callback_query->getId();
        $callback_data     =json_encode( $callback_query->getData());

        $data = [
            'callback_query_id' => $callback_query_id,
            'text'              => 'Hello Da Farmaworld',
            'show_alert'        => 'true',
        ];

        return Request::answerCallbackQuery($data);
    }

that work fine but 3 button make same response if i want make different response for each button i make code with: case1 case2 ecc but in the same file CallbackqueryCommand.php or in hook.php thanks very much

something like that:

    CallbackqueryCommand::addCallbackHandler(function (CallbackQuery $query) {
        $data = $query->getData();
        switch ($data){
            case "testcallback":
                $data = [
                    'chat_id' => $query->getMessage()->getChat()->getId(),
                    'text' => 'Prova'
                ];
                Request::sendMessage($data);
                break;
            case "testcallback1":
                $data = [
                    'chat_id' => $query->getMessage()->getChat()->getId(),
                    'text' => 'Prova1'
                ];
                Request::sendMessage($data);
                break;
            default:
                $data = [
                    'chat_id' => $query->getMessage()->getChat()->getId(),
                    'text' => 'Prova2'
                ];
                Request::sendMessage($data);
                break;
        }
    });

Thanks all, it’s realy worked!!! i just remove this:

$telegram->setCustomInput("");

in my hook.php and please, close this 😃 👍