mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 21:20:23 +00:00
fix(reply): make external btw replies explicit
This commit is contained in:
@@ -15,10 +15,12 @@ export function formatBtwTextForExternalDelivery(payload: ReplyPayload): string
|
|||||||
if (!text) {
|
if (!text) {
|
||||||
return payload.text;
|
return payload.text;
|
||||||
}
|
}
|
||||||
if (!payload.btw?.question?.trim()) {
|
const question = payload.btw?.question?.trim();
|
||||||
|
if (!question) {
|
||||||
return payload.text;
|
return payload.text;
|
||||||
}
|
}
|
||||||
return text.startsWith("BTW:") ? text : `BTW: ${text}`;
|
const formatted = `BTW\nQuestion: ${question}\n\n${text}`;
|
||||||
|
return text === formatted || text.startsWith("BTW\nQuestion:") ? text : formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveReplyThreadingForPayload(params: {
|
function resolveReplyThreadingForPayload(params: {
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ describe("routeReply", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prefixes BTW replies on routed sends", async () => {
|
it("formats BTW replies prominently on routed sends", async () => {
|
||||||
mocks.sendMessageSlack.mockClear();
|
mocks.sendMessageSlack.mockClear();
|
||||||
await routeReply({
|
await routeReply({
|
||||||
payload: { text: "323", btw: { question: "what is 17 * 19?" } },
|
payload: { text: "323", btw: { question: "what is 17 * 19?" } },
|
||||||
@@ -312,12 +312,12 @@ describe("routeReply", () => {
|
|||||||
});
|
});
|
||||||
expect(mocks.sendMessageSlack).toHaveBeenCalledWith(
|
expect(mocks.sendMessageSlack).toHaveBeenCalledWith(
|
||||||
"channel:C123",
|
"channel:C123",
|
||||||
"BTW: 323",
|
"BTW\nQuestion: what is 17 * 19?\n\n323",
|
||||||
expect.any(Object),
|
expect.any(Object),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prefixes BTW replies on routed discord sends", async () => {
|
it("formats BTW replies prominently on routed discord sends", async () => {
|
||||||
mocks.sendMessageDiscord.mockClear();
|
mocks.sendMessageDiscord.mockClear();
|
||||||
await routeReply({
|
await routeReply({
|
||||||
payload: { text: "323", btw: { question: "what is 17 * 19?" } },
|
payload: { text: "323", btw: { question: "what is 17 * 19?" } },
|
||||||
@@ -327,7 +327,7 @@ describe("routeReply", () => {
|
|||||||
});
|
});
|
||||||
expect(mocks.sendMessageDiscord).toHaveBeenCalledWith(
|
expect(mocks.sendMessageDiscord).toHaveBeenCalledWith(
|
||||||
"channel:123456",
|
"channel:123456",
|
||||||
"BTW: 323",
|
"BTW\nQuestion: what is 17 * 19?\n\n323",
|
||||||
expect.any(Object),
|
expect.any(Object),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ describe("deliverOutboundPayloads", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prefixes BTW replies for telegram delivery", async () => {
|
it("formats BTW replies prominently for telegram delivery", async () => {
|
||||||
const sendTelegram = vi.fn().mockResolvedValue({ messageId: "m1", chatId: "c1" });
|
const sendTelegram = vi.fn().mockResolvedValue({ messageId: "m1", chatId: "c1" });
|
||||||
|
|
||||||
await deliverTelegramPayload({
|
await deliverTelegramPayload({
|
||||||
@@ -301,7 +301,7 @@ describe("deliverOutboundPayloads", () => {
|
|||||||
|
|
||||||
expect(sendTelegram).toHaveBeenCalledWith(
|
expect(sendTelegram).toHaveBeenCalledWith(
|
||||||
"123",
|
"123",
|
||||||
"BTW: 323",
|
"BTW\nQuestion: what is 17 * 19?\n\n323",
|
||||||
expect.objectContaining({ verbose: false, textMode: "html" }),
|
expect.objectContaining({ verbose: false, textMode: "html" }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -743,7 +743,7 @@ describe("deliverOutboundPayloads", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prefixes BTW replies for whatsapp delivery", async () => {
|
it("formats BTW replies prominently for whatsapp delivery", async () => {
|
||||||
const sendWhatsApp = vi.fn().mockResolvedValue({ messageId: "w1", toJid: "jid" });
|
const sendWhatsApp = vi.fn().mockResolvedValue({ messageId: "w1", toJid: "jid" });
|
||||||
|
|
||||||
await deliverWhatsAppPayload({
|
await deliverWhatsAppPayload({
|
||||||
@@ -751,7 +751,11 @@ describe("deliverOutboundPayloads", () => {
|
|||||||
payload: { text: "323", btw: { question: "what is 17 * 19?" } },
|
payload: { text: "323", btw: { question: "what is 17 * 19?" } },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(sendWhatsApp).toHaveBeenCalledWith("+1555", "BTW: 323", expect.any(Object));
|
expect(sendWhatsApp).toHaveBeenCalledWith(
|
||||||
|
"+1555",
|
||||||
|
"BTW\nQuestion: what is 17 * 19?\n\n323",
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("continues on errors when bestEffort is enabled", async () => {
|
it("continues on errors when bestEffort is enabled", async () => {
|
||||||
|
|||||||
@@ -1258,14 +1258,14 @@ describe("normalizeOutboundPayloads", () => {
|
|||||||
expect(normalized).toEqual([{ text: "final answer", mediaUrls: [] }]);
|
expect(normalized).toEqual([{ text: "final answer", mediaUrls: [] }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prefixes BTW replies for external delivery", () => {
|
it("formats BTW replies prominently for external delivery", () => {
|
||||||
const normalized = normalizeOutboundPayloads([
|
const normalized = normalizeOutboundPayloads([
|
||||||
{
|
{
|
||||||
text: "323",
|
text: "323",
|
||||||
btw: { question: "what is 17 * 19?" },
|
btw: { question: "what is 17 * 19?" },
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
expect(normalized).toEqual([{ text: "BTW: 323", mediaUrls: [] }]);
|
expect(normalized).toEqual([{ text: "BTW\nQuestion: what is 17 * 19?\n\n323", mediaUrls: [] }]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user