Working on inline keyboard reply recognition
This commit is contained in:
parent
f014629d1a
commit
27143c691f
57
F1DataBot.pm
57
F1DataBot.pm
@ -84,8 +84,29 @@ sub build {
|
||||
use JSON;
|
||||
use LWP::Simple::REST qw(POST plain);
|
||||
|
||||
my $EncodedKeyboard = JSON::encode_json(
|
||||
my $KeyboardData;
|
||||
my $KeyboardMessage;
|
||||
if ( $Param{QueryStep} ) {
|
||||
if ( $Param{QueryStep} eq 'hist' ) {
|
||||
# show next selection
|
||||
}
|
||||
else {
|
||||
# for now, testing fallback
|
||||
my $ResponseResult = plain POST(
|
||||
join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, 'sendMessage' ) ),
|
||||
{
|
||||
'chat_id' => $Param{Message}->{callback_query}->{from}->{id},
|
||||
'reply_to_message_id' => $Param{Message}->{callback_query}->{message}->{message_id},
|
||||
'text' => "Kommando $Param{QueryStep} erkannt",
|
||||
}
|
||||
);
|
||||
$Self->{LogObject}->info( 'build: Sending result is ' . $ResponseResult );
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$KeyboardData = {
|
||||
'inline_keyboard' => [
|
||||
[
|
||||
{
|
||||
@ -101,15 +122,18 @@ sub build {
|
||||
'resize' => 1,
|
||||
'single_use' => 1,
|
||||
'placeholder' => 'test',
|
||||
},
|
||||
};
|
||||
$KeyboardMessage = "Hallo $Param{Message}->{chat}->{first_name}, über die folgenden Fragen kannst du auswählen, welche Interaktion du ausführen möchtest. Was möchtest du tun?";
|
||||
}
|
||||
my $EncodedKeyboard = JSON::encode_json(
|
||||
$KeyboardData,
|
||||
);
|
||||
my $ResponseResult = plain POST(
|
||||
join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, 'sendMessage' ) ),
|
||||
{
|
||||
'chat_id' => $Param{Message}->{chat}->{id},
|
||||
'reply_to_message_id' => $Param{Message}->{id},
|
||||
'text' =>
|
||||
"Hallo $Param{Message}, über die folgenden Fragen kannst du auswählen, welche Interaktion du ausführen möchtest. Was möchtest du tun?",
|
||||
'text' => $KeyboardMessage,
|
||||
'reply_markup' => $EncodedKeyboard,
|
||||
}
|
||||
);
|
||||
@ -282,15 +306,16 @@ sub processMessage {
|
||||
$Self->{LogObject}
|
||||
->info( 'processMessage: Message is ' . Dumper( $Param{Message} ) );
|
||||
|
||||
my $Message = $Param{Message}->{message};
|
||||
if ( $Message->{from}->{id} eq '587238001' ) {
|
||||
|
||||
if ( $Param{Message}->{message}->{from}->{id} eq '587238001' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
my $ResponseData = {};
|
||||
if ( $Message->{text} =~
|
||||
if ( defined $Param{Message}->{message} && $Param{Message}->{message}->{text} =~
|
||||
/\/(?<command>greet|statistics|build)\s?(?<arguments>.*)?/ )
|
||||
{
|
||||
my $Message = $Param{Message}->{message};
|
||||
my $Command = $+{command};
|
||||
my $ArgumentsString = $+{arguments};
|
||||
$ResponseData = $Self->$Command(
|
||||
@ -301,21 +326,27 @@ sub processMessage {
|
||||
return;
|
||||
}
|
||||
}
|
||||
elsif ( defined $Param{Message}->{callback_query} ) {
|
||||
$Self->build(
|
||||
Message => $Param{Message},
|
||||
QueryStep => $Param{Message}->{callback_query}->{data},
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->{LogObject}
|
||||
->debug( 'Command not recognized. Data: ' . $Message->{text} );
|
||||
->debug( 'Command not recognized. Data: ' . $Param{Message}->{message}->{text} );
|
||||
$ResponseData->{text} =
|
||||
"I'm sorry, "
|
||||
. ( $Message->{chat}->{first_name}
|
||||
? $Message->{chat}->{first_name}
|
||||
: $Message->{chat}->{username} )
|
||||
. ( $Param{Message}->{message}->{chat}->{first_name}
|
||||
? $Param{Message}->{message}->{chat}->{first_name}
|
||||
: $Param{Message}->{message}->{chat}->{username} )
|
||||
. ", I couldn't understand your request. Currently I can process the commands:\n\n\t\/greet\n\t\/statistics driver standings\n\t\/statistics constructor standings";
|
||||
}
|
||||
|
||||
my $ResponseResult = plain POST(
|
||||
join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, 'sendMessage' ) ),
|
||||
{
|
||||
chat_id => $Message->{chat}->{id},
|
||||
chat_id => $Param{Message}->{message}->{chat}->{id},
|
||||
$ResponseData->%*,
|
||||
}
|
||||
);
|
||||
@ -327,7 +358,7 @@ sub processMessage {
|
||||
my $SeenResult = plain POST(
|
||||
join( '/', ( $Self->{URL}{Telegram}, $Self->{Token}, 'readMessageContents' ) ),
|
||||
{
|
||||
id => $Message->{id},
|
||||
id => $Param{Message}->{message}->{id},
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user