Fixed a couple message routing errors

This commit is contained in:
rodger committed 2026-06-04 21:23:24 -04:00
1 parent 311b8dde4b
commit f4c57e53db
3 files changed
+29 -8

No files matched your search

+5 -1
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";
}
+17 -7
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.");
}
}