@activepieces/piece-slack 0.0.0-pre1

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 ADDED
@@ -0,0 +1,7 @@
1
+ # pieces-slack
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running lint
6
+
7
+ Run `nx lint pieces-slack` to execute the lint via [ESLint](https://eslint.org/).
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@activepieces/piece-slack",
3
+ "version": "0.0.0-pre1",
4
+ "dependencies": {
5
+ "@sinclair/typebox": "0.24.51",
6
+ "axios": "1.2.4",
7
+ "cron-validator": "1.3.1",
8
+ "nanoid": "3.3.4"
9
+ },
10
+ "peerDependencies": {
11
+ "@activepieces/framework": "0.0.1",
12
+ "@activepieces/shared": "0.0.1",
13
+ "tslib": "2.4.1"
14
+ },
15
+ "main": "./src/index.js",
16
+ "types": "./src/index.d.ts"
17
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const slack: import("@activepieces/framework").Piece;
package/src/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slack = void 0;
4
+ const framework_1 = require("@activepieces/framework");
5
+ const send_direct_message_action_1 = require("./lib/actions/send-direct-message-action");
6
+ const send_message_action_1 = require("./lib/actions/send-message-action");
7
+ const package_json_1 = require("../package.json");
8
+ exports.slack = (0, framework_1.createPiece)({
9
+ name: 'slack',
10
+ displayName: 'Slack',
11
+ logoUrl: 'https://cdn.activepieces.com/pieces/slack.png',
12
+ version: package_json_1.version,
13
+ actions: [
14
+ send_direct_message_action_1.slackSendDirectMessageAction,
15
+ send_message_action_1.slackSendMessageAction,
16
+ ],
17
+ triggers: []
18
+ });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/slack/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AACrD,yFAAuF;AACvF,2EAA0E;AAC1E,kDAAyC;AAE5B,QAAA,KAAK,GAAG,IAAA,uBAAW,EAAC;IAChC,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,OAAO;IACpB,OAAO,EAAE,+CAA+C;IACvD,OAAO,EAAP,sBAAO;IACR,OAAO,EAAE;QACN,yDAA4B;QAC5B,4CAAsB;KACvB;IACF,QAAQ,EAAE,EACR;CACF,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export declare const slackSendDirectMessageAction: import("@activepieces/framework").Action;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slackSendDirectMessageAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const framework_1 = require("@activepieces/framework");
6
+ const props_1 = require("../common/props");
7
+ const utils_1 = require("../common/utils");
8
+ exports.slackSendDirectMessageAction = (0, framework_1.createAction)({
9
+ name: 'send_direct_message',
10
+ displayName: 'Send message to a user',
11
+ description: 'Send message to a user',
12
+ sampleData: {
13
+ success: true,
14
+ message: 'sample message',
15
+ results: [1, 2, 3, 4],
16
+ },
17
+ props: {
18
+ authentication: props_1.slackAuth,
19
+ userId: framework_1.Property.Dropdown({
20
+ displayName: 'User',
21
+ description: 'Message receiver',
22
+ required: true,
23
+ refreshers: ['authentication'],
24
+ options(propsValue) {
25
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
26
+ const auth = propsValue['authentication'];
27
+ if (!auth) {
28
+ return {
29
+ disabled: true,
30
+ placeholder: 'connect slack account',
31
+ options: [],
32
+ };
33
+ }
34
+ const accessToken = auth.access_token;
35
+ const request = {
36
+ method: framework_1.HttpMethod.GET,
37
+ url: 'https://slack.com/api/users.list',
38
+ authentication: {
39
+ type: framework_1.AuthenticationType.BEARER_TOKEN,
40
+ token: accessToken,
41
+ },
42
+ };
43
+ const response = yield framework_1.httpClient.sendRequest(request);
44
+ const options = response.body.members.map(member => ({
45
+ label: member.name,
46
+ value: member.id,
47
+ }));
48
+ return {
49
+ disabled: false,
50
+ placeholder: 'Select channel',
51
+ options,
52
+ };
53
+ });
54
+ },
55
+ }),
56
+ text: framework_1.Property.LongText({
57
+ displayName: 'Message',
58
+ description: 'The text of your message',
59
+ required: true,
60
+ }),
61
+ },
62
+ run(context) {
63
+ var _a;
64
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
65
+ const token = (_a = context.propsValue.authentication) === null || _a === void 0 ? void 0 : _a.access_token;
66
+ const { text, userId } = context.propsValue;
67
+ (0, framework_1.assertNotNullOrUndefined)(token, 'token');
68
+ (0, framework_1.assertNotNullOrUndefined)(text, 'text');
69
+ (0, framework_1.assertNotNullOrUndefined)(userId, 'userId');
70
+ return (0, utils_1.slackSendMessage)({
71
+ token,
72
+ text,
73
+ conversationId: userId,
74
+ });
75
+ });
76
+ },
77
+ });
78
+ //# sourceMappingURL=send-direct-message-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-direct-message-action.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/slack/src/lib/actions/send-direct-message-action.ts"],"names":[],"mappings":";;;;AAAA,uDASgC;AAChC,2CAA2C;AAC3C,2CAAkD;AAErC,QAAA,4BAA4B,GAAG,IAAA,wBAAY,EAAC;IACvD,IAAI,EAAE,qBAAqB;IAC3B,WAAW,EAAE,wBAAwB;IACrC,WAAW,EAAE,wBAAwB;IACrC,UAAU,EAAE;QACV,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,gBAAgB;QACzB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;KACtB;IACD,KAAK,EAAE;QACL,cAAc,EAAE,iBAAS;QACzB,MAAM,EAAE,oBAAQ,CAAC,QAAQ,CAAS;YAChC,WAAW,EAAE,MAAM;YACnB,WAAW,EAAE,kBAAkB;YAC/B,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,CAAC,gBAAgB,CA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CAAC,CAAA;YACxC,IAAA,oCAAwB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YACtC,IAAA,oCAAwB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;YAE1C,OAAO,IAAA,wBAAgB,EAAC;gBACtB,KAAK;gBACL,IAAI;gBACJ,cAAc,EAAE,MAAM;aACvB,CAAC,CAAA;;KACH;CACF,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export declare const slackSendMessageAction: import("@activepieces/framework").Action;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slackSendMessageAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const framework_1 = require("@activepieces/framework");
6
+ const props_1 = require("../common/props");
7
+ const utils_1 = require("../common/utils");
8
+ exports.slackSendMessageAction = (0, framework_1.createAction)({
9
+ name: 'send_channel_message',
10
+ displayName: 'Send message to a channel',
11
+ description: 'Send message to a channel',
12
+ sampleData: {
13
+ success: true,
14
+ message: 'sample message',
15
+ results: [1, 2, 3, 4],
16
+ },
17
+ props: {
18
+ authentication: props_1.slackAuth,
19
+ channel: framework_1.Property.Dropdown({
20
+ displayName: 'Channel',
21
+ description: 'Channel, private group, or IM channel to send message to.',
22
+ required: true,
23
+ refreshers: ['authentication'],
24
+ options(value) {
25
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
26
+ if (!value['authentication']) {
27
+ return {
28
+ disabled: true,
29
+ placeholder: 'connect slack account',
30
+ options: [],
31
+ };
32
+ }
33
+ const authentication = value['authentication'];
34
+ const accessToken = authentication['access_token'];
35
+ const request = {
36
+ method: framework_1.HttpMethod.GET,
37
+ url: `https://slack.com/api/conversations.list?types=public_channel,private_channel`,
38
+ authentication: {
39
+ type: framework_1.AuthenticationType.BEARER_TOKEN,
40
+ token: accessToken,
41
+ },
42
+ };
43
+ const response = yield framework_1.httpClient.sendRequest(request);
44
+ return {
45
+ disabled: false,
46
+ placeholder: 'Select channel',
47
+ options: response.body.channels.map((ch) => {
48
+ return {
49
+ label: ch.name,
50
+ value: ch.id,
51
+ };
52
+ }),
53
+ };
54
+ });
55
+ },
56
+ }),
57
+ text: framework_1.Property.LongText({
58
+ displayName: 'Message',
59
+ description: 'The text of your message',
60
+ required: true,
61
+ }),
62
+ },
63
+ run(context) {
64
+ var _a;
65
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
66
+ const token = (_a = context.propsValue.authentication) === null || _a === void 0 ? void 0 : _a.access_token;
67
+ const { text, channel } = context.propsValue;
68
+ (0, framework_1.assertNotNullOrUndefined)(token, 'token');
69
+ (0, framework_1.assertNotNullOrUndefined)(text, 'text');
70
+ (0, framework_1.assertNotNullOrUndefined)(channel, 'channel');
71
+ return (0, utils_1.slackSendMessage)({
72
+ token,
73
+ text,
74
+ conversationId: channel,
75
+ });
76
+ });
77
+ },
78
+ });
79
+ //# sourceMappingURL=send-message-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-message-action.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/slack/src/lib/actions/send-message-action.ts"],"names":[],"mappings":";;;;AAAA,uDASgC;AAChC,2CAA2C;AAC3C,2CAAkD;AAErC,QAAA,sBAAsB,GAAG,IAAA,wBAAY,EAAC;IACjD,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EAAE,2BAA2B;IACxC,WAAW,EAAE,2BAA2B;IACxC,UAAU,EAAE;QACV,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,gBAAgB;QACzB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;KACtB;IACD,KAAK,EAAE;QACL,cAAc,EAAE,iBAAS;QACzB,OAAO,EAAE,oBAAQ,CAAC,QAAQ,CAAC;YACzB,WAAW,EAAE,SAAS;YACtB,WAAW,EAAE,2DAA2D;YACxE,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,CAAC,gBAAgB,CAAC;YACxB,OAAO,CAAC,KAAK;;oBACjB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,IAAA,oCAAwB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YACtC,IAAA,oCAAwB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAA;YAE5C,OAAO,IAAA,wBAAgB,EAAC;gBACtB,KAAK;gBACL,IAAI;gBACJ,cAAc,EAAE,OAAO;aACxB,CAAC,CAAA;;KACH;CACF,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export declare const slackAuth: import("@activepieces/framework").OAuth2Property<true>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slackAuth = void 0;
4
+ const framework_1 = require("@activepieces/framework");
5
+ exports.slackAuth = framework_1.Property.OAuth2({
6
+ description: '',
7
+ displayName: 'Authentication',
8
+ authUrl: 'https://slack.com/oauth/authorize',
9
+ tokenUrl: 'https://slack.com/api/oauth.access',
10
+ required: true,
11
+ scope: [
12
+ 'channels:read',
13
+ 'channels:write',
14
+ 'chat:write:bot',
15
+ 'groups:read',
16
+ 'mpim:read',
17
+ 'users:read',
18
+ ],
19
+ });
20
+ //# sourceMappingURL=props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/slack/src/lib/common/props.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAErC,QAAA,SAAS,GAAG,oBAAQ,CAAC,MAAM,CAAC;IACvC,WAAW,EAAE,EAAE;IACf,WAAW,EAAE,gBAAgB;IAC7B,OAAO,EAAE,mCAAmC;IAC5C,QAAQ,EAAE,oCAAoC;IAC9C,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACL,eAAe;QACf,gBAAgB;QAChB,gBAAgB;QAChB,aAAa;QACb,WAAW;QACX,YAAY;KACb;CACF,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ export declare const slackSendMessage: ({ text, conversationId, token }: SlackSendMessageParams) => Promise<{
2
+ success: boolean;
3
+ request_body: SlackSendMessageRequestBody | undefined;
4
+ response_body: import("@activepieces/framework").HttpMessageBody;
5
+ }>;
6
+ declare type SlackSendMessageRequestBody = {
7
+ text: string;
8
+ channel: string;
9
+ };
10
+ declare type SlackSendMessageParams = {
11
+ token: string;
12
+ conversationId: string;
13
+ text: string;
14
+ };
15
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slackSendMessage = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const framework_1 = require("@activepieces/framework");
6
+ const slackSendMessage = ({ text, conversationId, token }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
7
+ const request = {
8
+ method: framework_1.HttpMethod.POST,
9
+ url: 'https://slack.com/api/chat.postMessage',
10
+ body: {
11
+ text,
12
+ channel: conversationId,
13
+ },
14
+ authentication: {
15
+ type: framework_1.AuthenticationType.BEARER_TOKEN,
16
+ token,
17
+ },
18
+ };
19
+ const response = yield framework_1.httpClient.sendRequest(request);
20
+ return {
21
+ success: true,
22
+ request_body: request.body,
23
+ response_body: response.body,
24
+ };
25
+ });
26
+ exports.slackSendMessage = slackSendMessage;
27
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/slack/src/lib/common/utils.ts"],"names":[],"mappings":";;;;AAAA,uDAAiG;AAE1F,MAAM,gBAAgB,GAAG,CAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAA0B,EAAE,EAAE;IAChG,MAAM,OAAO,GAA6C;QACxD,MAAM,EAAE,sBAAU,CAAC,IAAI;QACvB,GAAG,EAAE,wCAAwC;QAC7C,IAAI,EAAE;YACJ,IAAI;YACJ,OAAO,EAAE,cAAc;SACxB;QACD,cAAc,EAAE;YACd,IAAI,EAAE,8BAAkB,CAAC,YAAY;YACrC,KAAK;SACN;KACF,CAAA;IAED,MAAM,QAAQ,GAAG,MAAM,sBAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAEtD,OAAO;QACL,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,OAAO,CAAC,IAAI;QAC1B,aAAa,EAAE,QAAQ,CAAC,IAAI;KAC7B,CAAA;AACH,CAAC,CAAA,CAAA;AArBY,QAAA,gBAAgB,oBAqB5B"}