feat!: move msteams to plugin
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { ChannelOutboundAdapter, ChannelPlugin } from "../../channels/plugins/types.js";
|
||||
import type { PluginRegistry } from "../../plugins/registry.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { sendMessage, sendPoll } from "./message.js";
|
||||
|
||||
const callGatewayMock = vi.fn();
|
||||
@@ -11,6 +14,11 @@ vi.mock("../../gateway/call.js", () => ({
|
||||
describe("sendMessage channel normalization", () => {
|
||||
beforeEach(() => {
|
||||
callGatewayMock.mockReset();
|
||||
setActivePluginRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setActivePluginRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
it("normalizes Teams alias", async () => {
|
||||
@@ -18,6 +26,18 @@ describe("sendMessage channel normalization", () => {
|
||||
messageId: "m1",
|
||||
conversationId: "c1",
|
||||
}));
|
||||
setActivePluginRegistry(
|
||||
createRegistry([
|
||||
{
|
||||
pluginId: "msteams",
|
||||
source: "test",
|
||||
plugin: createMSTeamsPlugin({
|
||||
outbound: createMSTeamsOutbound(),
|
||||
aliases: ["teams"],
|
||||
}),
|
||||
},
|
||||
]),
|
||||
);
|
||||
const result = await sendMessage({
|
||||
cfg: {},
|
||||
to: "conversation:19:abc@thread.tacv2",
|
||||
@@ -48,10 +68,27 @@ describe("sendMessage channel normalization", () => {
|
||||
describe("sendPoll channel normalization", () => {
|
||||
beforeEach(() => {
|
||||
callGatewayMock.mockReset();
|
||||
setActivePluginRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setActivePluginRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
it("normalizes Teams alias for polls", async () => {
|
||||
callGatewayMock.mockResolvedValueOnce({ messageId: "p1" });
|
||||
setActivePluginRegistry(
|
||||
createRegistry([
|
||||
{
|
||||
pluginId: "msteams",
|
||||
source: "test",
|
||||
plugin: createMSTeamsPlugin({
|
||||
aliases: ["teams"],
|
||||
outbound: createMSTeamsOutbound({ includePoll: true }),
|
||||
}),
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
const result = await sendPoll({
|
||||
cfg: {},
|
||||
@@ -68,3 +105,64 @@ describe("sendPoll channel normalization", () => {
|
||||
expect(result.channel).toBe("msteams");
|
||||
});
|
||||
});
|
||||
|
||||
const createRegistry = (channels: PluginRegistry["channels"]): PluginRegistry => ({
|
||||
plugins: [],
|
||||
tools: [],
|
||||
channels,
|
||||
providers: [],
|
||||
gatewayHandlers: {},
|
||||
httpHandlers: [],
|
||||
cliRegistrars: [],
|
||||
services: [],
|
||||
diagnostics: [],
|
||||
});
|
||||
|
||||
const emptyRegistry = createRegistry([]);
|
||||
|
||||
const createMSTeamsOutbound = (opts?: { includePoll?: boolean }): ChannelOutboundAdapter => ({
|
||||
deliveryMode: "direct",
|
||||
sendText: async ({ deps, to, text }) => {
|
||||
const send = deps?.sendMSTeams;
|
||||
if (!send) {
|
||||
throw new Error("sendMSTeams missing");
|
||||
}
|
||||
const result = await send(to, text);
|
||||
return { channel: "msteams", ...result };
|
||||
},
|
||||
sendMedia: async ({ deps, to, text, mediaUrl }) => {
|
||||
const send = deps?.sendMSTeams;
|
||||
if (!send) {
|
||||
throw new Error("sendMSTeams missing");
|
||||
}
|
||||
const result = await send(to, text, { mediaUrl });
|
||||
return { channel: "msteams", ...result };
|
||||
},
|
||||
...(opts?.includePoll
|
||||
? {
|
||||
pollMaxOptions: 12,
|
||||
sendPoll: async () => ({ channel: "msteams", messageId: "p1" }),
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
|
||||
const createMSTeamsPlugin = (params: {
|
||||
aliases?: string[];
|
||||
outbound: ChannelOutboundAdapter;
|
||||
}): ChannelPlugin => ({
|
||||
id: "msteams",
|
||||
meta: {
|
||||
id: "msteams",
|
||||
label: "Microsoft Teams",
|
||||
selectionLabel: "Microsoft Teams (Bot Framework)",
|
||||
docsPath: "/channels/msteams",
|
||||
blurb: "Bot Framework; enterprise support.",
|
||||
aliases: params.aliases,
|
||||
},
|
||||
capabilities: { chatTypes: ["direct"] },
|
||||
config: {
|
||||
listAccountIds: () => [],
|
||||
resolveAccount: () => ({}),
|
||||
},
|
||||
outbound: params.outbound,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user