@elizaos/plugin-msteams 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +28 -0
- package/package.json +30 -0
- package/src/actions/sendMessage.ts +371 -0
- package/src/client.ts +500 -0
- package/src/config.ts +127 -0
- package/src/environment.ts +167 -0
- package/src/index.ts +104 -0
- package/src/providers/chatState.ts +198 -0
- package/src/service.ts +656 -0
- package/src/types.ts +262 -0
- package/tsconfig.json +19 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// MS Teams Plugin for ElizaOS
|
|
2
|
+
// Provides integration with Microsoft Teams via Bot Framework
|
|
3
|
+
// Export actions
|
|
4
|
+
export { SEND_ADAPTIVE_CARD_ACTION, SEND_MESSAGE_ACTION, SEND_POLL_ACTION, sendAdaptiveCardAction, sendMessageAction, sendPollAction, } from "./actions/sendMessage";
|
|
5
|
+
// Export client
|
|
6
|
+
export { MAX_MEDIA_BYTES, MAX_MESSAGE_LENGTH, MSTeamsClient } from "./client";
|
|
7
|
+
export { buildMSTeamsSettings, msTeamsEnvSchema, resolveMSTeamsCredentials, validateMSTeamsConfig, } from "./environment";
|
|
8
|
+
// Export providers
|
|
9
|
+
export { CHAT_STATE_PROVIDER, CONVERSATION_MEMBERS_PROVIDER, chatStateProvider, conversationMembersProvider, TEAM_INFO_PROVIDER, teamInfoProvider, } from "./providers/chatState";
|
|
10
|
+
// Export service
|
|
11
|
+
export { MSTEAMS_SERVICE_NAME, MSTeamsService } from "./service";
|
|
12
|
+
export { MSTeamsEventType } from "./types";
|
|
13
|
+
// Plugin metadata
|
|
14
|
+
export const PLUGIN_NAME = "msteams";
|
|
15
|
+
export const PLUGIN_VERSION = "2.0.0-alpha.1";
|
|
16
|
+
export const PLUGIN_DESCRIPTION = "Microsoft Teams integration for ElizaOS agents via Bot Framework";
|
|
17
|
+
import { sendAdaptiveCardAction, sendMessageAction, sendPollAction, } from "./actions/sendMessage";
|
|
18
|
+
import { chatStateProvider, conversationMembersProvider, teamInfoProvider, } from "./providers/chatState";
|
|
19
|
+
import { MSTeamsService } from "./service";
|
|
20
|
+
const msTeamsPlugin = {
|
|
21
|
+
name: PLUGIN_NAME,
|
|
22
|
+
description: PLUGIN_DESCRIPTION,
|
|
23
|
+
services: [MSTeamsService],
|
|
24
|
+
actions: [sendMessageAction, sendPollAction, sendAdaptiveCardAction],
|
|
25
|
+
providers: [chatStateProvider, conversationMembersProvider, teamInfoProvider],
|
|
26
|
+
};
|
|
27
|
+
export default msTeamsPlugin;
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elizaos/plugin-msteams",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"description": "Microsoft Teams integration for ElizaOS",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc -p tsconfig.json",
|
|
10
|
+
"dev": "tsc -w -p tsconfig.json"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"botbuilder": "^4.23.0",
|
|
14
|
+
"botframework-connector": "^4.23.0",
|
|
15
|
+
"@microsoft/microsoft-graph-client": "^3.0.7",
|
|
16
|
+
"zod": "^4.3.6"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@elizaos/core": "workspace:*"
|
|
20
|
+
},
|
|
21
|
+
"milaidy": {
|
|
22
|
+
"platforms": [
|
|
23
|
+
"node"
|
|
24
|
+
],
|
|
25
|
+
"runtime": "node",
|
|
26
|
+
"platformDetails": {
|
|
27
|
+
"node": "Node.js via main entry point"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Action,
|
|
3
|
+
ActionExample,
|
|
4
|
+
ActionResult,
|
|
5
|
+
HandlerCallback,
|
|
6
|
+
HandlerOptions,
|
|
7
|
+
IAgentRuntime,
|
|
8
|
+
Memory,
|
|
9
|
+
State,
|
|
10
|
+
} from "@elizaos/core";
|
|
11
|
+
import { MSTEAMS_SERVICE_NAME, type MSTeamsService } from "../service";
|
|
12
|
+
|
|
13
|
+
export const SEND_MESSAGE_ACTION = "SEND_MSTEAMS_MESSAGE";
|
|
14
|
+
|
|
15
|
+
export const sendMessageAction: Action = {
|
|
16
|
+
name: SEND_MESSAGE_ACTION,
|
|
17
|
+
similes: [
|
|
18
|
+
"MSTEAMS_SEND_MESSAGE",
|
|
19
|
+
"MSTEAMS_REPLY",
|
|
20
|
+
"MSTEAMS_MESSAGE",
|
|
21
|
+
"SEND_TEAMS_MESSAGE",
|
|
22
|
+
"REPLY_TEAMS",
|
|
23
|
+
"TEAMS_SEND",
|
|
24
|
+
"TEAMS_MESSAGE",
|
|
25
|
+
],
|
|
26
|
+
description: "Send a message to a Microsoft Teams conversation",
|
|
27
|
+
|
|
28
|
+
validate: async (
|
|
29
|
+
_runtime: IAgentRuntime,
|
|
30
|
+
message: Memory,
|
|
31
|
+
): Promise<boolean> => {
|
|
32
|
+
const source = message.content?.source;
|
|
33
|
+
return source === "msteams";
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
handler: async (
|
|
37
|
+
runtime: IAgentRuntime,
|
|
38
|
+
message: Memory,
|
|
39
|
+
state: State | undefined,
|
|
40
|
+
_options?: HandlerOptions,
|
|
41
|
+
callback?: HandlerCallback,
|
|
42
|
+
): Promise<ActionResult> => {
|
|
43
|
+
const msTeamsService = runtime.getService(
|
|
44
|
+
MSTEAMS_SERVICE_NAME,
|
|
45
|
+
) as unknown as MSTeamsService | undefined;
|
|
46
|
+
if (!msTeamsService) {
|
|
47
|
+
if (callback) {
|
|
48
|
+
await callback({
|
|
49
|
+
text: "MS Teams service not available",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { success: false, error: "MS Teams service not initialized" };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const client = msTeamsService.getClient();
|
|
56
|
+
if (!client) {
|
|
57
|
+
if (callback) {
|
|
58
|
+
await callback({
|
|
59
|
+
text: "MS Teams client not available",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return { success: false, error: "MS Teams client not initialized" };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const currentState = state ?? (await runtime.composeState(message));
|
|
66
|
+
const responseText = currentState.values?.response?.toString() || "";
|
|
67
|
+
const conversationId = message.content?.conversationId as
|
|
68
|
+
| string
|
|
69
|
+
| undefined;
|
|
70
|
+
|
|
71
|
+
if (!conversationId) {
|
|
72
|
+
if (callback) {
|
|
73
|
+
await callback({
|
|
74
|
+
text: "No conversation ID available",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return { success: false, error: "Missing conversation ID" };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const result = await client.sendProactiveMessage(
|
|
82
|
+
conversationId,
|
|
83
|
+
responseText,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (callback) {
|
|
87
|
+
await callback({
|
|
88
|
+
text: responseText,
|
|
89
|
+
action: SEND_MESSAGE_ACTION,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
data: {
|
|
96
|
+
action: SEND_MESSAGE_ACTION,
|
|
97
|
+
conversationId,
|
|
98
|
+
messageId: result.messageId,
|
|
99
|
+
text: responseText,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const errorMessage =
|
|
104
|
+
error instanceof Error ? error.message : String(error);
|
|
105
|
+
|
|
106
|
+
if (callback) {
|
|
107
|
+
await callback({
|
|
108
|
+
text: `Failed to send message: ${errorMessage}`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return { success: false, error: errorMessage };
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
examples: [
|
|
117
|
+
[
|
|
118
|
+
{
|
|
119
|
+
name: "{{name1}}",
|
|
120
|
+
content: {
|
|
121
|
+
text: "Send a message to this Teams conversation",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "{{agentName}}",
|
|
126
|
+
content: {
|
|
127
|
+
text: "I'll send a message to this Teams chat now.",
|
|
128
|
+
actions: [SEND_MESSAGE_ACTION],
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
] as ActionExample[][],
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const SEND_POLL_ACTION = "SEND_MSTEAMS_POLL";
|
|
136
|
+
|
|
137
|
+
export const sendPollAction: Action = {
|
|
138
|
+
name: SEND_POLL_ACTION,
|
|
139
|
+
similes: [
|
|
140
|
+
"MSTEAMS_SEND_POLL",
|
|
141
|
+
"MSTEAMS_CREATE_POLL",
|
|
142
|
+
"TEAMS_POLL",
|
|
143
|
+
"CREATE_POLL",
|
|
144
|
+
"SEND_POLL",
|
|
145
|
+
],
|
|
146
|
+
description: "Send a poll to a Microsoft Teams conversation",
|
|
147
|
+
|
|
148
|
+
validate: async (
|
|
149
|
+
_runtime: IAgentRuntime,
|
|
150
|
+
message: Memory,
|
|
151
|
+
): Promise<boolean> => {
|
|
152
|
+
const source = message.content?.source;
|
|
153
|
+
return source === "msteams";
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
handler: async (
|
|
157
|
+
runtime: IAgentRuntime,
|
|
158
|
+
message: Memory,
|
|
159
|
+
state: State | undefined,
|
|
160
|
+
_options?: HandlerOptions,
|
|
161
|
+
callback?: HandlerCallback,
|
|
162
|
+
): Promise<ActionResult> => {
|
|
163
|
+
const msTeamsService = runtime.getService(
|
|
164
|
+
MSTEAMS_SERVICE_NAME,
|
|
165
|
+
) as unknown as MSTeamsService | undefined;
|
|
166
|
+
if (!msTeamsService) {
|
|
167
|
+
if (callback) {
|
|
168
|
+
await callback({
|
|
169
|
+
text: "MS Teams service not available",
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return { success: false, error: "MS Teams service not initialized" };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const client = msTeamsService.getClient();
|
|
176
|
+
if (!client) {
|
|
177
|
+
if (callback) {
|
|
178
|
+
await callback({
|
|
179
|
+
text: "MS Teams client not available",
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return { success: false, error: "MS Teams client not initialized" };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const currentState = state ?? (await runtime.composeState(message));
|
|
186
|
+
const conversationId = message.content?.conversationId as
|
|
187
|
+
| string
|
|
188
|
+
| undefined;
|
|
189
|
+
const question = currentState.values?.pollQuestion?.toString() || "";
|
|
190
|
+
const optionsRaw = currentState.values?.pollOptions;
|
|
191
|
+
|
|
192
|
+
if (!conversationId) {
|
|
193
|
+
return { success: false, error: "Missing conversation ID" };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!question) {
|
|
197
|
+
return { success: false, error: "Missing poll question" };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Parse options
|
|
201
|
+
let options: string[] = [];
|
|
202
|
+
if (Array.isArray(optionsRaw)) {
|
|
203
|
+
options = optionsRaw.map((o) => String(o));
|
|
204
|
+
} else if (typeof optionsRaw === "string") {
|
|
205
|
+
options = optionsRaw.split(",").map((o) => o.trim());
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (options.length < 2) {
|
|
209
|
+
return { success: false, error: "Poll must have at least 2 options" };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
const result = await client.sendPoll(conversationId, question, options);
|
|
214
|
+
|
|
215
|
+
if (callback) {
|
|
216
|
+
await callback({
|
|
217
|
+
text: `Poll created: ${question}`,
|
|
218
|
+
action: SEND_POLL_ACTION,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
success: true,
|
|
224
|
+
data: {
|
|
225
|
+
action: SEND_POLL_ACTION,
|
|
226
|
+
conversationId,
|
|
227
|
+
pollId: result.pollId,
|
|
228
|
+
messageId: result.messageId,
|
|
229
|
+
question,
|
|
230
|
+
options,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
} catch (error) {
|
|
234
|
+
const errorMessage =
|
|
235
|
+
error instanceof Error ? error.message : String(error);
|
|
236
|
+
return { success: false, error: errorMessage };
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
examples: [
|
|
241
|
+
[
|
|
242
|
+
{
|
|
243
|
+
name: "{{name1}}",
|
|
244
|
+
content: {
|
|
245
|
+
text: "Create a poll asking what day works best for our meeting",
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "{{agentName}}",
|
|
250
|
+
content: {
|
|
251
|
+
text: "I'll create a poll for that.",
|
|
252
|
+
actions: [SEND_POLL_ACTION],
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
] as ActionExample[][],
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
export const SEND_ADAPTIVE_CARD_ACTION = "SEND_MSTEAMS_CARD";
|
|
260
|
+
|
|
261
|
+
export const sendAdaptiveCardAction: Action = {
|
|
262
|
+
name: SEND_ADAPTIVE_CARD_ACTION,
|
|
263
|
+
similes: [
|
|
264
|
+
"MSTEAMS_SEND_CARD",
|
|
265
|
+
"MSTEAMS_ADAPTIVE_CARD",
|
|
266
|
+
"TEAMS_CARD",
|
|
267
|
+
"SEND_CARD",
|
|
268
|
+
],
|
|
269
|
+
description: "Send an Adaptive Card to a Microsoft Teams conversation",
|
|
270
|
+
|
|
271
|
+
validate: async (
|
|
272
|
+
_runtime: IAgentRuntime,
|
|
273
|
+
message: Memory,
|
|
274
|
+
): Promise<boolean> => {
|
|
275
|
+
const source = message.content?.source;
|
|
276
|
+
return source === "msteams";
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
handler: async (
|
|
280
|
+
runtime: IAgentRuntime,
|
|
281
|
+
message: Memory,
|
|
282
|
+
state: State | undefined,
|
|
283
|
+
_options?: HandlerOptions,
|
|
284
|
+
callback?: HandlerCallback,
|
|
285
|
+
): Promise<ActionResult> => {
|
|
286
|
+
const msTeamsService = runtime.getService(
|
|
287
|
+
MSTEAMS_SERVICE_NAME,
|
|
288
|
+
) as unknown as MSTeamsService | undefined;
|
|
289
|
+
if (!msTeamsService) {
|
|
290
|
+
return { success: false, error: "MS Teams service not initialized" };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const client = msTeamsService.getClient();
|
|
294
|
+
if (!client) {
|
|
295
|
+
return { success: false, error: "MS Teams client not initialized" };
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const currentState = state ?? (await runtime.composeState(message));
|
|
299
|
+
const conversationId = message.content?.conversationId as
|
|
300
|
+
| string
|
|
301
|
+
| undefined;
|
|
302
|
+
const cardContent = currentState.values?.cardContent as
|
|
303
|
+
| Record<string, unknown>
|
|
304
|
+
| undefined;
|
|
305
|
+
|
|
306
|
+
if (!conversationId) {
|
|
307
|
+
return { success: false, error: "Missing conversation ID" };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (!cardContent) {
|
|
311
|
+
return { success: false, error: "Missing card content" };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
const cardBody = Array.isArray(cardContent.body) ? cardContent.body : [];
|
|
316
|
+
const cardActions = Array.isArray(cardContent.actions)
|
|
317
|
+
? cardContent.actions
|
|
318
|
+
: undefined;
|
|
319
|
+
const card = {
|
|
320
|
+
type: "AdaptiveCard" as const,
|
|
321
|
+
version: "1.5",
|
|
322
|
+
body: cardBody as unknown[],
|
|
323
|
+
actions: cardActions as unknown[] | undefined,
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const result = await client.sendAdaptiveCard(
|
|
327
|
+
conversationId,
|
|
328
|
+
card,
|
|
329
|
+
currentState.values?.fallbackText?.toString(),
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
if (callback) {
|
|
333
|
+
await callback({
|
|
334
|
+
text: "Adaptive Card sent",
|
|
335
|
+
action: SEND_ADAPTIVE_CARD_ACTION,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
success: true,
|
|
341
|
+
data: {
|
|
342
|
+
action: SEND_ADAPTIVE_CARD_ACTION,
|
|
343
|
+
conversationId,
|
|
344
|
+
messageId: result.messageId,
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
} catch (error) {
|
|
348
|
+
const errorMessage =
|
|
349
|
+
error instanceof Error ? error.message : String(error);
|
|
350
|
+
return { success: false, error: errorMessage };
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
examples: [
|
|
355
|
+
[
|
|
356
|
+
{
|
|
357
|
+
name: "{{name1}}",
|
|
358
|
+
content: {
|
|
359
|
+
text: "Send a card with meeting details",
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
name: "{{agentName}}",
|
|
364
|
+
content: {
|
|
365
|
+
text: "I'll send an Adaptive Card with the meeting information.",
|
|
366
|
+
actions: [SEND_ADAPTIVE_CARD_ACTION],
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
] as ActionExample[][],
|
|
371
|
+
};
|