mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 15:51:22 +00:00
feat(discord): Discord transport
This commit is contained in:
committed by
Peter Steinberger
parent
557f8e5a04
commit
ac659ff5a7
@@ -386,3 +386,87 @@ describe("trigger handling", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("group intro prompts", () => {
|
||||
it("labels Discord groups using the surface metadata", async () => {
|
||||
const commandSpy = vi
|
||||
.spyOn(commandReply, "runCommandReply")
|
||||
.mockResolvedValue({ payloads: [{ text: "ok" }], meta: { durationMs: 1 } });
|
||||
|
||||
await getReplyFromConfig(
|
||||
{
|
||||
Body: "status update",
|
||||
From: "group:dev",
|
||||
To: "+1888",
|
||||
ChatType: "group",
|
||||
GroupSubject: "Release Squad",
|
||||
GroupMembers: "Alice, Bob",
|
||||
Surface: "discord",
|
||||
},
|
||||
{},
|
||||
baseCfg,
|
||||
);
|
||||
|
||||
expect(commandSpy).toHaveBeenCalledOnce();
|
||||
const body =
|
||||
commandSpy.mock.calls.at(-1)?.[0]?.templatingCtx.Body ?? "";
|
||||
const intro = body.split("\n\n")[0];
|
||||
expect(intro).toBe(
|
||||
'You are replying inside the Discord group "Release Squad". Group members: Alice, Bob. Address the specific sender noted in the message context.',
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps WhatsApp labeling for WhatsApp group chats", async () => {
|
||||
const commandSpy = vi
|
||||
.spyOn(commandReply, "runCommandReply")
|
||||
.mockResolvedValue({ payloads: [{ text: "ok" }], meta: { durationMs: 1 } });
|
||||
|
||||
await getReplyFromConfig(
|
||||
{
|
||||
Body: "ping",
|
||||
From: "123@g.us",
|
||||
To: "+1999",
|
||||
ChatType: "group",
|
||||
GroupSubject: "Ops",
|
||||
Surface: "whatsapp",
|
||||
},
|
||||
{},
|
||||
baseCfg,
|
||||
);
|
||||
|
||||
expect(commandSpy).toHaveBeenCalledOnce();
|
||||
const body =
|
||||
commandSpy.mock.calls.at(-1)?.[0]?.templatingCtx.Body ?? "";
|
||||
const intro = body.split("\n\n")[0];
|
||||
expect(intro).toBe(
|
||||
'You are replying inside the WhatsApp group "Ops". Address the specific sender noted in the message context.',
|
||||
);
|
||||
});
|
||||
|
||||
it("labels Telegram groups using their own surface", async () => {
|
||||
const commandSpy = vi
|
||||
.spyOn(commandReply, "runCommandReply")
|
||||
.mockResolvedValue({ payloads: [{ text: "ok" }], meta: { durationMs: 1 } });
|
||||
|
||||
await getReplyFromConfig(
|
||||
{
|
||||
Body: "ping",
|
||||
From: "group:tg",
|
||||
To: "+1777",
|
||||
ChatType: "group",
|
||||
GroupSubject: "Dev Chat",
|
||||
Surface: "telegram",
|
||||
},
|
||||
{},
|
||||
baseCfg,
|
||||
);
|
||||
|
||||
expect(commandSpy).toHaveBeenCalledOnce();
|
||||
const body =
|
||||
commandSpy.mock.calls.at(-1)?.[0]?.templatingCtx.Body ?? "";
|
||||
const intro = body.split("\n\n")[0];
|
||||
expect(intro).toBe(
|
||||
'You are replying inside the Telegram group "Dev Chat". Address the specific sender noted in the message context.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -790,9 +790,18 @@ export async function getReplyFromConfig(
|
||||
defaultGroupActivation();
|
||||
const subject = sessionCtx.GroupSubject?.trim();
|
||||
const members = sessionCtx.GroupMembers?.trim();
|
||||
const surface = sessionCtx.Surface?.trim().toLowerCase();
|
||||
const surfaceLabel = (() => {
|
||||
if (!surface) return "chat";
|
||||
if (surface === "whatsapp") return "WhatsApp";
|
||||
if (surface === "telegram") return "Telegram";
|
||||
if (surface === "discord") return "Discord";
|
||||
if (surface === "webchat") return "WebChat";
|
||||
return `${surface.at(0)?.toUpperCase() ?? ""}${surface.slice(1)}`;
|
||||
})();
|
||||
const subjectLine = subject
|
||||
? `You are replying inside the WhatsApp group "${subject}".`
|
||||
: "You are replying inside a WhatsApp group chat.";
|
||||
? `You are replying inside the ${surfaceLabel} group "${subject}".`
|
||||
: `You are replying inside a ${surfaceLabel} group chat.`;
|
||||
const membersLine = members ? `Group members: ${members}.` : undefined;
|
||||
const activationLine =
|
||||
activation === "always"
|
||||
|
||||
Reference in New Issue
Block a user