fix(telegram): unblock btw side questions

This commit is contained in:
Nimrod Gutman
2026-03-14 13:04:55 +02:00
parent 15feecfd97
commit e7500a0961
4 changed files with 54 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
import { normalizeCommandBody, type CommandNormalizeOptions } from "../commands-registry.js";
const BTW_COMMAND_RE = /^\/btw(?::|\s|$)/i;
export function isBtwRequestText(text?: string, options?: CommandNormalizeOptions): boolean {
if (!text) {
return false;
}
const normalized = normalizeCommandBody(text, options).trim();
return BTW_COMMAND_RE.test(normalized);
}
export function extractBtwQuestion(
text?: string,
options?: CommandNormalizeOptions,
): string | null {
if (!text) {
return null;
}
const normalized = normalizeCommandBody(text, options).trim();
const match = normalized.match(/^\/btw(?:\s+(.*))?$/i);
if (!match) {
return null;
}
return match[1]?.trim() ?? "";
}

View File

@@ -1,4 +1,5 @@
import { runBtwSideQuestion } from "../../agents/btw.js";
import { extractBtwQuestion } from "./btw-command.js";
import { rejectUnauthorizedCommand } from "./command-gates.js";
import type { CommandHandler } from "./commands-types.js";
@@ -8,8 +9,8 @@ export const handleBtwCommand: CommandHandler = async (params, allowTextCommands
if (!allowTextCommands) {
return null;
}
const match = params.command.commandBodyNormalized.match(/^\/btw(?:\s+(.*))?$/i);
if (!match) {
const question = extractBtwQuestion(params.command.commandBodyNormalized);
if (question === null) {
return null;
}
const unauthorized = rejectUnauthorizedCommand(params, "/btw");
@@ -17,7 +18,6 @@ export const handleBtwCommand: CommandHandler = async (params, allowTextCommands
return unauthorized;
}
const question = match[1]?.trim() ?? "";
if (!question) {
return {
shouldContinue: false,