@scopieflows/app-microsoft-teams 0.3.3
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 +7 -0
- package/package.json +31 -0
- package/src/i18n/ca.json +35 -0
- package/src/i18n/de.json +84 -0
- package/src/i18n/es.json +84 -0
- package/src/i18n/fr.json +84 -0
- package/src/i18n/hi.json +35 -0
- package/src/i18n/id.json +35 -0
- package/src/i18n/ja.json +84 -0
- package/src/i18n/nl.json +84 -0
- package/src/i18n/pt.json +84 -0
- package/src/i18n/ru.json +35 -0
- package/src/i18n/translation.json +84 -0
- package/src/i18n/vi.json +35 -0
- package/src/i18n/zh.json +84 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +130 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/create-channel.d.ts +5 -0
- package/src/lib/actions/create-channel.js +41 -0
- package/src/lib/actions/create-channel.js.map +1 -0
- package/src/lib/actions/create-chat-and-send-message.d.ts +6 -0
- package/src/lib/actions/create-chat-and-send-message.js +84 -0
- package/src/lib/actions/create-chat-and-send-message.js.map +1 -0
- package/src/lib/actions/create-private-channel.d.ts +5 -0
- package/src/lib/actions/create-private-channel.js +39 -0
- package/src/lib/actions/create-private-channel.js.map +1 -0
- package/src/lib/actions/delete-chat-message.d.ts +4 -0
- package/src/lib/actions/delete-chat-message.js +36 -0
- package/src/lib/actions/delete-chat-message.js.map +1 -0
- package/src/lib/actions/find-channel.d.ts +4 -0
- package/src/lib/actions/find-channel.js +40 -0
- package/src/lib/actions/find-channel.js.map +1 -0
- package/src/lib/actions/find-team-member.d.ts +5 -0
- package/src/lib/actions/find-team-member.js +54 -0
- package/src/lib/actions/find-team-member.js.map +1 -0
- package/src/lib/actions/get-channel-message.d.ts +6 -0
- package/src/lib/actions/get-channel-message.js +39 -0
- package/src/lib/actions/get-channel-message.js.map +1 -0
- package/src/lib/actions/get-chat-message.d.ts +4 -0
- package/src/lib/actions/get-chat-message.js +31 -0
- package/src/lib/actions/get-chat-message.js.map +1 -0
- package/src/lib/actions/reply-to-channel-message.d.ts +7 -0
- package/src/lib/actions/reply-to-channel-message.js +56 -0
- package/src/lib/actions/reply-to-channel-message.js.map +1 -0
- package/src/lib/actions/request-approval-channel-message.d.ts +5 -0
- package/src/lib/actions/request-approval-channel-message.js +104 -0
- package/src/lib/actions/request-approval-channel-message.js.map +1 -0
- package/src/lib/actions/request-approval-direct-message.d.ts +4 -0
- package/src/lib/actions/request-approval-direct-message.js +102 -0
- package/src/lib/actions/request-approval-direct-message.js.map +1 -0
- package/src/lib/actions/send-channel-message.d.ts +6 -0
- package/src/lib/actions/send-channel-message.js +59 -0
- package/src/lib/actions/send-channel-message.js.map +1 -0
- package/src/lib/actions/send-chat-message.d.ts +5 -0
- package/src/lib/actions/send-chat-message.js +57 -0
- package/src/lib/actions/send-chat-message.js.map +1 -0
- package/src/lib/common/graph.d.ts +10 -0
- package/src/lib/common/graph.js +90 -0
- package/src/lib/common/graph.js.map +1 -0
- package/src/lib/common/index.d.ts +7 -0
- package/src/lib/common/index.js +217 -0
- package/src/lib/common/index.js.map +1 -0
- package/src/lib/triggers/new-channel-message.d.ts +14 -0
- package/src/lib/triggers/new-channel-message.js +137 -0
- package/src/lib/triggers/new-channel-message.js.map +1 -0
- package/src/lib/triggers/new-channel.d.ts +10 -0
- package/src/lib/triggers/new-channel.js +95 -0
- package/src/lib/triggers/new-channel.js.map +1 -0
- package/src/lib/triggers/new-chat-message.d.ts +10 -0
- package/src/lib/triggers/new-chat-message.js +132 -0
- package/src/lib/triggers/new-chat-message.js.map +1 -0
- package/src/lib/triggers/new-chat.d.ts +2 -0
- package/src/lib/triggers/new-chat.js +95 -0
- package/src/lib/triggers/new-chat.js.map +1 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const sendChannelMessageAction: import("@scopieflows/pieces-framework").IAction<import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>, {
|
|
2
|
+
teamId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
3
|
+
channelId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
4
|
+
contentType: import("@scopieflows/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
content: import("@scopieflows/pieces-framework").LongTextProperty<true>;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendChannelMessageAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const __1 = require("../../");
|
|
6
|
+
const pieces_framework_1 = require("@scopieflows/pieces-framework");
|
|
7
|
+
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
exports.sendChannelMessageAction = (0, pieces_framework_1.createAction)({
|
|
10
|
+
auth: __1.microsoftTeamsAuth,
|
|
11
|
+
name: 'microsoft_teams_send_channel_message',
|
|
12
|
+
displayName: 'Send Channel Message',
|
|
13
|
+
description: "Sends a message to a teams's channel.",
|
|
14
|
+
props: {
|
|
15
|
+
teamId: common_1.microsoftTeamsCommon.teamId,
|
|
16
|
+
channelId: common_1.microsoftTeamsCommon.channelId,
|
|
17
|
+
contentType: pieces_framework_1.Property.StaticDropdown({
|
|
18
|
+
displayName: 'Content Type',
|
|
19
|
+
required: true,
|
|
20
|
+
defaultValue: 'text',
|
|
21
|
+
options: {
|
|
22
|
+
disabled: false,
|
|
23
|
+
options: [
|
|
24
|
+
{
|
|
25
|
+
label: 'Text',
|
|
26
|
+
value: 'text',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: 'HTML',
|
|
30
|
+
value: 'html',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
content: pieces_framework_1.Property.LongText({
|
|
36
|
+
displayName: 'Message',
|
|
37
|
+
required: true,
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
run(context) {
|
|
41
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const { teamId, channelId, contentType, content } = context.propsValue;
|
|
43
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
44
|
+
authProvider: {
|
|
45
|
+
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
//https://learn.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http
|
|
49
|
+
const chatMessage = {
|
|
50
|
+
body: {
|
|
51
|
+
content: content,
|
|
52
|
+
contentType: contentType,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return yield client.api(`/teams/${teamId}/channels/${channelId}/messages`).post(chatMessage);
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=send-channel-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-channel-message.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-teams/src/lib/actions/send-channel-message.ts"],"names":[],"mappings":";;;;AAAA,8BAA4C;AAC5C,oEAAuE;AACvE,8EAA2D;AAC3D,sCAAiD;AAEpC,QAAA,wBAAwB,GAAG,IAAA,+BAAY,EAAC;IACpD,IAAI,EAAE,sBAAkB;IACxB,IAAI,EAAE,sCAAsC;IAC5C,WAAW,EAAE,sBAAsB;IACnC,WAAW,EAAE,uCAAuC;IACpD,KAAK,EAAE;QACN,MAAM,EAAE,6BAAoB,CAAC,MAAM;QACnC,SAAS,EAAE,6BAAoB,CAAC,SAAS;QACzC,WAAW,EAAE,2BAAQ,CAAC,cAAc,CAAC;YACpC,WAAW,EAAE,cAAc;YAC3B,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,MAAM;YACpB,OAAO,EAAE;gBACR,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE;oBACR;wBACC,KAAK,EAAE,MAAM;wBACb,KAAK,EAAE,MAAM;qBACb;oBACD;wBACC,KAAK,EAAE,MAAM;wBACb,KAAK,EAAE,MAAM;qBACb;iBACD;aACD;SACD,CAAC;QACF,OAAO,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC1B,WAAW,EAAE,SAAS;YACtB,QAAQ,EAAE,IAAI;SACd,CAAC;KACF;IACK,GAAG,CAAC,OAAO;;YAChB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;YAEvE,MAAM,MAAM,GAAG,+BAAM,CAAC,kBAAkB,CAAC;gBACxC,YAAY,EAAE;oBACb,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;iBAChE;aACD,CAAC,CAAC;YAEH,iGAAiG;YACjG,MAAM,WAAW,GAAG;gBACnB,IAAI,EAAE;oBACL,OAAO,EAAE,OAAO;oBAChB,WAAW,EAAE,WAAW;iBACxB;aACD,CAAC;YAEF,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,MAAM,aAAa,SAAS,WAAW,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9F,CAAC;KAAA;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const sendChatMessageAction: import("@scopieflows/pieces-framework").IAction<import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>, {
|
|
2
|
+
chatId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
3
|
+
contentType: import("@scopieflows/pieces-framework").StaticDropdownProperty<string, true>;
|
|
4
|
+
content: import("@scopieflows/pieces-framework").LongTextProperty<true>;
|
|
5
|
+
}>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendChatMessageAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const __1 = require("../..");
|
|
6
|
+
const pieces_framework_1 = require("@scopieflows/pieces-framework");
|
|
7
|
+
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
exports.sendChatMessageAction = (0, pieces_framework_1.createAction)({
|
|
10
|
+
auth: __1.microsoftTeamsAuth,
|
|
11
|
+
name: 'microsoft_teams_send_chat_message',
|
|
12
|
+
displayName: 'Send Chat Message',
|
|
13
|
+
description: 'Sends a message in an existing chat.',
|
|
14
|
+
props: {
|
|
15
|
+
chatId: common_1.microsoftTeamsCommon.chatId,
|
|
16
|
+
contentType: pieces_framework_1.Property.StaticDropdown({
|
|
17
|
+
displayName: 'Content Type',
|
|
18
|
+
required: true,
|
|
19
|
+
defaultValue: 'text',
|
|
20
|
+
options: {
|
|
21
|
+
disabled: false,
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
label: 'Text',
|
|
25
|
+
value: 'text',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'HTML',
|
|
29
|
+
value: 'html',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
content: pieces_framework_1.Property.LongText({
|
|
35
|
+
displayName: 'Message',
|
|
36
|
+
required: true,
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
run(context) {
|
|
40
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const { chatId, contentType, content } = context.propsValue;
|
|
42
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
43
|
+
authProvider: {
|
|
44
|
+
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const chatMessage = {
|
|
48
|
+
body: {
|
|
49
|
+
content: content,
|
|
50
|
+
contentType: contentType,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
return yield client.api(`/chats/${chatId}/messages`).post(chatMessage);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=send-chat-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-chat-message.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-teams/src/lib/actions/send-chat-message.ts"],"names":[],"mappings":";;;;AAAA,6BAA2C;AAC3C,oEAAuE;AACvE,8EAA2D;AAC3D,sCAAiD;AAEpC,QAAA,qBAAqB,GAAG,IAAA,+BAAY,EAAC;IACjD,IAAI,EAAE,sBAAkB;IACxB,IAAI,EAAE,mCAAmC;IACzC,WAAW,EAAE,mBAAmB;IAChC,WAAW,EAAE,sCAAsC;IACnD,KAAK,EAAE;QACN,MAAM,EAAE,6BAAoB,CAAC,MAAM;QACnC,WAAW,EAAE,2BAAQ,CAAC,cAAc,CAAC;YACpC,WAAW,EAAE,cAAc;YAC3B,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,MAAM;YACpB,OAAO,EAAE;gBACR,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE;oBACR;wBACC,KAAK,EAAE,MAAM;wBACb,KAAK,EAAE,MAAM;qBACb;oBACD;wBACC,KAAK,EAAE,MAAM;wBACb,KAAK,EAAE,MAAM;qBACb;iBACD;aACD;SACD,CAAC;QACF,OAAO,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC1B,WAAW,EAAE,SAAS;YACtB,QAAQ,EAAE,IAAI;SACd,CAAC;KACF;IACK,GAAG,CAAC,OAAO;;YAChB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;YAE5D,MAAM,MAAM,GAAG,+BAAM,CAAC,kBAAkB,CAAC;gBACxC,YAAY,EAAE;oBACb,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;iBAChE;aACD,CAAC,CAAC;YAEH,MAAM,WAAW,GAAG;gBACnB,IAAI,EAAE;oBACL,OAAO,EAAE,OAAO;oBAChB,WAAW,EAAE,WAAW;iBACxB;aACD,CAAC;YAEF,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxE,CAAC;KAAA;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Client } from '@microsoft/microsoft-graph-client';
|
|
2
|
+
type GraphRetryOptions = {
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
initialDelayMs?: number;
|
|
5
|
+
maxDelayMs?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const createGraphClient: (accessToken: string) => Client;
|
|
8
|
+
export declare const buildGraphErrorMessage: (error: any) => string;
|
|
9
|
+
export declare const withGraphRetry: <T>(requestFn: () => Promise<T>, options?: GraphRetryOptions) => Promise<T>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withGraphRetry = exports.buildGraphErrorMessage = exports.createGraphClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
6
|
+
const createGraphClient = (accessToken) => {
|
|
7
|
+
return microsoft_graph_client_1.Client.initWithMiddleware({
|
|
8
|
+
authProvider: {
|
|
9
|
+
getAccessToken: () => Promise.resolve(accessToken),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.createGraphClient = createGraphClient;
|
|
14
|
+
const delay = (ms) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return new Promise((resolve) => setTimeout(resolve, ms)); });
|
|
15
|
+
const parseRetryAfterMs = (error) => {
|
|
16
|
+
var _a, _b, _c, _d;
|
|
17
|
+
const headers = (_c = (_a = error === null || error === void 0 ? void 0 : error.headers) !== null && _a !== void 0 ? _a : (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : undefined;
|
|
18
|
+
const retryAfter = (_d = headers === null || headers === void 0 ? void 0 : headers['Retry-After']) !== null && _d !== void 0 ? _d : headers === null || headers === void 0 ? void 0 : headers['retry-after'];
|
|
19
|
+
if (!retryAfter)
|
|
20
|
+
return null;
|
|
21
|
+
const asNumber = Number(retryAfter);
|
|
22
|
+
if (!Number.isNaN(asNumber))
|
|
23
|
+
return asNumber * 1000;
|
|
24
|
+
// Retry-After can be HTTP-date; in that case, compute delta
|
|
25
|
+
const retryDate = Date.parse(retryAfter);
|
|
26
|
+
if (!Number.isNaN(retryDate)) {
|
|
27
|
+
return Math.max(0, retryDate - Date.now());
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
const extractStatusCode = (error) => {
|
|
32
|
+
var _a, _b, _c, _d, _e, _f;
|
|
33
|
+
return ((_f = (_d = (_b = (_a = error === null || error === void 0 ? void 0 : error.statusCode) !== null && _a !== void 0 ? _a : error === null || error === void 0 ? void 0 : error.status) !== null && _b !== void 0 ? _b : (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.status) !== null && _d !== void 0 ? _d : (_e = error === null || error === void 0 ? void 0 : error.response) === null || _e === void 0 ? void 0 : _e.statusCode) !== null && _f !== void 0 ? _f : 0);
|
|
34
|
+
};
|
|
35
|
+
const shouldRetry = (statusCode, code) => {
|
|
36
|
+
// Retry on throttling and transient errors
|
|
37
|
+
if (statusCode === 429 || statusCode === 503 || statusCode === 504)
|
|
38
|
+
return true;
|
|
39
|
+
// Some concurrency conflicts can be retried
|
|
40
|
+
if (statusCode === 409)
|
|
41
|
+
return true;
|
|
42
|
+
// Optionally retry generic server errors
|
|
43
|
+
if (statusCode >= 500 && statusCode < 600)
|
|
44
|
+
return true;
|
|
45
|
+
// Some SDKs surface codes like 'TooManyRequests'
|
|
46
|
+
if (code && /too\s*many\s*requests/i.test(code))
|
|
47
|
+
return true;
|
|
48
|
+
return false;
|
|
49
|
+
};
|
|
50
|
+
const buildGraphErrorMessage = (error) => {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
52
|
+
const status = extractStatusCode(error);
|
|
53
|
+
const err = (_c = (_b = (_a = error === null || error === void 0 ? void 0 : error.body) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : error === null || error === void 0 ? void 0 : error.error) !== null && _c !== void 0 ? _c : {};
|
|
54
|
+
const code = (_d = err === null || err === void 0 ? void 0 : err.code) !== null && _d !== void 0 ? _d : error === null || error === void 0 ? void 0 : error.code;
|
|
55
|
+
const message = (_f = (_e = err === null || err === void 0 ? void 0 : err.message) !== null && _e !== void 0 ? _e : error === null || error === void 0 ? void 0 : error.message) !== null && _f !== void 0 ? _f : 'Request failed';
|
|
56
|
+
const inner = (_h = (_g = err === null || err === void 0 ? void 0 : err.innerError) !== null && _g !== void 0 ? _g : err === null || err === void 0 ? void 0 : err.innererror) !== null && _h !== void 0 ? _h : {};
|
|
57
|
+
const requestId = (_k = (_j = inner === null || inner === void 0 ? void 0 : inner['request-id']) !== null && _j !== void 0 ? _j : inner === null || inner === void 0 ? void 0 : inner.requestId) !== null && _k !== void 0 ? _k : error === null || error === void 0 ? void 0 : error.requestId;
|
|
58
|
+
return `Graph error (${status}${code ? ` ${code}` : ''})${requestId ? ` [request-id: ${requestId}]` : ''}: ${message}`;
|
|
59
|
+
};
|
|
60
|
+
exports.buildGraphErrorMessage = buildGraphErrorMessage;
|
|
61
|
+
const withGraphRetry = (requestFn_1, ...args_1) => tslib_1.__awaiter(void 0, [requestFn_1, ...args_1], void 0, function* (requestFn, options = {}) {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
63
|
+
const maxRetries = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : 3;
|
|
64
|
+
const initialDelayMs = (_b = options.initialDelayMs) !== null && _b !== void 0 ? _b : 1000;
|
|
65
|
+
const maxDelayMs = (_c = options.maxDelayMs) !== null && _c !== void 0 ? _c : 10000;
|
|
66
|
+
let attempt = 0;
|
|
67
|
+
let delayMs = initialDelayMs;
|
|
68
|
+
while (attempt <= maxRetries) {
|
|
69
|
+
try {
|
|
70
|
+
return yield requestFn();
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
const status = extractStatusCode(e);
|
|
74
|
+
const code = (_h = (_f = (_e = (_d = e === null || e === void 0 ? void 0 : e.body) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.code) !== null && _f !== void 0 ? _f : (_g = e === null || e === void 0 ? void 0 : e.error) === null || _g === void 0 ? void 0 : _g.code) !== null && _h !== void 0 ? _h : e === null || e === void 0 ? void 0 : e.code;
|
|
75
|
+
if (attempt < maxRetries && shouldRetry(status, code)) {
|
|
76
|
+
const retryAfterMs = parseRetryAfterMs(e);
|
|
77
|
+
yield delay(Math.min(retryAfterMs !== null && retryAfterMs !== void 0 ? retryAfterMs : delayMs, maxDelayMs));
|
|
78
|
+
attempt++;
|
|
79
|
+
if (!retryAfterMs) {
|
|
80
|
+
delayMs = Math.min(delayMs * 2, maxDelayMs);
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
throw new Error((0, exports.buildGraphErrorMessage)(e));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw new Error("Unexpected error occured");
|
|
88
|
+
});
|
|
89
|
+
exports.withGraphRetry = withGraphRetry;
|
|
90
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-teams/src/lib/common/graph.ts"],"names":[],"mappings":";;;;AAAA,8EAA2D;AAQpD,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAU,EAAE;IAChE,OAAO,+BAAM,CAAC,kBAAkB,CAAC;QAChC,YAAY,EAAE;YACb,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;SAClD;KACD,CAAC,CAAC;AACJ,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B;AAEF,MAAM,KAAK,GAAG,CAAO,EAAU,EAAiB,EAAE,0DACjD,OAAA,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA,GAAA,CAAC;AAEnD,MAAM,iBAAiB,GAAG,CAAC,KAAU,EAAiB,EAAE;;IACvD,MAAM,OAAO,GACZ,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,0CAAE,OAAO,mCAAI,SAAS,CAAC;IACzD,MAAM,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,aAAa,CAAC,mCAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,aAAa,CAAC,CAAC;IACxE,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,GAAG,IAAI,CAAC;IACpD,4DAA4D;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,CAAC;AA9BW,QAAA,cAAc,kBA8BzB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const microsoftTeamsCommon: {
|
|
2
|
+
teamId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
3
|
+
channelId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
4
|
+
memberId: (isRequired?: boolean) => import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>> | import("@scopieflows/pieces-framework").DropdownProperty<string, false, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
5
|
+
memberIds: (isRequired?: boolean) => import("@scopieflows/pieces-framework").MultiSelectDropdownProperty<string, false, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>> | import("@scopieflows/pieces-framework").MultiSelectDropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
6
|
+
chatId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.microsoftTeamsCommon = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@scopieflows/pieces-framework");
|
|
6
|
+
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
7
|
+
const __1 = require("../../");
|
|
8
|
+
exports.microsoftTeamsCommon = {
|
|
9
|
+
teamId: pieces_framework_1.Property.Dropdown({
|
|
10
|
+
auth: __1.microsoftTeamsAuth,
|
|
11
|
+
displayName: 'Team ID',
|
|
12
|
+
refreshers: [],
|
|
13
|
+
required: true,
|
|
14
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
15
|
+
if (!auth) {
|
|
16
|
+
return {
|
|
17
|
+
disabled: true,
|
|
18
|
+
placeholder: 'Please connect your account first.',
|
|
19
|
+
options: [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const authValue = auth;
|
|
23
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
24
|
+
authProvider: {
|
|
25
|
+
getAccessToken: () => Promise.resolve(authValue.access_token),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const options = [];
|
|
29
|
+
// Pagination : https://learn.microsoft.com/en-us/graph/sdks/paging?view=graph-rest-1.0&tabs=typescript#manually-requesting-subsequent-pages
|
|
30
|
+
// List Joined Channels : https://learn.microsoft.com/en-us/graph/api/user-list-joinedteams?view=graph-rest-1.0&tabs=http
|
|
31
|
+
let response = yield client.api('/me/joinedTeams').get();
|
|
32
|
+
while (response.value.length > 0) {
|
|
33
|
+
for (const team of response.value) {
|
|
34
|
+
options.push({ label: team.displayName, value: team.id });
|
|
35
|
+
}
|
|
36
|
+
if (response['@odata.nextLink']) {
|
|
37
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
disabled: false,
|
|
45
|
+
options: options,
|
|
46
|
+
};
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
channelId: pieces_framework_1.Property.Dropdown({
|
|
50
|
+
auth: __1.microsoftTeamsAuth,
|
|
51
|
+
displayName: 'Channel ID',
|
|
52
|
+
refreshers: ['teamId'],
|
|
53
|
+
required: true,
|
|
54
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, teamId }) {
|
|
55
|
+
if (!auth || !teamId) {
|
|
56
|
+
return {
|
|
57
|
+
disabled: true,
|
|
58
|
+
placeholder: 'Please connect your account first and select team.',
|
|
59
|
+
options: [],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const authValue = auth;
|
|
63
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
64
|
+
authProvider: {
|
|
65
|
+
getAccessToken: () => Promise.resolve(authValue.access_token),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
const options = [];
|
|
69
|
+
// Pagination : https://learn.microsoft.com/en-us/graph/sdks/paging?view=graph-rest-1.0&tabs=typescript#manually-requesting-subsequent-pages
|
|
70
|
+
// List Channels : https://learn.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-1.0&tabs=http
|
|
71
|
+
let response = yield client.api(`/teams/${teamId}/channels`).get();
|
|
72
|
+
while (response.value.length > 0) {
|
|
73
|
+
for (const channel of response.value) {
|
|
74
|
+
options.push({ label: channel.displayName, value: channel.id });
|
|
75
|
+
}
|
|
76
|
+
if (response['@odata.nextLink']) {
|
|
77
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
disabled: false,
|
|
85
|
+
options: options,
|
|
86
|
+
};
|
|
87
|
+
}),
|
|
88
|
+
}),
|
|
89
|
+
memberId: (isRequired = false) => pieces_framework_1.Property.Dropdown({
|
|
90
|
+
auth: __1.microsoftTeamsAuth,
|
|
91
|
+
displayName: 'Member',
|
|
92
|
+
refreshers: ['teamId'],
|
|
93
|
+
required: isRequired,
|
|
94
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, teamId }) {
|
|
95
|
+
if (!auth || !teamId) {
|
|
96
|
+
return {
|
|
97
|
+
disabled: true,
|
|
98
|
+
placeholder: 'Please connect your account first and select team.',
|
|
99
|
+
options: [],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const authValue = auth;
|
|
103
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
104
|
+
authProvider: {
|
|
105
|
+
getAccessToken: () => Promise.resolve(authValue.access_token),
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
const options = [];
|
|
109
|
+
let response = yield client.api(`/teams/${teamId}/members`).get();
|
|
110
|
+
while (response.value.length > 0) {
|
|
111
|
+
for (const member of response.value) {
|
|
112
|
+
options.push({ label: member.displayName, value: member.id });
|
|
113
|
+
}
|
|
114
|
+
if (response['@odata.nextLink']) {
|
|
115
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
disabled: false,
|
|
123
|
+
options: options,
|
|
124
|
+
};
|
|
125
|
+
}),
|
|
126
|
+
}),
|
|
127
|
+
memberIds: (isRequired = false) => pieces_framework_1.Property.MultiSelectDropdown({
|
|
128
|
+
auth: __1.microsoftTeamsAuth,
|
|
129
|
+
displayName: 'Member',
|
|
130
|
+
refreshers: ['teamId'],
|
|
131
|
+
required: isRequired,
|
|
132
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, teamId }) {
|
|
133
|
+
if (!auth || !teamId) {
|
|
134
|
+
return {
|
|
135
|
+
disabled: true,
|
|
136
|
+
placeholder: 'Please connect your account first and select team.',
|
|
137
|
+
options: [],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const authValue = auth;
|
|
141
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
142
|
+
authProvider: {
|
|
143
|
+
getAccessToken: () => Promise.resolve(authValue.access_token),
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
const options = [];
|
|
147
|
+
let response = yield client.api(`/teams/${teamId}/members`).get();
|
|
148
|
+
while (response.value.length > 0) {
|
|
149
|
+
for (const member of response.value) {
|
|
150
|
+
options.push({ label: member.displayName, value: member.id });
|
|
151
|
+
}
|
|
152
|
+
if (response['@odata.nextLink']) {
|
|
153
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
disabled: false,
|
|
161
|
+
options: options,
|
|
162
|
+
};
|
|
163
|
+
}),
|
|
164
|
+
}),
|
|
165
|
+
chatId: pieces_framework_1.Property.Dropdown({
|
|
166
|
+
auth: __1.microsoftTeamsAuth,
|
|
167
|
+
displayName: 'Chat ID',
|
|
168
|
+
refreshers: [],
|
|
169
|
+
required: true,
|
|
170
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
171
|
+
var _b, _c;
|
|
172
|
+
if (!auth) {
|
|
173
|
+
return {
|
|
174
|
+
disabled: true,
|
|
175
|
+
placeholder: 'Please connect your account first and select team.',
|
|
176
|
+
options: [],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const authValue = auth;
|
|
180
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
181
|
+
authProvider: {
|
|
182
|
+
getAccessToken: () => Promise.resolve(authValue.access_token),
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
const options = [];
|
|
186
|
+
// Pagination : https://learn.microsoft.com/en-us/graph/sdks/paging?view=graph-rest-1.0&tabs=typescript#manually-requesting-subsequent-pages
|
|
187
|
+
// List Chats : https://learn.microsoft.com/en-us/graph/api/chat-list?view=graph-rest-1.0&tabs=http
|
|
188
|
+
let response = yield client.api('/chats').expand('members').get();
|
|
189
|
+
while (response.value.length > 0) {
|
|
190
|
+
for (const chat of response.value) {
|
|
191
|
+
const chatName = (_b = chat.topic) !== null && _b !== void 0 ? _b : (_c = chat.members) === null || _c === void 0 ? void 0 : _c.filter((member) => member.displayName).map((member) => member.displayName).join(',');
|
|
192
|
+
options.push({
|
|
193
|
+
label: `(${CHAT_TYPE[chat.chatType]} Chat) ${chatName || '(no title)'}`,
|
|
194
|
+
value: chat.id,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (response['@odata.nextLink']) {
|
|
198
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
disabled: false,
|
|
206
|
+
options: options,
|
|
207
|
+
};
|
|
208
|
+
}),
|
|
209
|
+
}),
|
|
210
|
+
};
|
|
211
|
+
const CHAT_TYPE = {
|
|
212
|
+
oneOnOne: '1 : 1',
|
|
213
|
+
group: 'Group',
|
|
214
|
+
meeting: 'Meeting',
|
|
215
|
+
unknownFutureValue: 'Unknown',
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-teams/src/lib/common/index.ts"],"names":[],"mappings":";;;;AAAA,oEAA+F;AAE/F,8EAA2E;AAE3E,8BAA4C;AAE/B,QAAA,oBAAoB,GAAG;IACnC,MAAM,EAAE,2BAAQ,CAAC,QAAQ,CAAC;QACzB,IAAI,EAAE,sBAAkB;QACxB,WAAW,EAAE,SAAS;QACtB,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;YACvB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACX,OAAO;oBACN,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,oCAAoC;oBACjD,OAAO,EAAE,EAAE;iBACX,CAAC;YACH,CAAC;YACD,MAAM,SAAS,GAAG,IAAuD,CAAC;YAE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AC,MAAM,CAAC,WAAW,EACtD,IAAI,CAAC,GAAG,CAAC,CAAC;oBACb,OAAO,CAAC,IAAI,CAAC;wBACZ,KAAK,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,QAAmC,CAAC,UAAU,QAAQ,IAAI,YAAY,EAAE;wBAClG,KAAK,EAAE,IAAI,CAAC,EAAG;qBACf,CAAC,CAAC;gBACJ,CAAC;gBACD,IAAI,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBACjC,QAAQ,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;gBAChE,CAAC;qBAAM,CAAC;oBACP,MAAM;gBACP,CAAC;YACF,CAAC;YACD,OAAO;gBACN,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,OAAO;aAChB,CAAC;QACH,CAAC,CAAA;KACD,CAAC;CACF,CAAC;AAEF,MAAM,SAAS,GAAG;IACjB,QAAQ,EAAE,OAAO;IACjB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,kBAAkB,EAAE,SAAS;CAC7B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TriggerStrategy } from '@scopieflows/pieces-framework';
|
|
2
|
+
export declare const newChannelMessageTrigger: import("@scopieflows/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>, {
|
|
3
|
+
teamId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
4
|
+
channelId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
5
|
+
}> | import("@scopieflows/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>, {
|
|
6
|
+
teamId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
7
|
+
channelId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
8
|
+
}> | import("@scopieflows/pieces-framework").ITrigger<TriggerStrategy.MANUAL, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>, {
|
|
9
|
+
teamId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
10
|
+
channelId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
11
|
+
}> | import("@scopieflows/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>, {
|
|
12
|
+
teamId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
13
|
+
channelId: import("@scopieflows/pieces-framework").DropdownProperty<string, true, import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>>;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newChannelMessageTrigger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const index_1 = require("../../index");
|
|
6
|
+
const pieces_common_1 = require("@scopieflows/pieces-common");
|
|
7
|
+
const pieces_framework_1 = require("@scopieflows/pieces-framework");
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
10
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
11
|
+
const shared_1 = require("@scopieflows/shared");
|
|
12
|
+
exports.newChannelMessageTrigger = (0, pieces_framework_1.createTrigger)({
|
|
13
|
+
auth: index_1.microsoftTeamsAuth,
|
|
14
|
+
name: 'new-channel-message',
|
|
15
|
+
displayName: 'New Channel Message',
|
|
16
|
+
description: 'Triggers when a new message is posted in a channel.',
|
|
17
|
+
props: {
|
|
18
|
+
teamId: common_1.microsoftTeamsCommon.teamId,
|
|
19
|
+
channelId: common_1.microsoftTeamsCommon.channelId,
|
|
20
|
+
},
|
|
21
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
22
|
+
onEnable(context) {
|
|
23
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
25
|
+
auth: context.auth,
|
|
26
|
+
store: context.store,
|
|
27
|
+
propsValue: context.propsValue,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
onDisable(context) {
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
34
|
+
auth: context.auth,
|
|
35
|
+
store: context.store,
|
|
36
|
+
propsValue: context.propsValue,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
test(context) {
|
|
41
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
run(context) {
|
|
46
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
sampleData: {
|
|
51
|
+
replyToId: null,
|
|
52
|
+
etag: '1747831213175',
|
|
53
|
+
messageType: 'message',
|
|
54
|
+
createdDateTime: '2025-05-21T12:40:13.175Z',
|
|
55
|
+
lastModifiedDateTime: '2025-05-21T12:40:13.175Z',
|
|
56
|
+
lastEditedDateTime: null,
|
|
57
|
+
deletedDateTime: null,
|
|
58
|
+
subject: 'Test',
|
|
59
|
+
summary: null,
|
|
60
|
+
chatId: null,
|
|
61
|
+
importance: 'normal',
|
|
62
|
+
locale: 'en-us',
|
|
63
|
+
webUrl: '',
|
|
64
|
+
policyViolation: null,
|
|
65
|
+
eventDetail: null,
|
|
66
|
+
id: '1747831213175',
|
|
67
|
+
from: {
|
|
68
|
+
application: null,
|
|
69
|
+
device: null,
|
|
70
|
+
user: {
|
|
71
|
+
'@odata.type': '#microsoft.graph.teamworkUserIdentity',
|
|
72
|
+
id: '90b3720d-f459-42c1-a02e-a1ecb068',
|
|
73
|
+
displayName: 'ScopieFlows',
|
|
74
|
+
userIdentityType: 'aadUser',
|
|
75
|
+
tenantId: '9b37335a-d996-4a8d-9ae4-a3a04c94',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
body: {
|
|
79
|
+
contentType: 'html',
|
|
80
|
+
content: '<p>Test Message</p>',
|
|
81
|
+
},
|
|
82
|
+
channelIdentity: {
|
|
83
|
+
teamId: '99cb9-7ebe-43ee-a69b-5f77ce8a4b4e',
|
|
84
|
+
channelId: '19:LiZnIkTo_1FmFY9OTsfym0q3bwo-y2UfV9FaYA1@thread.tacv2',
|
|
85
|
+
},
|
|
86
|
+
attachments: [],
|
|
87
|
+
mentions: [],
|
|
88
|
+
reactions: [],
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const polling = {
|
|
92
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
93
|
+
items(_a) {
|
|
94
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue, lastFetchEpochMS, store }) {
|
|
95
|
+
var _b, _c;
|
|
96
|
+
const { teamId, channelId } = propsValue;
|
|
97
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
98
|
+
authProvider: {
|
|
99
|
+
getAccessToken: () => Promise.resolve(auth.access_token),
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const messages = [];
|
|
103
|
+
if (lastFetchEpochMS === 0) {
|
|
104
|
+
const response = yield client
|
|
105
|
+
.api(`/teams/${teamId}/channels/${channelId}/messages`)
|
|
106
|
+
.top(5)
|
|
107
|
+
.get();
|
|
108
|
+
if (!(0, shared_1.isNil)(response.value)) {
|
|
109
|
+
messages.push(...response.value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const requestUrl = (_b = (yield store.get('deltalink'))) !== null && _b !== void 0 ? _b : `/teams/${teamId}/channels/${channelId}/messages/delta`;
|
|
114
|
+
let nextLink = requestUrl;
|
|
115
|
+
// https://learn.microsoft.com/en-us/graph/api/chatmessage-delta?view=graph-rest-1.0&tabs=http
|
|
116
|
+
while (nextLink) {
|
|
117
|
+
const response = yield client.api(nextLink).get();
|
|
118
|
+
const channelMessages = response.value;
|
|
119
|
+
if (Array.isArray(channelMessages)) {
|
|
120
|
+
messages.push(...channelMessages);
|
|
121
|
+
}
|
|
122
|
+
nextLink = (_c = response['@odata.nextLink']) !== null && _c !== void 0 ? _c : null;
|
|
123
|
+
if (response['@odata.deltaLink']) {
|
|
124
|
+
yield store.put('deltalink', response['@odata.deltaLink']);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return messages.map((message) => {
|
|
129
|
+
return {
|
|
130
|
+
epochMilliSeconds: (0, dayjs_1.default)(message.createdDateTime).valueOf(),
|
|
131
|
+
data: message,
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=new-channel-message.js.map
|