The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Telebot::Handler - Base class for telegram updates handlers

SYNOPSIS

    use Telebot::Handler;
    my $handler = Telebot::Handler->new(
        app => $app,
        payload => {},
        update_id => 1,
    );
    $handler->run();

DESCRIPTION

Telebot::Handler is the base class for Telebot handlers. After recieving update from telegram app process it with handlers. Telebot uses handler for update itself and handlers for each part of update (Message, Poll, etc). First of all Telebot after recieving update calls handler for Update. And then depending on update content one of handlers for update parts (Message, Poll, etc). Telebot defines default handlers for all types. You can define your own handlers in Handler/ subdirectory. Handler must have the camelized name of corresponding update part.

Handler/Update.pm - for handling update itself

Handler/Message.pm - for handling message part of update

Handler/CallbackQuery.pm - for handling callback_query part of update

ATTRIBUTES

Telebot::Handler implements the following attributes.

app

    my $app = $handler->app;

Reference to main Telebot application. Use it to call plugins and so on.

payload

    my $payload = $handler->payload;

Payload of telegram update (or part of update). Contain perl structure with data recieved from webhook.

update_id

    my $update_id = $handler->update_id;

Each telegram update have update_id. This attribute contain update_id of processed telegram update.

METHODS

Telebot::Handler inherits all methods from Mojo::Base and implements the following new ones.

run

    $handler->run;

This method is overloaded in inheritted classes and called for processing telegram update (or part of it). Not overloaded it dumps payload.

COPYRIGHT AND LICENSE

Copyright (C) 2022, Igor Lobanov. This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

https://github.com/igorlobanov/telebot, Mojolicious::Guides, https://mojolicious.org, https://core.telegram.org/api.