Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buttons for a bot #52

Open
BeheniyKys opened this issue Mar 28, 2022 · 3 comments
Open

Buttons for a bot #52

BeheniyKys opened this issue Mar 28, 2022 · 3 comments

Comments

@BeheniyKys
Copy link

BeheniyKys commented Mar 28, 2022

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
Copy link

OxMohsen commented May 10, 2022

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
Copy link
Member

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

@m4n50n
Copy link

m4n50n commented Jan 23, 2024

@BeheniyKys Did you achieve what you ask?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants