@activepieces/piece-chatwoot 0.0.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/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@activepieces/piece-chatwoot",
3
+ "version": "0.0.1",
4
+ "main": "./src/index.js",
5
+ "types": "./src/index.d.ts",
6
+ "scripts": {
7
+ "build": "tsc -p tsconfig.lib.json && cp package.json dist/",
8
+ "lint": "eslint 'src/**/*.ts'"
9
+ },
10
+ "dependencies": {
11
+ "@activepieces/pieces-common": "0.12.0",
12
+ "@activepieces/pieces-framework": "0.26.0",
13
+ "@activepieces/shared": "0.43.0",
14
+ "tslib": "2.6.2"
15
+ }
16
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export declare const chatwoot: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ apiAccessToken: import("@activepieces/pieces-framework").SecretTextProperty<true>;
4
+ accountId: import("@activepieces/pieces-framework").NumberProperty<true>;
5
+ }>>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,QAAQ;;;;GAwBnB,CAAC"}
package/src/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chatwoot = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const send_message_1 = require("./lib/actions/send-message");
7
+ const new_message_1 = require("./lib/triggers/new-message");
8
+ const auth_1 = require("./lib/auth");
9
+ const pieces_common_1 = require("@activepieces/pieces-common");
10
+ const types_1 = require("./lib/common/types");
11
+ const constants_1 = require("./lib/common/constants");
12
+ exports.chatwoot = (0, pieces_framework_1.createPiece)({
13
+ displayName: 'Chatwoot',
14
+ description: 'Receive and reply to customer messages with Chatwoot',
15
+ auth: auth_1.chatwootAuth,
16
+ minimumSupportedRelease: '0.30.0',
17
+ logoUrl: 'https://cdn.activepieces.com/pieces/chatwoot.png',
18
+ authors: ['AhmadTash'],
19
+ actions: [send_message_1.sendMessage,
20
+ (0, pieces_common_1.createCustomApiCallAction)({
21
+ auth: auth_1.chatwootAuth,
22
+ baseUrl: (auth) => {
23
+ const authValue = (0, types_1.getChatwootAuth)(auth);
24
+ return authValue.baseUrl;
25
+ },
26
+ authMapping: (auth) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
27
+ const authValue = (0, types_1.getChatwootAuth)(auth);
28
+ return {
29
+ [constants_1.CHATWOOT_AUTH_HEADER]: authValue.apiAccessToken,
30
+ };
31
+ }),
32
+ })
33
+ ],
34
+ triggers: [new_message_1.newMessage],
35
+ });
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAA6D;AAC7D,6DAAyD;AACzD,4DAAwD;AACxD,qCAA0C;AAC1C,+DAAwE;AACxE,8CAAqD;AACrD,sDAA8D;AAEjD,QAAA,QAAQ,GAAG,IAAA,8BAAW,EAAC;IAClC,WAAW,EAAE,UAAU;IACvB,WAAW,EAAE,sDAAsD;IACnE,IAAI,EAAE,mBAAY;IAClB,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EACL,kDAAkD;IACpD,OAAO,EAAE,CAAC,WAAW,CAAC;IACtB,OAAO,EAAE,CAAC,0BAAW;QACnB,IAAA,yCAAyB,EAAC;YACxB,IAAI,EAAC,mBAAY;YACjB,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChB,MAAM,SAAS,GAAG,IAAA,uBAAe,EAAC,IAAK,CAAC,CAAC;gBACzC,OAAO,SAAS,CAAC,OAAO,CAAC;YAC3B,CAAC;YACD,WAAW,EAAE,CAAO,IAAI,EAAE,EAAE;gBAC1B,MAAM,SAAS,GAAG,IAAA,uBAAe,EAAC,IAAK,CAAC,CAAC;gBACzC,OAAO;oBACL,CAAC,gCAAoB,CAAC,EAAE,SAAS,CAAC,cAAc;iBACjD,CAAC;YACJ,CAAC,CAAA;SACF,CAAC;KACH;IACD,QAAQ,EAAE,CAAC,wBAAU,CAAC;CACvB,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare const sendMessage: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ apiAccessToken: import("@activepieces/pieces-framework").SecretTextProperty<true>;
4
+ accountId: import("@activepieces/pieces-framework").NumberProperty<true>;
5
+ }>, {
6
+ conversationId: import("@activepieces/pieces-framework").NumberProperty<true>;
7
+ message: import("@activepieces/pieces-framework").LongTextProperty<true>;
8
+ isPrivate: import("@activepieces/pieces-framework").CheckboxProperty<true>;
9
+ }>;
10
+ //# sourceMappingURL=send-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-message.d.ts","sourceRoot":"","sources":["../../../../src/lib/actions/send-message.ts"],"names":[],"mappings":"AA4DA,eAAO,MAAM,WAAW;;;;;;;;EAmDtB,CAAC"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendMessage = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const pieces_common_1 = require("@activepieces/pieces-common");
7
+ const constants_1 = require("../common/constants");
8
+ const types_1 = require("../common/types");
9
+ const auth_1 = require("../auth");
10
+ const MAX_RETRIES = 3;
11
+ const INITIAL_BACKOFF_MS = 1000;
12
+ function sendWithRetry(baseUrl, accountId, conversationId, token, body) {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ var _a;
15
+ const endpoints = (0, constants_1.chatwootEndpoints)(baseUrl, accountId);
16
+ const url = endpoints.CONVERSATION_MESSAGES(conversationId);
17
+ let lastError;
18
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
19
+ try {
20
+ const response = yield pieces_common_1.httpClient.sendRequest({
21
+ method: pieces_common_1.HttpMethod.POST,
22
+ url,
23
+ headers: {
24
+ [constants_1.CHATWOOT_AUTH_HEADER]: token,
25
+ 'Content-Type': 'application/json',
26
+ },
27
+ body,
28
+ });
29
+ return response.body;
30
+ }
31
+ catch (error) {
32
+ lastError = error instanceof Error ? error : new Error(String(error));
33
+ const errorAny = error;
34
+ const statusCode = (_a = errorAny.response) === null || _a === void 0 ? void 0 : _a.status;
35
+ const isRetryable = statusCode === 429 ||
36
+ (statusCode !== undefined && statusCode >= 500);
37
+ if (!isRetryable || attempt === MAX_RETRIES - 1) {
38
+ throw lastError;
39
+ }
40
+ const backoffMs = INITIAL_BACKOFF_MS * Math.pow(2, attempt);
41
+ yield new Promise((resolve) => setTimeout(resolve, backoffMs));
42
+ }
43
+ }
44
+ throw lastError !== null && lastError !== void 0 ? lastError : new Error('Send message failed after retries');
45
+ });
46
+ }
47
+ exports.sendMessage = (0, pieces_framework_1.createAction)({
48
+ auth: auth_1.chatwootAuth,
49
+ name: 'send_message',
50
+ displayName: 'Send Message',
51
+ description: 'Send a message reply to a Chatwoot conversation',
52
+ props: {
53
+ conversationId: pieces_framework_1.Property.Number({
54
+ displayName: 'Conversation ID',
55
+ description: 'The numeric conversation display ID. Available from the trigger output.',
56
+ required: true,
57
+ }),
58
+ message: pieces_framework_1.Property.LongText({
59
+ displayName: 'Message',
60
+ description: 'The text message to send',
61
+ required: true,
62
+ }),
63
+ isPrivate: pieces_framework_1.Property.Checkbox({
64
+ displayName: 'Private Note',
65
+ description: 'If checked, sends as a private note visible only to agents (not the contact)',
66
+ required: true,
67
+ defaultValue: false,
68
+ }),
69
+ },
70
+ run(context) {
71
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
72
+ const { conversationId, message, isPrivate } = context.propsValue;
73
+ const authValue = (0, types_1.getChatwootAuth)(context.auth);
74
+ const body = {
75
+ content: message,
76
+ message_type: 'outgoing',
77
+ private: isPrivate,
78
+ content_type: 'text',
79
+ };
80
+ const result = yield sendWithRetry(authValue.baseUrl, authValue.accountId, conversationId, authValue.apiAccessToken, body);
81
+ return {
82
+ success: true,
83
+ messageId: result.id,
84
+ conversationId: result.conversation_id,
85
+ status: result.status,
86
+ };
87
+ });
88
+ },
89
+ });
90
+ //# sourceMappingURL=send-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-message.js","sourceRoot":"","sources":["../../../../src/lib/actions/send-message.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,+DAAqE;AACrE,mDAA8E;AAC9E,2CAGyB;AACzB,kCAAuC;AAEvC,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,SAAe,aAAa,CAC1B,OAAe,EACf,SAAiB,EACjB,cAAsB,EACtB,KAAa,EACb,IAA6B;;;QAE7B,MAAM,SAAS,GAAG,IAAA,6BAAiB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACxD,MAAM,GAAG,GAAG,SAAS,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAC5D,IAAI,SAA4B,CAAC;QAEjC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;YACvD,IAAI,CAAC;gBACH,MAAM,QAAQ,GACZ,MAAM,0BAAU,CAAC,WAAW,CAA8B;oBACxD,MAAM,EAAE,0BAAU,CAAC,IAAI;oBACvB,GAAG;oBACH,OAAO,EAAE;wBACP,CAAC,gCAAoB,CAAC,EAAE,KAAK;wBAC7B,cAAc,EAAE,kBAAkB;qBACnC;oBACD,IAAI;iBACL,CAAC,CAAC;gBAEL,OAAO,QAAQ,CAAC,IAAI,CA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0B;YACvC,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,SAAS,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC3B,WAAW,EAAE,cAAc;YAC3B,WAAW,EACT,8EAA8E;YAChF,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,KAAK;SACpB,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;YACf,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;YAClE,MAAM,SAAS,GAAG,IAAA,uBAAe,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAEhD,MAAM,IAAI,GAAG;gBACX,OAAO,EAAE,OAAO;gBAChB,YAAY,EAAE,UAAU;gBACxB,OAAO,EAAE,SAAS;gBAClB,YAAY,EAAE,MAAM;aACrB,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,aAAa,CAChC,SAAS,CAAC,OAAO,EACjB,SAAS,CAAC,SAAS,EACnB,cAAc,EACd,SAAS,CAAC,cAAc,EACxB,IAAI,CACL,CAAC;YAEF,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,MAAM,CAAC,EAAE;gBACpB,cAAc,EAAE,MAAM,CAAC,eAAe;gBACtC,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const chatwootAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ apiAccessToken: import("@activepieces/pieces-framework").SecretTextProperty<true>;
4
+ accountId: import("@activepieces/pieces-framework").NumberProperty<true>;
5
+ }>;
6
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/lib/auth.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,YAAY;;;;EAwBvB,CAAC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chatwootAuth = void 0;
4
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
5
+ const authDesc = `
6
+ To connect your Chatwoot account:
7
+
8
+ **Chatwoot URL:**
9
+ - For Chatwoot Cloud, use: \`https://app.chatwoot.com\`
10
+ - For self-hosted instances, use your server URL (e.g. \`https://chatwoot.yourcompany.com\`)
11
+
12
+ **API Access Token:**
13
+ 1. Log in to your Chatwoot dashboard.
14
+ 2. Click your avatar in the bottom-left corner and go to **Profile Settings**.
15
+ 3. Scroll down to the **Access Token** section.
16
+ 4. Copy your access token.
17
+
18
+ **Account ID:**
19
+ 1. In your Chatwoot dashboard, the Account ID is visible in the URL: \`/app/accounts/{ACCOUNT_ID}/...\`
20
+ 2. It is a numeric value (e.g. 1, 2, etc.)
21
+
22
+ `;
23
+ exports.chatwootAuth = pieces_framework_1.PieceAuth.CustomAuth({
24
+ displayName: 'Chatwoot Connection',
25
+ required: true,
26
+ description: authDesc,
27
+ props: {
28
+ baseUrl: pieces_framework_1.Property.ShortText({
29
+ displayName: 'Chatwoot URL',
30
+ description: 'Your Chatwoot instance URL (e.g. https://app.chatwoot.com)',
31
+ required: true,
32
+ defaultValue: 'https://app.chatwoot.com',
33
+ }),
34
+ apiAccessToken: pieces_framework_1.PieceAuth.SecretText({
35
+ displayName: 'API Access Token',
36
+ description: 'Your user API access token from Profile Settings',
37
+ required: true,
38
+ }),
39
+ accountId: pieces_framework_1.Property.Number({
40
+ displayName: 'Account ID',
41
+ description: 'Your numeric account ID (visible in the dashboard URL)',
42
+ required: true,
43
+ }),
44
+ },
45
+ });
46
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/lib/auth.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AAErE,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;CAiBhB,CAAC;AAEW,QAAA,YAAY,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC/C,WAAW,EAAE,qBAAqB;IAClC,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,QAAQ;IACrB,KAAK,EAAE;QACL,OAAO,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC1B,WAAW,EAAE,cAAc;YAC3B,WAAW,EACT,4DAA4D;YAC9D,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,0BAA0B;SACzC,CAAC;QACF,cAAc,EAAE,4BAAS,CAAC,UAAU,CAAC;YACnC,WAAW,EAAE,kBAAkB;YAC/B,WAAW,EAAE,kDAAkD;YAC/D,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,SAAS,EAAE,2BAAQ,CAAC,MAAM,CAAC;YACzB,WAAW,EAAE,YAAY;YACzB,WAAW,EACT,wDAAwD;YAC1D,QAAQ,EAAE,IAAI;SACf,CAAC;KACH;CACF,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const CHATWOOT_DEFAULT_BASE_URL = "https://app.chatwoot.com";
2
+ export declare function chatwootEndpoints(baseUrl: string, accountId: number): {
3
+ readonly WEBHOOKS: `${string}/api/v1/accounts/${number}/webhooks`;
4
+ readonly WEBHOOK_BY_ID: (webhookId: number) => string;
5
+ readonly CONVERSATION_MESSAGES: (conversationId: number) => string;
6
+ readonly PROFILE: `${string}/auth/sign_in`;
7
+ };
8
+ export declare const CHATWOOT_AUTH_HEADER = "api_access_token";
9
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/lib/common/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,6BAA6B,CAAC;AAEpE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;wCAIrC,MAAM;qDAEO,MAAM;;EAIjD;AAED,eAAO,MAAM,oBAAoB,qBAAqB,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CHATWOOT_AUTH_HEADER = exports.CHATWOOT_DEFAULT_BASE_URL = void 0;
4
+ exports.chatwootEndpoints = chatwootEndpoints;
5
+ exports.CHATWOOT_DEFAULT_BASE_URL = 'https://app.chatwoot.com';
6
+ function chatwootEndpoints(baseUrl, accountId) {
7
+ const base = (baseUrl !== null && baseUrl !== void 0 ? baseUrl : '').replace(/\/+$/, '');
8
+ return {
9
+ WEBHOOKS: `${base}/api/v1/accounts/${accountId}/webhooks`,
10
+ WEBHOOK_BY_ID: (webhookId) => `${base}/api/v1/accounts/${accountId}/webhooks/${webhookId}`,
11
+ CONVERSATION_MESSAGES: (conversationId) => `${base}/api/v1/accounts/${accountId}/conversations/${conversationId}/messages`,
12
+ PROFILE: `${base}/auth/sign_in`,
13
+ };
14
+ }
15
+ exports.CHATWOOT_AUTH_HEADER = 'api_access_token';
16
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/lib/common/constants.ts"],"names":[],"mappings":";;;AAEA,8CAUC;AAZY,QAAA,yBAAyB,GAAG,0BAA0B,CAAC;AAEpE,SAAgB,iBAAiB,CAAC,OAAe,EAAE,SAAiB;IAClE,MAAM,IAAI,GAAG,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACjD,OAAO;QACL,QAAQ,EAAE,GAAG,IAAI,oBAAoB,SAAS,WAAW;QACzD,aAAa,EAAE,CAAC,SAAiB,EAAE,EAAE,CACnC,GAAG,IAAI,oBAAoB,SAAS,aAAa,SAAS,EAAE;QAC9D,qBAAqB,EAAE,CAAC,cAAsB,EAAE,EAAE,CAChD,GAAG,IAAI,oBAAoB,SAAS,kBAAkB,cAAc,WAAW;QACjF,OAAO,EAAE,GAAG,IAAI,eAAe;KACvB,CAAC;AACb,CAAC;AAEY,QAAA,oBAAoB,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
2
+ import { chatwootAuth } from '../auth';
3
+ export interface ChatwootWebhookSender {
4
+ id: number;
5
+ name: string;
6
+ email?: string;
7
+ phone_number?: string;
8
+ type?: string;
9
+ }
10
+ export interface ChatwootWebhookContact {
11
+ id: number;
12
+ name: string;
13
+ email?: string;
14
+ phone_number?: string;
15
+ }
16
+ export interface ChatwootWebhookConversation {
17
+ display_id: number;
18
+ additional_attributes?: Record<string, unknown>;
19
+ }
20
+ export interface ChatwootWebhookAccount {
21
+ id: number;
22
+ name: string;
23
+ }
24
+ export type ChatwootMessageType = 'incoming' | 'outgoing' | 'template';
25
+ export interface ChatwootWebhookPayload {
26
+ event: string;
27
+ id: number;
28
+ content: string;
29
+ created_at: string;
30
+ message_type: ChatwootMessageType;
31
+ content_type: string;
32
+ content_attributes: Record<string, unknown>;
33
+ source_id: string;
34
+ sender: ChatwootWebhookSender;
35
+ contact: ChatwootWebhookContact;
36
+ conversation: ChatwootWebhookConversation;
37
+ account: ChatwootWebhookAccount;
38
+ }
39
+ export interface ChatwootParsedMessage {
40
+ messageId: number;
41
+ content: string;
42
+ messageType: ChatwootMessageType;
43
+ conversationId: number;
44
+ contactId: number;
45
+ contactName: string;
46
+ accountId: number;
47
+ createdAt: string;
48
+ }
49
+ export interface ChatwootCreateWebhookRequest {
50
+ url: string;
51
+ subscriptions: string[];
52
+ }
53
+ export interface ChatwootWebhookResponse {
54
+ payload: {
55
+ webhook: {
56
+ id: number;
57
+ };
58
+ };
59
+ }
60
+ /** Single webhook in list response (GET /webhooks) */
61
+ export interface ChatwootWebhookListItem {
62
+ id: number;
63
+ url: string;
64
+ subscriptions?: string[];
65
+ account_id?: number;
66
+ }
67
+ export interface ChatwootSendMessageRequest {
68
+ content: string;
69
+ message_type: 'outgoing';
70
+ private: boolean;
71
+ content_type: 'text';
72
+ }
73
+ export interface ChatwootSendMessageResponse {
74
+ id: number;
75
+ content: string;
76
+ account_id: number;
77
+ inbox_id: number;
78
+ conversation_id: number;
79
+ message_type: number;
80
+ created_at: number;
81
+ updated_at: number;
82
+ private: boolean;
83
+ status: string;
84
+ content_type: string;
85
+ sender_type: string;
86
+ sender_id: number;
87
+ }
88
+ export interface ChatwootAuthProps {
89
+ baseUrl: string;
90
+ apiAccessToken: string;
91
+ accountId: number;
92
+ }
93
+ /** Normalize auth from either V0 (props only) or V1 (connection value with type + props) */
94
+ export declare function getChatwootAuth(auth: AppConnectionValueForAuthProperty<typeof chatwootAuth>): ChatwootAuthProps;
95
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CAC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AAC;IAChB,YAAY,EAAE,UAAU,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,IAAI,EAAE,iCAAiC,CAAC,OAAO,YAAY,CAAC,GAAG,iBAAiB,CAM/G"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChatwootAuth = getChatwootAuth;
4
+ /** Normalize auth from either V0 (props only) or V1 (connection value with type + props) */
5
+ function getChatwootAuth(auth) {
6
+ var _a, _b, _c;
7
+ return {
8
+ baseUrl: (_a = auth.props.baseUrl) !== null && _a !== void 0 ? _a : '',
9
+ accountId: (_b = auth.props.accountId) !== null && _b !== void 0 ? _b : 0,
10
+ apiAccessToken: (_c = auth.props.apiAccessToken) !== null && _c !== void 0 ? _c : '',
11
+ };
12
+ }
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/lib/common/types.ts"],"names":[],"mappings":";;AA2GA,0CAMC;AAPD,4FAA4F;AAC5F,SAAgB,eAAe,CAAC,IAA4D;;IAC1F,OAAO;QACL,OAAO,EAAE,MAAA,IAAI,CAAC,KAAK,CAAC,OAAO,mCAAI,EAAE;QACjC,SAAS,EAAE,MAAA,IAAI,CAAC,KAAK,CAAC,SAAS,mCAAI,CAAC;QACpC,cAAc,EAAE,MAAA,IAAI,CAAC,KAAK,CAAC,cAAc,mCAAI,EAAE;KAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { TriggerStrategy } from '@activepieces/pieces-framework';
2
+ export declare const newMessage: import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
3
+ baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
4
+ apiAccessToken: import("@activepieces/pieces-framework").SecretTextProperty<true>;
5
+ accountId: import("@activepieces/pieces-framework").NumberProperty<true>;
6
+ }>, {}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@activepieces/pieces-framework").CustomAuthProperty<{
7
+ baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
8
+ apiAccessToken: import("@activepieces/pieces-framework").SecretTextProperty<true>;
9
+ accountId: import("@activepieces/pieces-framework").NumberProperty<true>;
10
+ }>, {}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.MANUAL, import("@activepieces/pieces-framework").CustomAuthProperty<{
11
+ baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
12
+ apiAccessToken: import("@activepieces/pieces-framework").SecretTextProperty<true>;
13
+ accountId: import("@activepieces/pieces-framework").NumberProperty<true>;
14
+ }>, {}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
15
+ baseUrl: import("@activepieces/pieces-framework").ShortTextProperty<true>;
16
+ apiAccessToken: import("@activepieces/pieces-framework").SecretTextProperty<true>;
17
+ accountId: import("@activepieces/pieces-framework").NumberProperty<true>;
18
+ }>, {}>;
19
+ //# sourceMappingURL=new-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new-message.d.ts","sourceRoot":"","sources":["../../../../src/lib/triggers/new-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,eAAe,EAAE,MAAM,gCAAgC,CAAC;AA4ChF,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;OA0LrB,CAAC"}
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newMessage = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const pieces_common_1 = require("@activepieces/pieces-common");
7
+ const constants_1 = require("../common/constants");
8
+ const types_1 = require("../common/types");
9
+ const auth_1 = require("../auth");
10
+ const WEBHOOK_STORE_KEY = '_chatwoot_webhook_id';
11
+ function normalizeUrl(u) {
12
+ if (u == null || typeof u !== 'string')
13
+ return '';
14
+ return u.trim().replace(/\/+$/, '');
15
+ }
16
+ function toWebhookList(raw) {
17
+ if (Array.isArray(raw))
18
+ return raw;
19
+ if (raw && typeof raw === 'object') {
20
+ const o = raw;
21
+ // Top-level array keys
22
+ for (const key of ['payload', 'data', 'webhooks']) {
23
+ const v = o[key];
24
+ if (Array.isArray(v))
25
+ return v;
26
+ }
27
+ // Chatwoot returns { payload: { webhooks: [...] } }
28
+ const payload = o['payload'];
29
+ if (payload && typeof payload === 'object') {
30
+ const p = payload;
31
+ const w = p['webhooks'];
32
+ if (Array.isArray(w))
33
+ return w;
34
+ }
35
+ const data = o['data'];
36
+ if (data && typeof data === 'object') {
37
+ const d = data;
38
+ const w = d['webhooks'];
39
+ if (Array.isArray(w))
40
+ return w;
41
+ }
42
+ }
43
+ return [];
44
+ }
45
+ exports.newMessage = (0, pieces_framework_1.createTrigger)({
46
+ auth: auth_1.chatwootAuth,
47
+ name: 'new_message',
48
+ displayName: 'New Incoming Message',
49
+ description: 'Triggers when a contact sends a new message in a Chatwoot conversation',
50
+ type: pieces_framework_1.TriggerStrategy.WEBHOOK,
51
+ props: {},
52
+ sampleData: {
53
+ messageId: 42,
54
+ content: 'Hello, I need help with my order',
55
+ messageType: 'incoming',
56
+ conversationId: 7,
57
+ contactId: 15,
58
+ contactName: 'Jane Doe',
59
+ accountId: 1,
60
+ createdAt: '2024-06-15 10:30:00 UTC',
61
+ },
62
+ onEnable(context) {
63
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
64
+ var _a, _b, _c;
65
+ const authValue = (0, types_1.getChatwootAuth)(context.auth);
66
+ const endpoints = (0, constants_1.chatwootEndpoints)(authValue.baseUrl, authValue.accountId);
67
+ const webhookUrl = context.webhookUrl;
68
+ // List existing webhooks and reuse if this URL is already registered (avoids 422 "Url has already been taken")
69
+ let webhookId;
70
+ try {
71
+ const listRes = yield pieces_common_1.httpClient.sendRequest({
72
+ method: pieces_common_1.HttpMethod.GET,
73
+ url: endpoints.WEBHOOKS,
74
+ headers: {
75
+ [constants_1.CHATWOOT_AUTH_HEADER]: authValue.apiAccessToken,
76
+ },
77
+ });
78
+ const list = toWebhookList(listRes.body);
79
+ const targetUrl = normalizeUrl(webhookUrl);
80
+ const existing = list.find((w) => normalizeUrl(w.url) === targetUrl);
81
+ if (existing) {
82
+ webhookId = existing.id;
83
+ }
84
+ else {
85
+ const createRes = yield pieces_common_1.httpClient.sendRequest({
86
+ method: pieces_common_1.HttpMethod.POST,
87
+ url: endpoints.WEBHOOKS,
88
+ headers: {
89
+ [constants_1.CHATWOOT_AUTH_HEADER]: authValue.apiAccessToken,
90
+ 'Content-Type': 'application/json',
91
+ },
92
+ body: {
93
+ url: webhookUrl,
94
+ subscriptions: ['message_created'],
95
+ },
96
+ });
97
+ webhookId = createRes.body.payload.webhook.id;
98
+ }
99
+ }
100
+ catch (err) {
101
+ const status = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.status;
102
+ const body = (_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.body;
103
+ if (status === 422 && body && typeof body === 'object' && 'message' in body && ((_c = body.message) === null || _c === void 0 ? void 0 : _c.includes('already been taken'))) {
104
+ // List might have failed or returned different shape; try listing again with generic type
105
+ const listRes = yield pieces_common_1.httpClient.sendRequest({
106
+ method: pieces_common_1.HttpMethod.GET,
107
+ url: endpoints.WEBHOOKS,
108
+ headers: { [constants_1.CHATWOOT_AUTH_HEADER]: authValue.apiAccessToken },
109
+ });
110
+ const list = toWebhookList(listRes.body);
111
+ const targetUrl = normalizeUrl(webhookUrl);
112
+ const existing = list.find((w) => normalizeUrl(w.url) === targetUrl);
113
+ if (existing === null || existing === void 0 ? void 0 : existing.id) {
114
+ webhookId = existing.id;
115
+ }
116
+ else {
117
+ throw err;
118
+ }
119
+ }
120
+ else {
121
+ throw err;
122
+ }
123
+ }
124
+ yield context.store.put(WEBHOOK_STORE_KEY, { webhookId });
125
+ });
126
+ },
127
+ onDisable(context) {
128
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
129
+ const authValue = (0, types_1.getChatwootAuth)(context.auth);
130
+ const endpoints = (0, constants_1.chatwootEndpoints)(authValue.baseUrl, authValue.accountId);
131
+ const stored = yield context.store.get(WEBHOOK_STORE_KEY);
132
+ if (!(stored === null || stored === void 0 ? void 0 : stored.webhookId)) {
133
+ return;
134
+ }
135
+ try {
136
+ yield pieces_common_1.httpClient.sendRequest({
137
+ method: pieces_common_1.HttpMethod.DELETE,
138
+ url: endpoints.WEBHOOK_BY_ID(stored.webhookId),
139
+ headers: {
140
+ [constants_1.CHATWOOT_AUTH_HEADER]: authValue.apiAccessToken,
141
+ },
142
+ });
143
+ }
144
+ catch (error) {
145
+ console.error('[Chatwoot] Error deleting webhook:', error);
146
+ }
147
+ yield context.store.delete(WEBHOOK_STORE_KEY);
148
+ });
149
+ },
150
+ run(context) {
151
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
152
+ var _a;
153
+ // Engine passes TriggerPayload: { body, headers, queryParams }. Chatwoot POST body may be raw or wrapped in .payload
154
+ const rawBody = (_a = context.payload) === null || _a === void 0 ? void 0 : _a.body;
155
+ const payload = (rawBody && typeof rawBody === 'object' && 'payload' in rawBody)
156
+ ? rawBody['payload']
157
+ : rawBody;
158
+ if (!payload || typeof payload !== 'object') {
159
+ return [];
160
+ }
161
+ const event = payload['event'];
162
+ if (event !== 'message_created') {
163
+ return [];
164
+ }
165
+ const messageType = payload['message_type'];
166
+ if (messageType !== 'incoming') {
167
+ return [];
168
+ }
169
+ const content = payload['content'];
170
+ if (content == null || String(content).trim().length === 0) {
171
+ return [];
172
+ }
173
+ const conversation = payload['conversation'];
174
+ const contact = payload['contact'];
175
+ const sender = payload['sender'];
176
+ const account = payload['account'];
177
+ // Chatwoot sends conversation.id (not display_id) in webhook payloads
178
+ // Try display_id first (for API compatibility), then fall back to id
179
+ let conversationId = 0;
180
+ if (conversation != null && typeof conversation === 'object') {
181
+ if ('display_id' in conversation) {
182
+ const displayId = conversation['display_id'];
183
+ conversationId = displayId != null ? Number(displayId) || 0 : 0;
184
+ }
185
+ else if ('id' in conversation) {
186
+ const id = conversation['id'];
187
+ conversationId = id != null ? Number(id) || 0 : 0;
188
+ }
189
+ }
190
+ // Contact info may be in 'contact' or 'sender' field
191
+ const contactObj = contact || sender;
192
+ const contactId = contactObj != null && typeof contactObj === 'object' && 'id' in contactObj
193
+ ? Number(contactObj['id']) || 0
194
+ : 0;
195
+ const contactName = contactObj != null && typeof contactObj === 'object' && 'name' in contactObj
196
+ ? String(contactObj['name'])
197
+ : 'Unknown';
198
+ const accountId = account != null && typeof account === 'object' && 'id' in account
199
+ ? Number(account['id']) || 0
200
+ : 0;
201
+ const messageId = typeof payload['id'] === 'number' ? payload['id'] : Number(payload['id']) || 0;
202
+ const createdAt = payload['created_at'] != null ? String(payload['created_at']) : '';
203
+ const parsed = {
204
+ messageId,
205
+ content: String(content).trim(),
206
+ messageType: 'incoming',
207
+ conversationId,
208
+ contactId,
209
+ contactName,
210
+ accountId,
211
+ createdAt,
212
+ };
213
+ return [parsed];
214
+ });
215
+ },
216
+ });
217
+ //# sourceMappingURL=new-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new-message.js","sourceRoot":"","sources":["../../../../src/lib/triggers/new-message.ts"],"names":[],"mappings":";;;;AAAA,qEAAgF;AAChF,+DAAqE;AACrE,mDAA8E;AAC9E,2CAKyB;AACzB,kCAAuC;AAEvC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAEjD,SAAS,YAAY,CAAC,CAAqB;IACzC,IAAI,CAAC,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IAClD,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,aAAa,CAAC,GAAY;IACjC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IACnC,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,GAA8B,CAAC;QACzC,uBAAuB;QACvB,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC;YAClD,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YACjB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,oDAAoD;QACpD,MAAM,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAC7B,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC3C,MAAM,CAAC,GAAG,OAAkC,CAAC;YAC7C,MAAM,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;YACxB,I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