mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 01:11:37 +00:00
fix(telegram): unblock btw side questions
This commit is contained in:
@@ -60,6 +60,20 @@ describe("getTelegramSequentialKey", () => {
|
||||
"telegram:123:control",
|
||||
],
|
||||
[{ message: mockMessage({ chat: mockChat({ id: 123 }), text: "/status" }) }, "telegram:123"],
|
||||
[
|
||||
{ message: mockMessage({ chat: mockChat({ id: 123 }), text: "/btw what is the time?" }) },
|
||||
"telegram:123:btw:1",
|
||||
],
|
||||
[
|
||||
{
|
||||
me: { username: "openclaw_bot" } as never,
|
||||
message: mockMessage({
|
||||
chat: mockChat({ id: 123 }),
|
||||
text: "/btw@openclaw_bot what is the time?",
|
||||
}),
|
||||
},
|
||||
"telegram:123:btw:1",
|
||||
],
|
||||
[
|
||||
{ message: mockMessage({ chat: mockChat({ id: 123 }), text: "stop" }) },
|
||||
"telegram:123:control",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type Message, type UserFromGetMe } from "@grammyjs/types";
|
||||
import { isAbortRequestText } from "../../../src/auto-reply/reply/abort.js";
|
||||
import { isBtwRequestText } from "../../../src/auto-reply/reply/btw-command.js";
|
||||
import { resolveTelegramForumThreadId } from "./bot/helpers.js";
|
||||
|
||||
export type TelegramSequentialKeyContext = {
|
||||
@@ -41,6 +42,16 @@ export function getTelegramSequentialKey(ctx: TelegramSequentialKeyContext): str
|
||||
}
|
||||
return "telegram:control";
|
||||
}
|
||||
if (isBtwRequestText(rawText, botUsername ? { botUsername } : undefined)) {
|
||||
const messageId = msg?.message_id;
|
||||
if (typeof chatId === "number" && typeof messageId === "number") {
|
||||
return `telegram:${chatId}:btw:${messageId}`;
|
||||
}
|
||||
if (typeof chatId === "number") {
|
||||
return `telegram:${chatId}:btw`;
|
||||
}
|
||||
return "telegram:btw";
|
||||
}
|
||||
const isGroup = msg?.chat?.type === "group" || msg?.chat?.type === "supergroup";
|
||||
const messageThreadId = msg?.message_thread_id;
|
||||
const isForum = msg?.chat?.is_forum;
|
||||
|
||||
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