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