Fixed a couple message routing errors

This commit is contained in:
Rodger Castle 2026-06-04 21:23:24 -04:00
parent 311b8dde4b
commit f4c57e53db
3 changed files with 29 additions and 8 deletions

View File

@ -181,6 +181,13 @@ Send `/today` to your bot. You should receive a digest (or an "all clear" messag
## 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:
```bash

View File

@ -206,7 +206,11 @@ sub _post {
my $tx = $self->{_ua}->post(
$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) {
warn "Telegram API error ($method): " . $res->body . "\n";
}

View File

@ -45,15 +45,22 @@ sub _handle_message {
my ($msg, $chat_id, $db, $config, $telegram) = @_;
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)
$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);
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);
} 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.");
}
}