@matimo/microsoft 0.1.0
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/README.md +104 -0
- package/definition.yaml +61 -0
- package/package.json +18 -0
- package/tools/graph-client.ts +233 -0
- package/tools/ms_create_calendar_event/definition.yaml +100 -0
- package/tools/ms_create_calendar_event/ms_create_calendar_event.ts +79 -0
- package/tools/ms_create_document/definition.yaml +103 -0
- package/tools/ms_create_document/ms_create_document.ts +96 -0
- package/tools/ms_get_email/definition.yaml +88 -0
- package/tools/ms_get_email/ms_get_email.ts +94 -0
- package/tools/ms_list_files/definition.yaml +81 -0
- package/tools/ms_list_files/ms_list_files.ts +71 -0
- package/tools/ms_publish_to_sharepoint/definition.yaml +92 -0
- package/tools/ms_publish_to_sharepoint/ms_publish_to_sharepoint.ts +126 -0
- package/tools/ms_read_file/definition.yaml +74 -0
- package/tools/ms_read_file/ms_read_file.ts +102 -0
- package/tools/ms_search_knowledge/definition.yaml +99 -0
- package/tools/ms_search_knowledge/ms_search_knowledge.ts +109 -0
- package/tools/ms_send_email/definition.yaml +94 -0
- package/tools/ms_send_email/ms_send_email.ts +98 -0
- package/tools/ms_send_teams_message/definition.yaml +87 -0
- package/tools/ms_send_teams_message/ms_send_teams_message.ts +69 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ms_send_teams_message
|
|
3
|
+
* New message: POST /teams/{team-id}/channels/{channel-id}/messages
|
|
4
|
+
* https://learn.microsoft.com/en-us/graph/api/channel-post-messages
|
|
5
|
+
* Reply: POST /teams/{team-id}/channels/{channel-id}/messages/{message-id}/replies
|
|
6
|
+
* https://learn.microsoft.com/en-us/graph/api/chatmessage-post-replies
|
|
7
|
+
*/
|
|
8
|
+
import { MatimoError, ErrorCode } from '@matimo/core';
|
|
9
|
+
import { getAccessToken, requireParams, graphRequest, type ToolContext } from '../graph-client';
|
|
10
|
+
|
|
11
|
+
const VALID_CONTENT_TYPES = ['text', 'html'];
|
|
12
|
+
|
|
13
|
+
interface ChannelMessage {
|
|
14
|
+
id?: string;
|
|
15
|
+
webUrl?: string;
|
|
16
|
+
createdDateTime?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default async function execute(
|
|
20
|
+
params: Record<string, unknown>,
|
|
21
|
+
context?: ToolContext
|
|
22
|
+
): Promise<unknown> {
|
|
23
|
+
requireParams(params, ['team_id', 'channel_id', 'text'], 'ms_send_teams_message');
|
|
24
|
+
|
|
25
|
+
const teamId = String(params.team_id);
|
|
26
|
+
const channelId = String(params.channel_id);
|
|
27
|
+
const text = String(params.text);
|
|
28
|
+
|
|
29
|
+
const contentType = params.content_type === undefined ? 'text' : String(params.content_type);
|
|
30
|
+
if (!VALID_CONTENT_TYPES.includes(contentType)) {
|
|
31
|
+
throw new MatimoError(
|
|
32
|
+
`ms_send_teams_message: 'content_type' must be one of ${VALID_CONTENT_TYPES.join(', ')} (received '${contentType}')`,
|
|
33
|
+
ErrorCode.VALIDATION_FAILED,
|
|
34
|
+
{ content_type: params.content_type }
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const replyToMessageId =
|
|
39
|
+
typeof params.reply_to_message_id === 'string' && params.reply_to_message_id
|
|
40
|
+
? params.reply_to_message_id
|
|
41
|
+
: undefined;
|
|
42
|
+
|
|
43
|
+
const token = getAccessToken(context);
|
|
44
|
+
|
|
45
|
+
const basePath = `/teams/${encodeURIComponent(teamId)}/channels/${encodeURIComponent(channelId)}/messages`;
|
|
46
|
+
const path = replyToMessageId
|
|
47
|
+
? `${basePath}/${encodeURIComponent(replyToMessageId)}/replies`
|
|
48
|
+
: basePath;
|
|
49
|
+
|
|
50
|
+
const message = await graphRequest<ChannelMessage>({
|
|
51
|
+
method: 'POST',
|
|
52
|
+
path,
|
|
53
|
+
token,
|
|
54
|
+
resourceType: 'Teams channel',
|
|
55
|
+
body: {
|
|
56
|
+
body: {
|
|
57
|
+
contentType,
|
|
58
|
+
content: text,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
message_id: message?.id ?? '',
|
|
66
|
+
web_url: message?.webUrl ?? '',
|
|
67
|
+
created_at: message?.createdDateTime ?? '',
|
|
68
|
+
};
|
|
69
|
+
}
|