Fixed a couple message routing errors
This commit is contained in:
parent
311b8dde4b
commit
f4c57e53db
@ -181,6 +181,13 @@ Send `/today` to your bot. You should receive a digest (or an "all clear" messag
|
|||||||
|
|
||||||
## AlmaLinux / RHEL-specific notes
|
## AlmaLinux / RHEL-specific notes
|
||||||
|
|
||||||
|
**IPv6 not routed (common on Linode/VPS)** — if the bot logs "Connect timeout" when trying to reach `api.telegram.org`, IPv6 is configured on the interface but not actually routed. Fix by telling the system resolver to prefer IPv4:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
echo 'precedence ::ffff:0:0/96 100' | sudo tee -a /etc/gai.conf
|
||||||
|
sudo systemctl restart mnemosyne-bot
|
||||||
|
```
|
||||||
|
|
||||||
**SELinux** — if nginx cannot connect to the local bot port, allow it:
|
**SELinux** — if nginx cannot connect to the local bot port, allow it:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@ -206,7 +206,11 @@ sub _post {
|
|||||||
my $tx = $self->{_ua}->post(
|
my $tx = $self->{_ua}->post(
|
||||||
$url => { 'Content-Type' => 'application/json' } => encode_json($body)
|
$url => { 'Content-Type' => 'application/json' } => encode_json($body)
|
||||||
);
|
);
|
||||||
my $res = $tx->result;
|
my $res = eval { $tx->result };
|
||||||
|
if ($@) {
|
||||||
|
warn "Telegram connection error ($method): $@\n";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
unless ($res->is_success) {
|
unless ($res->is_success) {
|
||||||
warn "Telegram API error ($method): " . $res->body . "\n";
|
warn "Telegram API error ($method): " . $res->body . "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,15 +45,22 @@ sub _handle_message {
|
|||||||
my ($msg, $chat_id, $db, $config, $telegram) = @_;
|
my ($msg, $chat_id, $db, $config, $telegram) = @_;
|
||||||
my $text = $msg->{text} // '';
|
my $text = $msg->{text} // '';
|
||||||
|
|
||||||
# Wizard in progress — text input feeds into the current step
|
|
||||||
if (exists $SESSIONS{$chat_id} && $SESSIONS{$chat_id}{step} ne 'done') {
|
|
||||||
_wizard_text($text, $chat_id, $msg, $db, $config, $telegram);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Strip bot username suffix from commands (e.g. /help@MnemosyneBot)
|
# Strip bot username suffix from commands (e.g. /help@MnemosyneBot)
|
||||||
$text =~ s{^(/\w+)@\w+}{$1};
|
$text =~ s{^(/\w+)@\w+}{$1};
|
||||||
|
|
||||||
|
# Wizard in progress — /cancel always escapes; other commands are blocked
|
||||||
|
if (exists $SESSIONS{$chat_id} && $SESSIONS{$chat_id}{step} ne 'done') {
|
||||||
|
if ($text =~ /^\/cancel/i) {
|
||||||
|
_cmd_cancel($chat_id, $telegram);
|
||||||
|
} elsif ($text =~ /^\//) {
|
||||||
|
$telegram->send_message($chat_id,
|
||||||
|
"A task wizard is in progress. Use /cancel to abort it first.");
|
||||||
|
} else {
|
||||||
|
_wizard_text($text, $chat_id, $msg, $db, $config, $telegram);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
my ($cmd, $args) = $text =~ /^(\/\w+)\s*(.*)/s ? ($1, $2) : ('', $text);
|
my ($cmd, $args) = $text =~ /^(\/\w+)\s*(.*)/s ? ($1, $2) : ('', $text);
|
||||||
|
|
||||||
if ($cmd eq '/today' || $cmd eq '/glance') { _cmd_today ($chat_id, $db, $config, $telegram) }
|
if ($cmd eq '/today' || $cmd eq '/glance') { _cmd_today ($chat_id, $db, $config, $telegram) }
|
||||||
@ -417,7 +424,10 @@ sub _wizard_text {
|
|||||||
_wizard_confirm($chat_id, $wmid, $sess, $telegram);
|
_wizard_confirm($chat_id, $wmid, $sess, $telegram);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$telegram->send_message($chat_id, "Unexpected input. /cancel to abort.");
|
# Button-only steps (await_class, await_weekday, etc.) land here if
|
||||||
|
# the user types instead of tapping. Prompt them back to the buttons.
|
||||||
|
$telegram->send_message($chat_id,
|
||||||
|
"Please use the buttons above to continue, or /cancel to abort.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user