<% CASE ['/start', 'Назад', 'Главное', 'меню']%>
{
"deleteMessage": { "message_id": {{ message.message_id }} }
},
{
"sendMessage": {
"text":"Главное меню",
"reply_markup": {
"keyboard": [
[
{"text": " Баланс"}
],
[
{"text": " Помощь"}
]
],
"one_time_keyboard": false,
"resize_keyboard": true
}
}
},
{
"deleteMessage": { "message_id": {{ message.message_id }} }
}
<% CASE ['/balance', '', 'Баланс'] %>
{
"deleteMessage": {
"message_id": {{ message.message_id }}
}
},
{
"sendMessage": {
"text": "Баланс: {{ user.balance }}",
"reply_markup": {
"keyboard": [
[
{
"text": "☰ История платежей"
}
],
[
{"text": "Назад"}
]
],
"one_time_keyboard": false,
"resize_keyboard": true
}
}
}
sub deleteMessage {
my $self = shift;
my %args = (
message_id => undef,
@_,
);
$self->http( 'deleteMessage',
data => \%args,
);
}
sub process_message {
my $self = shift;
my %args = (
message => undef,
@_,
);
return undef unless $self->token;
logger->debug('REQUEST:', \%args );
my $message = $args{callback_query} ? $args{callback_query}->{message} : $args{message};
$self->message( $message );
$self->chat_id( $message->{chat}->{id} );
my $query;
if ( $args{message} ) {
$query = $args{message}->{text};
} elsif ( $args{callback_query} ) {
$query = $args{callback_query}->{data};
}
my ( $cmd, @callback_args ) = split( /\s+/, $query );
if ( $cmd=~s/^\|// ) {
$cmd = join(' ', $cmd, @callback_args );
}
if ( $cmd ne '/register' ) {
my $user = $self->auth( $message );
if ( !$user ) {
logger->warning( 'USER_NOT_FOUND. Chat_id', $message->{chat}->{id}, 'username:', $message->{chat}->{username} );
$cmd = 'USER_NOT_FOUND';
} elsif ( $user->{block} ) {
return $self->sendMessage(
text => sprintf("You are blocked! (user_id: %s)", $user->{user_id} ),
);
}
}
my $obj = get_script( $cmd,
vars => {
cmd => $cmd,
message => $message,
args => \@callback_args,
},
);
if ( my @errors = get_service('report')->errors ) {
return $self->sendMessage(
text => join('<br>', @errors),
);
}
for my $script ( @{ $obj } ) {
logger->debug( 'Script:', $script );
my $method = get_script_method( $script );
my %allow_telegram_methods = (
sendPhoto => 1,
sendAudio => 1,
sendDocument => 1,
sendVideo => 1,
sendAnimation => 1,
sendVoice => 1,
sendVideoNote => 1,
sendMediaGroup => 1,
sendLocation => 1,
sendVenue => 1,
sendContact => 1,
sendPoll => 1,
sendDice => 1,
sendChatAction => 1,
deleteMessage => 1,
);
if ( $self->can( $method ) ) {
$self->$method( %{ $script->{ $method } || {} } );
} elsif ( $allow_telegram_methods{ $method } ) {
$self->http( $method,
data => $script->{ $method } || {},
);
} else {
logger->error("Method $method not exists");
next;
}
}
return 1;
}