| 1 | package Telebot::Controller::Tg; | ||
| 2 | use Mojo::Base 'Mojolicious::Controller', -signatures; | ||
| 3 | |||
| 4 | sub update ($c) { | ||
| 5 | my $data = $c->req->json; | ||
| 6 | $c->dump($data) if $c->app->config->{trace}; | ||
| 7 | if ($data->{update_id}) { | ||
| 8 | $c->minion->enqueue(update => [$data]); | ||
| 9 | } | ||
| 10 | $c->render(json => {ok => \1}); | ||
| 11 | } | ||
| 12 | |||
| 13 | sub index ($c) { | ||
| 14 | $c->render; | ||
| 15 | } | ||
| 16 | |||
| 17 | 1; | ||
| 18 | |||
| 19 | =pod | ||
| 20 | |||
| 21 | =encoding utf8 | ||
| 22 | |||
| 23 | =head1 NAME | ||
| 24 | |||
| 25 | Telebot::Controller::Tg - Controller for telegram webhook processing. | ||
| 26 | |||
| 27 | =head1 SYNOPSIS | ||
| 28 | |||
| 29 | use Telebot::Controller::Tg; | ||
| 30 | my $app = Telebot::Controller::Tg->new; | ||
| 31 | |||
| 32 | =head1 DESCRIPTION | ||
| 33 | |||
| 34 | L<Telebot::Controller::Tg> is controller for processing incoming webhook requests. | ||
| 35 | |||
| 36 | =head1 ATTRIBUTES | ||
| 37 | |||
| 38 | L<Telebot::Controller::Tg> inherits all attributes from L<Mojolicious::Controller>. | ||
| 39 | |||
| 40 | =head1 METHODS | ||
| 41 | |||
| 42 | L<Telebot::Controller::Tg> inherits all methods from L<Mojolicious::Controller> and implements the following new ones. | ||
| 43 | |||
| 44 | =head2 index | ||
| 45 | |||
| 46 | $app->index; | ||
| 47 | |||
| 48 | Root page. | ||
| 49 | |||
| 50 | =head2 update | ||
| 51 | |||
| 52 | $app->update; | ||
| 53 | |||
| 54 | Process incoming webhook. | ||
| 55 | |||
| 56 | =head1 COPYRIGHT AND LICENSE | ||
| 57 | |||
| 58 | Copyright (C) 2022, Igor Lobanov. | ||
| 59 | This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version | ||
| 60 | 2.0. | ||
| 61 | |||
| 62 | =head1 SEE ALSO | ||
| 63 | |||
| 64 | L<https://github.com/igorlobanov/telebot>, L<Mojolicious::Guides>, L<https://mojolicious.org>, | ||
| 65 | L<https://core.telegram.org/bots/api>. | ||
| 66 | |||
| 67 | =cut |