mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 09:21:55 +00:00
fix(telegram): unblock btw side questions
This commit is contained in:
26
src/auto-reply/reply/btw-command.ts
Normal file
26
src/auto-reply/reply/btw-command.ts
Normal 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() ?? "";
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user