forked from ash/telegram-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook_02_data.psgi
More file actions
43 lines (30 loc) · 758 Bytes
/
webhook_02_data.psgi
File metadata and controls
43 lines (30 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use 5.010;
use strict;
use Data::Dumper;
use JSON;
return main_app();
sub main_app {
my $app = sub {
my $env = shift;
my $status = 200;
my $headers = [
'Content-Type' => 'text/plain',
];
my $body = '';
my $path = $env->{PATH_INFO};
my $input = $env->{'psgi.input'};
my $json = join '', <$input>;
my $data = from_json($json);
say Dumper($data);
process_message($data) if $data->{message};
return [$status, $headers, [$body]];
};
return $app;
}
sub process_message {
my ($data) = @_;
my $message = $data->{message};
my $text = $message->{text};
my $chat_id = $message->{chat}{id};
say "[$chat_id] $text";
}