php-telegram-bot / example-bot

[WIP] An A-Z example of a PHP Telegram Bot.
MIT License
371 stars 187 forks source link

Buttons for a bot #52

Open BeheniyKys opened 2 years ago

BeheniyKys commented 2 years ago

Good afternoon, I beg you to help me, is it possible to somehow attach the code to the button, I'm new to php and according to your guide I can't figure out how to make a button with this function. I would be very grateful for help

/**
 * User "/newfollowup" command
 */
class NewfollowupCommand extends UserCommand
{
    /**
     * @var string
     */
    protected $name = 'newfollowup';

    /**
     * @var string
     */
    protected $description = 'Add a new followup to a ticket on GLPI via TelegramBot.';

    /**
     * @var string
     */
    protected $usage = '/newfollowup <ticket_id>**<text>';

    /**
     * @var string
     */
    protected $version = '1.0.0';

    /**
     * Command execute method
     *
     * @return \Longman\TelegramBot\Entities\ServerResponse
     * @throws \Longman\TelegramBot\Exception\TelegramException
     */
    public function execute()
    {
        $message   = $this->getMessage();
        $chat_id   = $message->getChat()->getId();
        $user_chat = $message->getFrom()->getUsername();
        $text      = trim($message->getText(true));

        $response = \PluginTelegrambotTicket::newFollowup($chat_id, $user_chat, $text);

        if(!$response){
            $response = 'Command usage: ' . $this->getUsage();
        }

        $data = [
            'chat_id' => $chat_id,
            'text'    => $response,
        ];

        return Request::sendMessage($data);
    }
}
OxMohsen commented 2 years ago

i don't know what you wanna do but for accessing the ticket_id and text in command usage you can use explode function like this:

list($ticket_id,$new_text) = explode('**', $text, 2);

after this line of code you can access $ticket_id and $new_text that come from usage command.

noplanman commented 1 year ago

@BeheniyKys I trust you've been able to achieve what you wanted?

m4n50n commented 9 months ago

@BeheniyKys Did you achieve what you ask?