@segment/action-destinations 3.169.0 → 3.171.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/dist/destinations/acoustic/Utility/eventprocessing.js +18 -18
- package/dist/destinations/acoustic/Utility/eventprocessing.js.map +1 -1
- package/dist/destinations/adobe-target/adobeTarget_operations.js +3 -3
- package/dist/destinations/adobe-target/adobeTarget_operations.js.map +1 -1
- package/dist/destinations/airship/customEvents/generated-types.d.ts +9 -0
- package/dist/destinations/airship/customEvents/generated-types.js +3 -0
- package/dist/destinations/airship/customEvents/generated-types.js.map +1 -0
- package/dist/destinations/airship/customEvents/index.d.ts +5 -0
- package/dist/destinations/airship/customEvents/index.js +59 -0
- package/dist/destinations/airship/customEvents/index.js.map +1 -0
- package/dist/destinations/airship/generated-types.d.ts +5 -0
- package/dist/destinations/airship/generated-types.js +3 -0
- package/dist/destinations/airship/generated-types.js.map +1 -0
- package/dist/destinations/airship/index.d.ts +4 -0
- package/dist/destinations/airship/index.js +97 -0
- package/dist/destinations/airship/index.js.map +1 -0
- package/dist/destinations/airship/manageTags/generated-types.d.ts +7 -0
- package/dist/destinations/airship/manageTags/generated-types.js +3 -0
- package/dist/destinations/airship/manageTags/generated-types.js.map +1 -0
- package/dist/destinations/airship/manageTags/index.d.ts +5 -0
- package/dist/destinations/airship/manageTags/index.js +38 -0
- package/dist/destinations/airship/manageTags/index.js.map +1 -0
- package/dist/destinations/airship/setAttributes/generated-types.d.ts +30 -0
- package/dist/destinations/airship/setAttributes/generated-types.js +3 -0
- package/dist/destinations/airship/setAttributes/generated-types.js.map +1 -0
- package/dist/destinations/airship/setAttributes/index.d.ts +5 -0
- package/dist/destinations/airship/setAttributes/index.js +182 -0
- package/dist/destinations/airship/setAttributes/index.js.map +1 -0
- package/dist/destinations/airship/utilities.d.ts +28 -0
- package/dist/destinations/airship/utilities.js +146 -0
- package/dist/destinations/airship/utilities.js.map +1 -0
- package/dist/destinations/ambee/generated-types.d.ts +7 -0
- package/dist/destinations/ambee/generated-types.js +3 -0
- package/dist/destinations/ambee/generated-types.js.map +1 -0
- package/dist/destinations/ambee/index.d.ts +4 -0
- package/dist/destinations/ambee/index.js +62 -0
- package/dist/destinations/ambee/index.js.map +1 -0
- package/dist/destinations/ambee/subscribeUserToCampaign/generated-types.d.ts +9 -0
- package/dist/destinations/ambee/subscribeUserToCampaign/generated-types.js +3 -0
- package/dist/destinations/ambee/subscribeUserToCampaign/generated-types.js.map +1 -0
- package/dist/destinations/ambee/subscribeUserToCampaign/index.d.ts +5 -0
- package/dist/destinations/ambee/subscribeUserToCampaign/index.js +88 -0
- package/dist/destinations/ambee/subscribeUserToCampaign/index.js.map +1 -0
- package/dist/destinations/emarsys/addToContactList/index.d.ts +1 -1
- package/dist/destinations/emarsys/addToContactList/index.js +4 -8
- package/dist/destinations/emarsys/addToContactList/index.js.map +1 -1
- package/dist/destinations/emarsys/emarsys-helper.js +0 -4
- package/dist/destinations/emarsys/emarsys-helper.js.map +1 -1
- package/dist/destinations/emarsys/removeFromContactList/index.d.ts +1 -1
- package/dist/destinations/emarsys/removeFromContactList/index.js +4 -8
- package/dist/destinations/emarsys/removeFromContactList/index.js.map +1 -1
- package/dist/destinations/emarsys/triggerEvent/index.d.ts +1 -1
- package/dist/destinations/emarsys/triggerEvent/index.js +7 -12
- package/dist/destinations/emarsys/triggerEvent/index.js.map +1 -1
- package/dist/destinations/emarsys/upsertContact/index.d.ts +1 -1
- package/dist/destinations/emarsys/upsertContact/index.js +6 -11
- package/dist/destinations/emarsys/upsertContact/index.js.map +1 -1
- package/dist/destinations/encharge/createUpdateObject/index.js +2 -2
- package/dist/destinations/encharge/createUpdateObject/index.js.map +1 -1
- package/dist/destinations/encharge/index.js +1 -1
- package/dist/destinations/encharge/index.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/index.js +3 -1
- package/dist/destinations/engage-messaging-twilio/index.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/generated-types.d.ts +31 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/generated-types.js +3 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/generated-types.js.map +1 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/index.d.ts +5 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/index.js +202 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/index.js.map +1 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/push-sender.d.ts +17 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/push-sender.js +173 -0
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/push-sender.js.map +1 -0
- package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.d.ts +3 -5
- package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.js +27 -74
- package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.d.ts +2 -2
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.js +4 -4
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/utils/message-sender.d.ts +13 -11
- package/dist/destinations/engage-messaging-twilio/utils/message-sender.js +122 -126
- package/dist/destinations/engage-messaging-twilio/utils/message-sender.js.map +1 -1
- package/dist/destinations/engage-messaging-twilio/utils/phone-message.d.ts +12 -0
- package/dist/destinations/engage-messaging-twilio/utils/phone-message.js +100 -0
- package/dist/destinations/engage-messaging-twilio/utils/phone-message.js.map +1 -0
- package/dist/destinations/engage-messaging-twilio/utils/test-utils.d.ts +34 -0
- package/dist/destinations/engage-messaging-twilio/utils/test-utils.js +35 -0
- package/dist/destinations/engage-messaging-twilio/utils/test-utils.js.map +1 -0
- package/dist/destinations/engage-messaging-twilio/utils/types.d.ts +39 -0
- package/dist/destinations/engage-messaging-twilio/utils/types.js +3 -0
- package/dist/destinations/engage-messaging-twilio/utils/types.js.map +1 -0
- package/dist/destinations/facebook-conversions-api/addToCart/generated-types.d.ts +21 -0
- package/dist/destinations/facebook-conversions-api/addToCart/index.js +3 -0
- package/dist/destinations/facebook-conversions-api/addToCart/index.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/custom/generated-types.d.ts +21 -0
- package/dist/destinations/facebook-conversions-api/custom/index.js +3 -0
- package/dist/destinations/facebook-conversions-api/custom/index.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/fb-capi-app-data.d.ts +10 -0
- package/dist/destinations/facebook-conversions-api/fb-capi-app-data.js +179 -0
- package/dist/destinations/facebook-conversions-api/fb-capi-app-data.js.map +1 -0
- package/dist/destinations/facebook-conversions-api/index.js +1 -1
- package/dist/destinations/facebook-conversions-api/index.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/initiateCheckout/generated-types.d.ts +21 -0
- package/dist/destinations/facebook-conversions-api/initiateCheckout/index.js +3 -0
- package/dist/destinations/facebook-conversions-api/initiateCheckout/index.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/pageView/generated-types.d.ts +21 -0
- package/dist/destinations/facebook-conversions-api/pageView/index.js +3 -0
- package/dist/destinations/facebook-conversions-api/pageView/index.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/purchase/generated-types.d.ts +21 -0
- package/dist/destinations/facebook-conversions-api/purchase/index.js +3 -0
- package/dist/destinations/facebook-conversions-api/purchase/index.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/search/generated-types.d.ts +21 -0
- package/dist/destinations/facebook-conversions-api/search/index.js +3 -0
- package/dist/destinations/facebook-conversions-api/search/index.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/viewContent/generated-types.d.ts +21 -0
- package/dist/destinations/facebook-conversions-api/viewContent/index.js +3 -0
- package/dist/destinations/facebook-conversions-api/viewContent/index.js.map +1 -1
- package/dist/destinations/facebook-custom-audiences/generated-types.d.ts +3 -0
- package/dist/destinations/facebook-custom-audiences/generated-types.js +3 -0
- package/dist/destinations/facebook-custom-audiences/generated-types.js.map +1 -0
- package/dist/destinations/facebook-custom-audiences/index.d.ts +4 -0
- package/dist/destinations/facebook-custom-audiences/index.js +32 -0
- package/dist/destinations/facebook-custom-audiences/index.js.map +1 -0
- package/dist/destinations/facebook-custom-audiences/syncEngage/generated-types.d.ts +3 -0
- package/dist/destinations/facebook-custom-audiences/syncEngage/generated-types.js +3 -0
- package/dist/destinations/facebook-custom-audiences/syncEngage/generated-types.js.map +1 -0
- package/dist/destinations/facebook-custom-audiences/syncEngage/index.d.ts +5 -0
- package/dist/destinations/facebook-custom-audiences/syncEngage/index.js +18 -0
- package/dist/destinations/facebook-custom-audiences/syncEngage/index.js.map +1 -0
- package/dist/destinations/facebook-custom-audiences/syncRetl/generated-types.d.ts +3 -0
- package/dist/destinations/facebook-custom-audiences/syncRetl/generated-types.js +3 -0
- package/dist/destinations/facebook-custom-audiences/syncRetl/generated-types.js.map +1 -0
- package/dist/destinations/facebook-custom-audiences/syncRetl/index.d.ts +5 -0
- package/dist/destinations/facebook-custom-audiences/syncRetl/index.js +18 -0
- package/dist/destinations/facebook-custom-audiences/syncRetl/index.js.map +1 -0
- package/dist/destinations/fullstory/index.js +1 -1
- package/dist/destinations/fullstory/index.js.map +1 -1
- package/dist/destinations/heap/identifyUser/index.js +0 -3
- package/dist/destinations/heap/identifyUser/index.js.map +1 -1
- package/dist/destinations/heap/trackEvent/index.js +0 -3
- package/dist/destinations/heap/trackEvent/index.js.map +1 -1
- package/dist/destinations/index.js +5 -0
- package/dist/destinations/index.js.map +1 -1
- package/dist/destinations/livelike-cloud/trackEvent/index.js +0 -3
- package/dist/destinations/livelike-cloud/trackEvent/index.js.map +1 -1
- package/dist/destinations/noop/generated-types.d.ts +2 -0
- package/dist/destinations/noop/generated-types.js +3 -0
- package/dist/destinations/noop/generated-types.js.map +1 -0
- package/dist/destinations/noop/index.d.ts +4 -0
- package/dist/destinations/noop/index.js +27 -0
- package/dist/destinations/noop/index.js.map +1 -0
- package/dist/destinations/noop/noop/generated-types.d.ts +3 -0
- package/dist/destinations/noop/noop/generated-types.js +3 -0
- package/dist/destinations/noop/noop/generated-types.js.map +1 -0
- package/dist/destinations/noop/noop/index.d.ts +5 -0
- package/dist/destinations/noop/noop/index.js +19 -0
- package/dist/destinations/noop/noop/index.js.map +1 -0
- package/dist/destinations/pinterest-conversions/reportConversionEvent/index.js.map +1 -1
- package/dist/destinations/podscribe/page/generated-types.d.ts +3 -0
- package/dist/destinations/podscribe/page/index.js +10 -1
- package/dist/destinations/podscribe/page/index.js.map +1 -1
- package/dist/destinations/podscribe/track/generated-types.d.ts +3 -0
- package/dist/destinations/podscribe/track/index.js +10 -1
- package/dist/destinations/podscribe/track/index.js.map +1 -1
- package/dist/destinations/the-trade-desk-crm/generated-types.d.ts +2 -0
- package/dist/destinations/the-trade-desk-crm/index.js +15 -1
- package/dist/destinations/the-trade-desk-crm/index.js.map +1 -1
- package/dist/destinations/tiktok-audiences/functions.d.ts +1 -1
- package/dist/destinations/tiktok-audiences/functions.js +3 -0
- package/dist/destinations/tiktok-audiences/functions.js.map +1 -1
- package/dist/destinations/tiktok-conversions/reportWebEvent/index.js +1 -1
- package/dist/destinations/tiktok-conversions/reportWebEvent/index.js.map +1 -1
- package/dist/destinations/userpilot/generated-types.d.ts +4 -0
- package/dist/destinations/userpilot/generated-types.js +3 -0
- package/dist/destinations/userpilot/generated-types.js.map +1 -0
- package/dist/destinations/userpilot/identifyUser/generated-types.d.ts +7 -0
- package/dist/destinations/userpilot/identifyUser/generated-types.js +3 -0
- package/dist/destinations/userpilot/identifyUser/generated-types.js.map +1 -0
- package/dist/destinations/userpilot/identifyUser/index.d.ts +5 -0
- package/dist/destinations/userpilot/identifyUser/index.js +52 -0
- package/dist/destinations/userpilot/identifyUser/index.js.map +1 -0
- package/dist/destinations/userpilot/index.d.ts +4 -0
- package/dist/destinations/userpilot/index.js +70 -0
- package/dist/destinations/userpilot/index.js.map +1 -0
- package/dist/destinations/userpilot/request-utils.d.ts +13 -0
- package/dist/destinations/userpilot/request-utils.js +62 -0
- package/dist/destinations/userpilot/request-utils.js.map +1 -0
- package/dist/destinations/userpilot/trackEvent/generated-types.d.ts +7 -0
- package/dist/destinations/userpilot/trackEvent/generated-types.js +3 -0
- package/dist/destinations/userpilot/trackEvent/generated-types.js.map +1 -0
- package/dist/destinations/userpilot/trackEvent/index.d.ts +5 -0
- package/dist/destinations/userpilot/trackEvent/index.js +48 -0
- package/dist/destinations/userpilot/trackEvent/index.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendMobilePush/push-sender.ts"],"names":[],"mappings":";;;AACA,wDAAmF;AACnF,4DAAuD;AAGvD,wDAA8D;AAU9D,MAAM,YAAa,SAAQ,wBAAS;CAQnC;AAED,MAAa,UAAwC,SAAQ,8BAAsB;IAAnF;;QAEY,2BAAsB,GAAa,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;QACpE,yBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QACjC,qBAAgB,GAAG,6BAA6B,CAAA;IAwO1D,CAAC;IAtOC,cAAc;QACZ,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,iDAAiD,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;YAC7G,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,iDAAiD,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;YACvF,OAAM;SACP;QAED,MAAM,cAAc,GAClB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,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,gBAAgB,EAAE,oBAAoB,CAAC,CAAA"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Payload } from './generated-types';
|
|
2
|
-
import {
|
|
3
|
-
export declare class SmsMessageSender extends
|
|
2
|
+
import { PhoneMessage } from '../utils/phone-message';
|
|
3
|
+
export declare class SmsMessageSender extends PhoneMessage<Payload> {
|
|
4
|
+
protected supportedTemplateTypes: string[];
|
|
4
5
|
getBody(phone: string): Promise<URLSearchParams>;
|
|
5
6
|
getChannelType(): string;
|
|
6
7
|
isValidExternalId(externalId: NonNullable<Payload['externalIds']>[number]): boolean;
|
|
7
8
|
private getProfileTraits;
|
|
8
|
-
private getContentTemplate;
|
|
9
|
-
private getUnparsedContent;
|
|
10
|
-
private parseContent;
|
|
11
9
|
}
|
|
@@ -1,77 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SmsMessageSender = void 0;
|
|
4
|
-
const liquidjs_1 = require("liquidjs");
|
|
5
4
|
const actions_core_1 = require("@segment/actions-core");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
class SmsMessageSender extends message_sender_1.MessageSender {
|
|
5
|
+
const phone_message_1 = require("../utils/phone-message");
|
|
6
|
+
class SmsMessageSender extends phone_message_1.PhoneMessage {
|
|
9
7
|
constructor() {
|
|
10
8
|
super(...arguments);
|
|
11
|
-
this.
|
|
12
|
-
if (!this.payload.userId) {
|
|
13
|
-
this.logError(`Unable to process SMS, no userId provided and no traits provided - ${this.settings.spaceId}`);
|
|
14
|
-
throw new actions_core_1.IntegrationError('Unable to process sms, no userId provided and no traits provided', 'Invalid parameters', 400);
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const { region, profileApiEnvironment, spaceId, profileApiAccessToken } = this.settings;
|
|
18
|
-
const domainName = region === 'eu-west-1' ? 'profiles.euw1.segment' : 'profiles.segment';
|
|
19
|
-
const topLevelName = profileApiEnvironment === 'production' ? 'com' : 'build';
|
|
20
|
-
const response = await this.request(`https://${domainName}.${topLevelName}/v1/spaces/${spaceId}/collections/users/profiles/user_id:${encodeURIComponent(this.payload.userId)}/traits?limit=200`, {
|
|
21
|
-
headers: {
|
|
22
|
-
authorization: `Basic ${Buffer.from(profileApiAccessToken + ':').toString('base64')}`,
|
|
23
|
-
'content-type': 'application/json'
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
this.tags.push(`profile_status_code:${response.status}`);
|
|
27
|
-
this.statsClient?.incr('actions-personas-messaging-twilio.profile_invoked', 1, this.tags);
|
|
28
|
-
const body = await response.json();
|
|
29
|
-
return body.traits;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
this.statsClient?.incr('actions-personas-messaging-twilio.profile_error', 1, this.tags);
|
|
33
|
-
this.logError(`SMS profile traits request failure - ${this.settings.spaceId} - [${error}]`);
|
|
34
|
-
throw new actions_core_1.IntegrationError('Unable to get profile traits for SMS message', 'SMS trait fetch failure', 500);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
this.getContentTemplate = async () => {
|
|
38
|
-
const twilioToken = Buffer.from(`${this.settings.twilioApiKeySID}:${this.settings.twilioApiKeySecret}`).toString('base64');
|
|
39
|
-
try {
|
|
40
|
-
this.logInfo("Get content template from Twilio by ContentSID");
|
|
41
|
-
const response = await this.request(`https://content.twilio.com/v1/Content/${this.payload.contentSid}`, {
|
|
42
|
-
method: 'GET',
|
|
43
|
-
headers: {
|
|
44
|
-
authorization: `Basic ${twilioToken}`
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
const data = await response.json();
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
this.tags.push('reason:get_content_template');
|
|
52
|
-
this.statsClient?.incr('actions-personas-messaging-twilio.error', 1, this.tags);
|
|
53
|
-
this.logError(`SMS failed request to fetch content template from Twilio Content API - ${this.settings.spaceId} - ${error}, ${JSON.stringify(error)})}`);
|
|
54
|
-
throw new actions_core_1.IntegrationError('Unable to fetch content template', 'Twilio Content API request failure', 500);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
this.getUnparsedContent = (data) => {
|
|
58
|
-
if (!data.types) {
|
|
59
|
-
this.logError(`SMS template from Twilio Content API does not contain a template type - ${this.settings.spaceId} - [${JSON.stringify(data)}]`);
|
|
60
|
-
throw new actions_core_1.IntegrationError('Unexpected response from Twilio Content API', `SMS template does not contain a template type`, 500);
|
|
61
|
-
}
|
|
62
|
-
const type = Object.keys(data.types)[0];
|
|
63
|
-
if (type === 'twilio/text' || type === 'twilio/media') {
|
|
64
|
-
return { body: data.types[type].body, media: data.types[type].media };
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.logError(`SMS unsupported content template type '${type}' - ${this.settings.spaceId}`);
|
|
68
|
-
throw new actions_core_1.IntegrationError('Unsupported content type', `Sending templates with '${type}' content type is not supported by SMS`, 400);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
9
|
+
this.supportedTemplateTypes = ['twilio/text', 'twilio/media'];
|
|
71
10
|
}
|
|
72
11
|
async getBody(phone) {
|
|
73
12
|
if (!this.payload.body && !this.payload.contentSid) {
|
|
74
|
-
this.logError(`
|
|
13
|
+
this.logError(`unable to process, no body provided and no content sid provided - ${this.settings.spaceId}`);
|
|
75
14
|
throw new actions_core_1.PayloadValidationError('Unable to process sms, no body provided and no content sid provided');
|
|
76
15
|
}
|
|
77
16
|
let traits;
|
|
@@ -89,8 +28,8 @@ class SmsMessageSender extends message_sender_1.MessageSender {
|
|
|
89
28
|
let parsedBody;
|
|
90
29
|
let parsedMedia = [];
|
|
91
30
|
if (this.payload.contentSid) {
|
|
92
|
-
const data = await this.
|
|
93
|
-
const parsed = await this.parseContent(
|
|
31
|
+
const data = await this.getContentTemplateTypes();
|
|
32
|
+
const parsed = await this.parseContent(data, profile);
|
|
94
33
|
parsedBody = parsed.body;
|
|
95
34
|
parsedMedia = parsed.media;
|
|
96
35
|
}
|
|
@@ -119,16 +58,30 @@ class SmsMessageSender extends message_sender_1.MessageSender {
|
|
|
119
58
|
}
|
|
120
59
|
return !externalId.channelType || externalId.channelType.toLowerCase() === this.getChannelType();
|
|
121
60
|
}
|
|
122
|
-
async
|
|
61
|
+
async getProfileTraits() {
|
|
62
|
+
if (!this.payload.userId) {
|
|
63
|
+
this.logError(`Unable to process, no userId provided and no traits provided - ${this.settings.spaceId}`);
|
|
64
|
+
throw new actions_core_1.PayloadValidationError('Unable to process sms, no userId provided and no traits provided');
|
|
65
|
+
}
|
|
123
66
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
67
|
+
const { region, profileApiEnvironment, spaceId, profileApiAccessToken } = this.settings;
|
|
68
|
+
const domainName = region === 'eu-west-1' ? 'profiles.euw1.segment' : 'profiles.segment';
|
|
69
|
+
const topLevelName = profileApiEnvironment === 'production' ? 'com' : 'build';
|
|
70
|
+
const response = await this.request(`https://${domainName}.${topLevelName}/v1/spaces/${spaceId}/collections/users/profiles/user_id:${encodeURIComponent(this.payload.userId)}/traits?limit=200`, {
|
|
71
|
+
headers: {
|
|
72
|
+
authorization: `Basic ${Buffer.from(profileApiAccessToken + ':').toString('base64')}`,
|
|
73
|
+
'content-type': 'application/json'
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
this.tags.push(`profile_status_code:${response.status}`);
|
|
77
|
+
this.statsClient?.incr('actions-personas-messaging-twilio.profile_invoked', 1, this.tags);
|
|
78
|
+
const body = await response.json();
|
|
79
|
+
return body.traits;
|
|
128
80
|
}
|
|
129
81
|
catch (error) {
|
|
130
|
-
this.
|
|
131
|
-
|
|
82
|
+
this.statsClient?.incr('actions-personas-messaging-twilio.profile_error', 1, this.tags);
|
|
83
|
+
this.logError(`profile traits request failure - ${this.settings.spaceId} - [${error}]`);
|
|
84
|
+
throw new actions_core_1.IntegrationError('Unable to get profile traits for SMS message', 'SMS trait fetch failure', 500);
|
|
132
85
|
}
|
|
133
86
|
}
|
|
134
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sms-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendSms/sms-sender.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"sms-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendSms/sms-sender.ts"],"names":[],"mappings":";;;AAEA,wDAAgF;AAChF,0DAAqD;AAErD,MAAa,gBAAiB,SAAQ,4BAAqB;IAA3D;;QACY,2BAAsB,GAAa,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;IA+F9E,CAAC;IA7FC,KAAK,CAAC,OAAO,CAAC,KAAa;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAClD,IAAI,CAAC,QAAQ,CAAC,qEAAqE,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;YAC3G,MAAM,IAAI,qCAAsB,CAAC,qEAAqE,CAAC,CAAA;SACxG;QAID,IAAI,MAAM,CAAA;QACV,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE;YAChC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;SAC1D;aAAM;YACL,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAA;SACvC;QAED,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS;YACzC,KAAK;YACL,MAAM;SACP,CAAA;QAED,IAAI,UAAkB,CAAA;QACtB,IAAI,WAAW,GAAyB,EAAE,CAAA;QAE1C,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC3B,MAAM,IAAI,GAAG,MAAM,I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C,oCAAoC,IAAI,CAAC,QAAQ,CAAC,OAAO,OAAO,KAAK,GAAG,CAAC,CAAA;YACvF,MAAM,IAAI,+BAAgB,CAAC,8CAA8C,EAAE,yBAAyB,EAAE,GAAG,CAAC,CAAA;SAC3G;IACH,CAAC;CACF;AAhGD,4CAgGC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Payload } from './generated-types';
|
|
2
|
-
import {
|
|
3
|
-
export declare class WhatsAppMessageSender extends
|
|
2
|
+
import { PhoneMessage } from '../utils/phone-message';
|
|
3
|
+
export declare class WhatsAppMessageSender extends PhoneMessage<Payload> {
|
|
4
4
|
getChannelType(): string;
|
|
5
5
|
getBody(phone: string): Promise<URLSearchParams>;
|
|
6
6
|
private getVariables;
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WhatsAppMessageSender = void 0;
|
|
4
4
|
const liquidjs_1 = require("liquidjs");
|
|
5
5
|
const actions_core_1 = require("@segment/actions-core");
|
|
6
|
-
const message_sender_1 = require("../utils/message-sender");
|
|
7
6
|
const google_libphonenumber_1 = require("google-libphonenumber");
|
|
7
|
+
const phone_message_1 = require("../utils/phone-message");
|
|
8
8
|
const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
|
|
9
9
|
const Liquid = new liquidjs_1.Liquid();
|
|
10
|
-
class WhatsAppMessageSender extends
|
|
10
|
+
class WhatsAppMessageSender extends phone_message_1.PhoneMessage {
|
|
11
11
|
constructor() {
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.getVariables = async () => {
|
|
@@ -31,7 +31,7 @@ class WhatsAppMessageSender extends message_sender_1.MessageSender {
|
|
|
31
31
|
return JSON.stringify(mapping);
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
this.logError(`Failed to parse
|
|
34
|
+
this.logError(`Failed to parse template with content variables - ${this.settings.spaceId} - [${error}]`);
|
|
35
35
|
throw new actions_core_1.IntegrationError(`Unable to parse templating in content variables`, `Content variables templating parse failure`, 400);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
@@ -48,7 +48,7 @@ class WhatsAppMessageSender extends message_sender_1.MessageSender {
|
|
|
48
48
|
}
|
|
49
49
|
catch (error) {
|
|
50
50
|
this.tags.push('type:invalid_phone_e164');
|
|
51
|
-
this.logError(`
|
|
51
|
+
this.logError(`invalid phone number - ${this.settings.spaceId} - [${error}]`);
|
|
52
52
|
this.statsClient?.incr('actions-personas-messaging-twilio.error', 1, this.tags);
|
|
53
53
|
throw new actions_core_1.IntegrationError('The string supplied did not seem to be a phone number. Phone number must be able to be formatted to e164 for whatsapp.', `INVALID_PHONE`, 400);
|
|
54
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whatsapp-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.ts"],"names":[],"mappings":";;;AACA,uCAA6C;AAE7C,wDAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"whatsapp-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.ts"],"names":[],"mappings":";;;AACA,uCAA6C;AAE7C,wDAAwD;AACxD,iEAA0E;AAC1E,0DAAqD;AAErD,MAAM,SAAS,GAAG,uCAAe,CAAC,WAAW,EAAE,CAAA;AAC/C,MAAM,MAAM,GAAG,IAAI,iBAAQ,EAAE,CAAA;AAE7B,MAAa,qBAAsB,SAAQ,4BAAqB;IAAhE;;QA2CU,iBAAY,GAAG,KAAK,IAA4B,EAAE;YACxD,IAAI;gBAIF,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB;oBAChE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,IAAI,CAAA;gBAC9D,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gB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BAAyB,CAAC,CAAA;YACzC,IAAI,CAAC,QAAQ,CAAC,0BAA0B,IAAI,CAAC,QAAQ,CAAC,OAAO,OAAO,KAAK,GAAG,CAAC,CAAA;YAC7E,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,yCAAyC,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;YAC/E,MAAM,IAAI,+BAAgB,CACxB,wHAAwH,EACxH,eAAe,EACf,GAAG,CACJ,CAAA;SACF;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC5B,IAAI,CAAC,QAAQ,CAAC,mDAAmD,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;YACzF,MAAM,IAAI,+BAAgB,CAAC,gDAAgD,EAAE,qBAAqB,EAAE,GAAG,CAAC,CAAA;SACzG;QAED,MAAM,MAAM,GAA2B;YACrC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;YACnC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,EAAE,EAAE,WAAW;SAChB,CAAA;QACD,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAA;QAElD,IAAI,gBAAgB;YAAE,MAAM,CAAC,kBAAkB,CAAC,GAAG,gBAAgB,CAAA;QAEnE,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;CAmCF;AA5ED,sDA4EC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { RequestOptions } from '@segment/actions-core';
|
|
2
1
|
import type { Settings } from '../generated-types';
|
|
3
2
|
import type { Payload as SmsPayload } from '../sendSms/generated-types';
|
|
4
3
|
import type { Payload as WhatsappPayload } from '../sendWhatsApp/generated-types';
|
|
4
|
+
import { RequestOptions } from '@segment/actions-core';
|
|
5
5
|
import { Logger, StatsClient, StatsContext } from '@segment/actions-core/src/destination-kit';
|
|
6
6
|
import { ExecuteInput } from '@segment/actions-core';
|
|
7
|
+
import { ContentTemplateTypes, Profile } from './types';
|
|
7
8
|
export declare type RequestFn = (url: string, options?: RequestOptions) => Promise<Response>;
|
|
8
9
|
export declare abstract class MessageSender<MessagePayload extends SmsPayload | WhatsappPayload> {
|
|
9
10
|
readonly request: RequestFn;
|
|
@@ -14,22 +15,23 @@ export declare abstract class MessageSender<MessagePayload extends SmsPayload |
|
|
|
14
15
|
readonly logger: Logger | undefined;
|
|
15
16
|
readonly executeInput: ExecuteInput<Settings, MessagePayload>;
|
|
16
17
|
readonly logDetails: Record<string, unknown>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
static readonly nonSendableStatuses: string[];
|
|
19
|
+
static readonly sendableStatuses: string[];
|
|
20
|
+
protected readonly supportedTemplateTypes: string[];
|
|
20
21
|
constructor(request: RequestFn, payload: MessagePayload, settings: Settings, statsClient: StatsClient | undefined, tags: StatsContext['tags'], logger: Logger | undefined, executeInput: ExecuteInput<Settings, MessagePayload>, logDetails?: Record<string, unknown>);
|
|
21
|
-
abstract getBody(phone: string): Promise<URLSearchParams>;
|
|
22
22
|
abstract getChannelType(): string;
|
|
23
|
-
|
|
23
|
+
abstract doSend(): Promise<Response | Response[] | object[] | undefined>;
|
|
24
|
+
send(): Promise<Response | object[] | Response[] | undefined>;
|
|
25
|
+
parseContent<R extends Record<string, string | string[] | undefined>>(content: R, profile: Profile): Promise<R>;
|
|
24
26
|
redactPii(pii: string | undefined): string | undefined;
|
|
25
27
|
logInfo(...msgs: string[]): void;
|
|
26
28
|
logError(error?: any, ...msgs: string[]): void;
|
|
27
29
|
private static isPromise;
|
|
28
30
|
logWrap<R = void>(messages: string[], fn: () => R): R;
|
|
29
31
|
initLogDetails(): void;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
getContentTemplateTypes(): Promise<ContentTemplateTypes>;
|
|
33
|
+
private extractTemplateTypes;
|
|
34
|
+
getWebhookUrlWithParams(externalIdType?: string, externalIdValue?: string, defaultConnectionOverrides?: string): string | null;
|
|
35
|
+
logTwilioError(error: unknown, apiName?: string): unknown;
|
|
36
|
+
throwTwilioError(error: unknown, apiName?: string): void;
|
|
35
37
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageSender = void 0;
|
|
4
|
+
const liquidjs_1 = require("liquidjs");
|
|
4
5
|
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
-
|
|
6
|
-
(function (SendabilityStatus) {
|
|
7
|
-
SendabilityStatus["NoSenderPhone"] = "no_sender_phone";
|
|
8
|
-
SendabilityStatus["ShouldSend"] = "should_send";
|
|
9
|
-
SendabilityStatus["DoNotSend"] = "do_not_send";
|
|
10
|
-
SendabilityStatus["SendDisabled"] = "send_disabled";
|
|
11
|
-
SendabilityStatus["InvalidSubscriptionStatus"] = "invalid_subscription_status";
|
|
12
|
-
})(SendabilityStatus || (SendabilityStatus = {}));
|
|
6
|
+
const Liquid = new liquidjs_1.Liquid();
|
|
13
7
|
class MessageSender {
|
|
14
8
|
constructor(request, payload, settings, statsClient, tags, logger, executeInput, logDetails = {}) {
|
|
15
9
|
this.request = request;
|
|
@@ -20,31 +14,36 @@ class MessageSender {
|
|
|
20
14
|
this.logger = logger;
|
|
21
15
|
this.executeInput = executeInput;
|
|
22
16
|
this.logDetails = logDetails;
|
|
23
|
-
this.EXTERNAL_ID_KEY = 'phone';
|
|
24
|
-
this.DEFAULT_HOSTNAME = 'api.twilio.com';
|
|
25
|
-
this.DEFAULT_CONNECTION_OVERRIDES = 'rp=all&rc=5';
|
|
26
|
-
this.getWebhookUrlWithParams = (phone) => {
|
|
27
|
-
const webhookUrl = this.settings.webhookUrl;
|
|
28
|
-
const connectionOverrides = this.settings.connectionOverrides;
|
|
29
|
-
const customArgs = {
|
|
30
|
-
...this.payload.customArgs,
|
|
31
|
-
space_id: this.settings.spaceId,
|
|
32
|
-
__segment_internal_external_id_key__: this.EXTERNAL_ID_KEY,
|
|
33
|
-
__segment_internal_external_id_value__: phone
|
|
34
|
-
};
|
|
35
|
-
if (webhookUrl && customArgs) {
|
|
36
|
-
const webhookUrlWithParams = new URL(webhookUrl);
|
|
37
|
-
for (const key of Object.keys(customArgs)) {
|
|
38
|
-
webhookUrlWithParams.searchParams.append(key, String(customArgs[key]));
|
|
39
|
-
}
|
|
40
|
-
webhookUrlWithParams.hash = connectionOverrides || this.DEFAULT_CONNECTION_OVERRIDES;
|
|
41
|
-
return webhookUrlWithParams.toString();
|
|
42
|
-
}
|
|
43
|
-
return null;
|
|
44
|
-
};
|
|
45
17
|
}
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
async send() {
|
|
19
|
+
this.initLogDetails();
|
|
20
|
+
this.tags.push(`channel:${this.getChannelType()}`);
|
|
21
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.initialize', 1, this.tags);
|
|
22
|
+
return this.logWrap([`Destination Action`], this.doSend.bind(this));
|
|
23
|
+
}
|
|
24
|
+
async parseContent(content, profile) {
|
|
25
|
+
try {
|
|
26
|
+
const parsedEntries = await Promise.all(Object.entries(content).map(async ([key, val]) => {
|
|
27
|
+
if (val == null) {
|
|
28
|
+
return [key, val];
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(val)) {
|
|
31
|
+
val = await Promise.all(val.map((item) => Liquid.parseAndRender(item, { profile })));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
val = await Liquid.parseAndRender(val, { profile });
|
|
35
|
+
}
|
|
36
|
+
return [key, val];
|
|
37
|
+
}));
|
|
38
|
+
return Object.fromEntries(parsedEntries);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
this.logDetails['error'] = error instanceof Error ? error.message : error?.toString();
|
|
42
|
+
this.logError(`unable to parse templating - ${this.settings.spaceId}`);
|
|
43
|
+
this.tags.push('reason:invalid_liquid');
|
|
44
|
+
this.statsClient?.incr('actions-personas-messaging-twilio.error', 1, this.tags);
|
|
45
|
+
throw new actions_core_1.PayloadValidationError(`Unable to parse templating in ${this.getChannelType()}`);
|
|
46
|
+
}
|
|
48
47
|
}
|
|
49
48
|
redactPii(pii) {
|
|
50
49
|
if (!pii) {
|
|
@@ -57,48 +56,48 @@ class MessageSender {
|
|
|
57
56
|
}
|
|
58
57
|
logInfo(...msgs) {
|
|
59
58
|
const [firstMsg, ...rest] = msgs;
|
|
60
|
-
this.logger?.info(`TE Messaging: ${firstMsg}`, ...rest, JSON.stringify(this.logDetails));
|
|
59
|
+
this.logger?.info(`TE Messaging: ${this.getChannelType().toUpperCase()} ${firstMsg}`, ...rest, JSON.stringify(this.logDetails));
|
|
61
60
|
}
|
|
62
61
|
logError(error, ...msgs) {
|
|
63
62
|
const [firstMsg, ...rest] = msgs;
|
|
64
63
|
if (typeof error === 'string') {
|
|
65
|
-
this.logger?.error(`TE Messaging: ${error}`, ...msgs, JSON.stringify(this.logDetails));
|
|
64
|
+
this.logger?.error(`TE Messaging: ${this.getChannelType().toUpperCase()} ${error}`, ...msgs, JSON.stringify(this.logDetails));
|
|
66
65
|
}
|
|
67
66
|
else {
|
|
68
|
-
this.logger?.error(`TE Messaging: ${firstMsg}`, ...rest, error instanceof Error ? error.message : error?.toString(), JSON.stringify(this.logDetails));
|
|
67
|
+
this.logger?.error(`TE Messaging: ${this.getChannelType().toUpperCase()} ${firstMsg}`, ...rest, error instanceof Error ? error.message : error?.toString(), JSON.stringify(this.logDetails));
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
static isPromise(obj) {
|
|
72
71
|
return obj instanceof Object && 'then' in obj && typeof obj.then === 'function';
|
|
73
72
|
}
|
|
74
73
|
logWrap(messages, fn) {
|
|
75
|
-
this.logInfo(
|
|
74
|
+
this.logInfo('Starting: ', ...messages);
|
|
76
75
|
try {
|
|
77
76
|
const res = fn();
|
|
78
77
|
if (MessageSender.isPromise(res)) {
|
|
79
78
|
return (async () => {
|
|
80
79
|
try {
|
|
81
80
|
const promisedRes = await res;
|
|
82
|
-
this.logInfo(
|
|
81
|
+
this.logInfo('Success: ', ...messages);
|
|
83
82
|
return promisedRes;
|
|
84
83
|
}
|
|
85
84
|
catch (error) {
|
|
86
|
-
this.logError(error,
|
|
85
|
+
this.logError(error, 'Failed: ', ...messages);
|
|
87
86
|
throw error;
|
|
88
87
|
}
|
|
89
88
|
})();
|
|
90
89
|
}
|
|
91
|
-
this.logInfo(
|
|
90
|
+
this.logInfo('Success: ', ...messages);
|
|
92
91
|
return res;
|
|
93
92
|
}
|
|
94
93
|
catch (error) {
|
|
95
|
-
this.logError(error,
|
|
94
|
+
this.logError(error, 'Failed: ', ...messages);
|
|
96
95
|
throw error;
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
initLogDetails() {
|
|
100
99
|
Object.assign(this.logDetails, {
|
|
101
|
-
externalIds: this.payload.externalIds?.map(eid => ({ ...eid, id: this.redactPii(eid.id) })),
|
|
100
|
+
externalIds: this.payload.externalIds?.map((eid) => ({ ...eid, id: this.redactPii(eid.id) })),
|
|
102
101
|
shouldSend: this.payload.send,
|
|
103
102
|
contentSid: this.payload.contentSid,
|
|
104
103
|
sourceId: this.settings.sourceId,
|
|
@@ -106,104 +105,101 @@ class MessageSender {
|
|
|
106
105
|
twilioApiKeySID: this.settings.twilioApiKeySID,
|
|
107
106
|
region: this.settings.region,
|
|
108
107
|
messageId: this.executeInput['rawData']?.messageId,
|
|
109
|
-
channelType: this.getChannelType()
|
|
108
|
+
channelType: this.getChannelType()
|
|
110
109
|
});
|
|
111
110
|
if ('userId' in this.payload)
|
|
112
111
|
this.logDetails.userId = this.payload.userId;
|
|
113
112
|
}
|
|
114
|
-
async
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.logInfo(`Not sending message, because sendabilityStatus: ${sendabilityStatus}, phone: ${this.redactPii(phone)}`);
|
|
120
|
-
return;
|
|
113
|
+
async getContentTemplateTypes() {
|
|
114
|
+
let template;
|
|
115
|
+
try {
|
|
116
|
+
if (!this.payload.contentSid) {
|
|
117
|
+
throw new actions_core_1.PayloadValidationError('Content SID not in payload');
|
|
121
118
|
}
|
|
122
|
-
this.logInfo("Getting content Body");
|
|
123
|
-
const body = await this.getBody(phone);
|
|
124
|
-
const webhookUrlWithParams = this.getWebhookUrlWithParams(phone);
|
|
125
|
-
if (webhookUrlWithParams)
|
|
126
|
-
body.append('StatusCallback', webhookUrlWithParams);
|
|
127
|
-
const twilioHostname = this.settings.twilioHostname ?? this.DEFAULT_HOSTNAME;
|
|
128
119
|
const twilioToken = Buffer.from(`${this.settings.twilioApiKeySID}:${this.settings.twilioApiKeySecret}`).toString('base64');
|
|
129
|
-
this.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
method: 'POST',
|
|
134
|
-
headers: {
|
|
135
|
-
authorization: `Basic ${twilioToken}`
|
|
136
|
-
},
|
|
137
|
-
body
|
|
138
|
-
});
|
|
139
|
-
this.tags.push(`twilio_status_code:${response.status}`);
|
|
140
|
-
this.statsClient?.incr('actions_personas_messaging_twilio.response', 1, this.tags);
|
|
141
|
-
if (this.payload.eventOccurredTS != undefined) {
|
|
142
|
-
this.statsClient?.histogram('actions-personas-messaging-twilio.eventDeliveryTS', Date.now() - new Date(this.payload.eventOccurredTS).getTime(), this.tags);
|
|
143
|
-
}
|
|
144
|
-
this.logDetails['twilio-request-id'] = response.headers?.get('twilio-request-id');
|
|
145
|
-
this.logInfo("Message sent successfully");
|
|
146
|
-
return response;
|
|
147
|
-
}
|
|
148
|
-
catch (errorOrig) {
|
|
149
|
-
let errorToRethrow = errorOrig;
|
|
150
|
-
if (errorOrig instanceof Object) {
|
|
151
|
-
const twilioApiError = errorOrig;
|
|
152
|
-
this.logDetails['twilioApiError_response_data'] = twilioApiError.response?.data;
|
|
153
|
-
this.logDetails['twilio-request-id'] = twilioApiError.response?.headers?.get('twilio-request-id');
|
|
154
|
-
this.logDetails['error'] = twilioApiError.response;
|
|
155
|
-
this.logError(`Twilio Programmable API error - ${this.settings.spaceId}`);
|
|
156
|
-
const statusCode = twilioApiError.status || twilioApiError.response?.data?.status;
|
|
157
|
-
this.tags.push(`twilio_status_code:${statusCode}`);
|
|
158
|
-
this.statsClient?.incr('actions_personas_messaging_twilio.response', 1, this.tags);
|
|
159
|
-
if (!twilioApiError.status) {
|
|
160
|
-
errorToRethrow = new actions_core_1.IntegrationError(twilioApiError.response?.data?.message || twilioApiError.message, (twilioApiError.response?.data?.code || statusCode)?.toString() || "Twilio Api Request Error", statusCode);
|
|
161
|
-
}
|
|
162
|
-
const errorCode = twilioApiError.response?.data?.code;
|
|
163
|
-
if (errorCode === 63018 || statusCode === 429) {
|
|
164
|
-
this.statsClient?.incr('actions_personas_messaging_twilio.rate_limited', 1, this.tags);
|
|
165
|
-
}
|
|
120
|
+
const response = await this.request(`https://content.twilio.com/v1/Content/${this.payload.contentSid}`, {
|
|
121
|
+
method: 'GET',
|
|
122
|
+
headers: {
|
|
123
|
+
authorization: `Basic ${twilioToken}`
|
|
166
124
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
getSendabilityPayload() {
|
|
172
|
-
if (!this.payload.send) {
|
|
173
|
-
this.statsClient?.incr('actions-personas-messaging-twilio.send-disabled', 1, this.tags);
|
|
174
|
-
return { sendabilityStatus: SendabilityStatus.SendDisabled, phone: undefined };
|
|
175
|
-
}
|
|
176
|
-
const validExtIds = this.payload.externalIds?.filter(extId => this.isValidExternalId(extId));
|
|
177
|
-
const firstSubscribedExtId = validExtIds?.find(extId => extId.subscriptionStatus
|
|
178
|
-
&& MessageSender.sendableStatuses.includes(extId.subscriptionStatus?.toString()?.toLowerCase()));
|
|
179
|
-
const invalidStatuses = validExtIds?.filter(extId => {
|
|
180
|
-
const subStatus = extId.subscriptionStatus?.toString()?.toLowerCase();
|
|
181
|
-
if (!subStatus)
|
|
182
|
-
return false;
|
|
183
|
-
return !(MessageSender.nonSendableStatuses.includes(subStatus) || MessageSender.sendableStatuses.includes(subStatus));
|
|
184
|
-
});
|
|
185
|
-
const hasInvalidStatuses = invalidStatuses && invalidStatuses.length > 0;
|
|
186
|
-
if (hasInvalidStatuses) {
|
|
187
|
-
this.logInfo(`Invalid subscription statuses found in externalIds: ${invalidStatuses.map(extId => extId.subscriptionStatus).join(', ')}`);
|
|
125
|
+
});
|
|
126
|
+
template = (await response.json());
|
|
188
127
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.
|
|
193
|
-
|
|
128
|
+
catch (error) {
|
|
129
|
+
this.tags.push('reason:get_content_template');
|
|
130
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.error', 1, this.tags);
|
|
131
|
+
this.logError(`failed request to fetch content template from Twilio Content API - ${this.settings.spaceId} - ${error}, ${JSON.stringify(error)})}`);
|
|
132
|
+
throw new actions_core_1.IntegrationError('Unable to fetch content template', 'Twilio Content API request failure', 500);
|
|
194
133
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
134
|
+
return this.extractTemplateTypes(template);
|
|
135
|
+
}
|
|
136
|
+
extractTemplateTypes(template) {
|
|
137
|
+
if (!template.types) {
|
|
138
|
+
this.logError(`template from Twilio Content API does not contain a template type - ${this.settings.spaceId} - [${JSON.stringify(template)}]`);
|
|
139
|
+
this.tags.push('reason:invalid_template_type');
|
|
140
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.error', 1);
|
|
141
|
+
throw new actions_core_1.IntegrationError('Template from Twilio Content API does not contain any template types', `NO_CONTENT_TYPES`, 400);
|
|
198
142
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
143
|
+
const type = Object.keys(template.types)[0];
|
|
144
|
+
if (this.supportedTemplateTypes.includes(type)) {
|
|
145
|
+
return { body: template.types[type].body, media: template.types[type].media };
|
|
202
146
|
}
|
|
203
147
|
else {
|
|
204
|
-
|
|
148
|
+
this.logError(`unsupported content template type '${type}' - ${this.settings.spaceId}`);
|
|
149
|
+
this.tags.push('reason:invalid_template_type');
|
|
150
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.error', 1);
|
|
151
|
+
throw new actions_core_1.IntegrationError(`Sending templates with '${type}' content type is not supported by ${this.getChannelType()}`, 'UNSUPPORTED_CONTENT_TYPE', 400);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
getWebhookUrlWithParams(externalIdType, externalIdValue, defaultConnectionOverrides = 'rp=all&rc=5') {
|
|
155
|
+
const webhookUrl = this.settings.webhookUrl;
|
|
156
|
+
const connectionOverrides = this.settings.connectionOverrides;
|
|
157
|
+
const customArgs = {
|
|
158
|
+
...this.payload.customArgs,
|
|
159
|
+
space_id: this.settings.spaceId,
|
|
160
|
+
__segment_internal_external_id_key__: externalIdType,
|
|
161
|
+
__segment_internal_external_id_value__: externalIdValue
|
|
162
|
+
};
|
|
163
|
+
if (webhookUrl && customArgs) {
|
|
164
|
+
try {
|
|
165
|
+
const webhookUrlWithParams = new URL(webhookUrl);
|
|
166
|
+
for (const key of Object.keys(customArgs)) {
|
|
167
|
+
webhookUrlWithParams.searchParams.append(key, String(customArgs[key]));
|
|
168
|
+
}
|
|
169
|
+
webhookUrlWithParams.hash = connectionOverrides || defaultConnectionOverrides;
|
|
170
|
+
return webhookUrlWithParams.toString();
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
this.logDetails['webhook-custom-args'] = this.payload.customArgs;
|
|
174
|
+
this.logError(`invalid webhook url - ${this.settings.spaceId}`);
|
|
175
|
+
throw new actions_core_1.PayloadValidationError('Invalid webhook url arguments');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
logTwilioError(error, apiName = 'Twilio Programmable API') {
|
|
181
|
+
let errorToRethrow = error;
|
|
182
|
+
if (error instanceof Object) {
|
|
183
|
+
const twilioApiError = error;
|
|
184
|
+
this.logDetails['twilioApiError_response_data'] = twilioApiError.response?.data;
|
|
185
|
+
this.logDetails['twilio-request-id'] = twilioApiError.response?.headers?.get('twilio-request-id');
|
|
186
|
+
this.logDetails['error'] = twilioApiError.response;
|
|
187
|
+
this.logError(`${apiName} error - ${this.settings.spaceId}`);
|
|
188
|
+
const statusCode = twilioApiError.status || twilioApiError.response?.data?.status;
|
|
189
|
+
this.tags.push(`twilio_status_code:${statusCode}`);
|
|
190
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.response', 1, this.tags);
|
|
191
|
+
if (!twilioApiError.status) {
|
|
192
|
+
errorToRethrow = new actions_core_1.IntegrationError(twilioApiError.response?.data?.message || twilioApiError.message, (twilioApiError.response?.data?.code || statusCode)?.toString() || 'Twilio Api Request Error', statusCode);
|
|
193
|
+
}
|
|
194
|
+
const errorCode = twilioApiError.response?.data?.code;
|
|
195
|
+
if (errorCode === 63018 || statusCode === 429) {
|
|
196
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.rate_limited', 1, this.tags);
|
|
197
|
+
}
|
|
205
198
|
}
|
|
206
|
-
return
|
|
199
|
+
return errorToRethrow;
|
|
200
|
+
}
|
|
201
|
+
throwTwilioError(error, apiName = 'Twilio Programmable API') {
|
|
202
|
+
throw this.logTwilioError(error, apiName);
|
|
207
203
|
}
|
|
208
204
|
}
|
|
209
205
|
exports.MessageSender = MessageSender;
|