-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebhook_09_keyboard.psgi
More file actions
59 lines (42 loc) · 1.04 KB
/
webhook_09_keyboard.psgi
File metadata and controls
59 lines (42 loc) · 1.04 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use 5.010;
use strict;
use Data::Dumper;
use JSON;
use Bot;
my $bot = Bot::bot();
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};
$text =~ s{[^0-9 .+/*)(-]}{}g;
my $result = eval $text;
my $keyboard = {
'keyboard' => [['123','12345'], ['678']]
};
$bot->sendMessage({
chat_id => $chat_id,
text => $result,
reply_markup => to_json($keyboard),
});
say "[$chat_id] $text";
}