| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bot::ChatBots::Telegram::Role::Source; |
|
2
|
3
|
|
|
3
|
|
4690
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
72
|
|
|
3
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
|
3
|
|
|
|
|
14
|
|
|
|
3
|
|
|
|
|
102
|
|
|
4
|
|
|
|
|
|
|
{ our $VERSION = '0.012'; } |
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
13
|
use Ouch; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
15
|
|
|
7
|
3
|
|
|
3
|
|
156
|
use Log::Any; |
|
|
3
|
|
|
|
|
13
|
|
|
|
3
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
131
|
use Moo::Role; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has token => ( |
|
12
|
|
|
|
|
|
|
is => 'ro', |
|
13
|
|
|
|
|
|
|
lazy => 1, |
|
14
|
|
|
|
|
|
|
predicate => 1, |
|
15
|
|
|
|
|
|
|
default => sub { ouch 500, 'token is not defined' } |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has sender => ( |
|
19
|
|
|
|
|
|
|
is => 'ro', |
|
20
|
|
|
|
|
|
|
lazy => 1, |
|
21
|
|
|
|
|
|
|
default => sub { # prefer has-a in this case |
|
22
|
|
|
|
|
|
|
my $self = shift; |
|
23
|
|
|
|
|
|
|
require Bot::ChatBots::Telegram::Sender; |
|
24
|
|
|
|
|
|
|
return Bot::ChatBots::Telegram::Sender->new(token => $self->token); |
|
25
|
|
|
|
|
|
|
}, |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
{ |
|
29
|
|
|
|
|
|
|
my %data_type_for = ( |
|
30
|
|
|
|
|
|
|
message => 'Message', |
|
31
|
|
|
|
|
|
|
edited_message => 'Message', |
|
32
|
|
|
|
|
|
|
channel_post => 'Message', |
|
33
|
|
|
|
|
|
|
edited_channel_post => 'Message', |
|
34
|
|
|
|
|
|
|
inline_query => 'InlineQuery', |
|
35
|
|
|
|
|
|
|
chosen_inline_result => 'ChosenInlineResult', |
|
36
|
|
|
|
|
|
|
callback_query => 'CallbackQuery', |
|
37
|
|
|
|
|
|
|
shipping_query => 'ShippingQuery', |
|
38
|
|
|
|
|
|
|
pre_checkout_query => 'PreCheckoutQuery', |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub normalize_record { |
|
42
|
3
|
|
|
3
|
1
|
3736
|
my ($self, $record) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
3
|
100
|
|
|
|
15
|
my $update = $record->{update} or ouch 500, 'no update found!'; |
|
45
|
2
|
|
|
|
|
4
|
$record->{source}{technology} = 'telegram'; |
|
46
|
2
|
|
66
|
|
|
12
|
$record->{source}{token} //= $record->{source}{object_token}; |
|
47
|
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
7
|
my ($type) = grep { $_ ne 'update_id' } keys %$update; |
|
|
4
|
|
|
|
|
10
|
|
|
49
|
2
|
|
|
|
|
4
|
$record->{type} = $type; |
|
50
|
|
|
|
|
|
|
|
|
51
|
2
|
|
50
|
|
|
9
|
$record->{data_type} = $data_type_for{$type} || 'unknown'; |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
5
|
my $payload = $record->{payload} = $update->{$type}; |
|
54
|
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
5
|
$record->{sender} = $payload->{from}; |
|
56
|
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
7
|
return $self->_normalize_record_chan($record); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _normalize_record_chan { |
|
62
|
2
|
|
|
2
|
|
4
|
my ($self, $record) = @_; |
|
63
|
2
|
|
|
|
|
4
|
my ($dtype, $payload) = @{$record}{qw< data_type payload >}; |
|
|
2
|
|
|
|
|
14
|
|
|
64
|
2
|
|
|
|
|
5
|
my $chan; |
|
65
|
2
|
50
|
|
|
|
6
|
if ($dtype eq 'Message') { |
|
|
|
0
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
4
|
$chan = {%{$payload->{chat}}}; |
|
|
2
|
|
|
|
|
12
|
|
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
elsif ($dtype eq 'CallbackQuery') { |
|
69
|
0
|
0
|
|
|
|
0
|
if (exists $payload->{message}) { |
|
70
|
0
|
|
|
|
|
0
|
$chan = {%{$payload->{message}{chat}}}; |
|
|
0
|
|
|
|
|
0
|
|
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
else { # FIXME guessing correctly here? |
|
73
|
0
|
|
|
|
|
0
|
$chan = {id => $payload->{chat_instance}}; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
2
|
50
|
|
|
|
6
|
if ($chan) { |
|
77
|
2
|
50
|
|
|
|
11
|
$chan->{fqid} = "$chan->{type}/$chan->{id}" if exists $chan->{id}; |
|
78
|
2
|
|
|
|
|
6
|
$record->{channel} = $chan; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
9
|
return $record; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |