example-bot icon indicating copy to clipboard operation
example-bot copied to clipboard

Buttons for a bot

Open BeheniyKys opened this issue 3 years ago • 3 comments

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);
    }
}

BeheniyKys avatar Mar 28 '22 14:03 BeheniyKys

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.

OxMohsen avatar May 10 '22 16:05 OxMohsen

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

noplanman avatar Sep 03 '23 12:09 noplanman

@BeheniyKys Did you achieve what you ask?

m4n50n avatar Jan 23 '24 11:01 m4n50n