| 1 | package Telegram::BotKit::UpdateParser; | ||
| 2 | $Telegram::BotKit::UpdateParser::VERSION = '0.03'; | ||
| 3 | # ABSTRACT: Module for parsing Telegram Update object. Resolve issue of getting text from inline or regular keyboard | ||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | use common::sense; | ||
| 8 | |||
| 9 | use Exporter qw(import); | ||
| 10 | our @EXPORT_OK = qw(get_chat_id get_text); | ||
| 11 | |||
| 12 | |||
| 13 | sub _parse { | ||
| 14 | my $update = shift; | ||
| 15 | if ($update->{message}{text}) { | ||
| 16 | return { data => $update->{message}{text}, chat_id => $update->{message}{chat}{id} }; | ||
| 17 | } | ||
| 18 | if ($update->{callback_query}{data}) { | ||
| 19 | return { data => $update->{callback_query}{data}, chat_id => $update->{callback_query}{message}{chat}{id} }; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | sub get_text { | ||
| 25 | my $update = shift; | ||
| 26 | _parse($update)->{data}; | ||
| 27 | } | ||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | sub get_chat_id { | ||
| 32 | my $update = shift; | ||
| 33 | _parse($update)->{chat_id}; | ||
| 34 | } | ||
| 35 | |||
| 36 | 1; | ||
| 37 | |||
| 38 | __END__ |