@segment/action-destinations 3.170.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/adobe-target/adobeTarget_operations.js +3 -3
- package/dist/destinations/adobe-target/adobeTarget_operations.js.map +1 -1
- 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-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/index.js +3 -0
- package/dist/destinations/index.js.map +1 -1
- 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
|
@@ -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,IAAI,CAAC,uBAAuB,EAAE,CAAA;YACjD,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AAO,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,gBAAgB,IAAI,CAAC,IAAI,CAAC,OAAO,C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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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/utils/message-sender.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"message-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/utils/message-sender.ts"],"names":[],"mappings":";;;AACA,uCAA6C;AAI7C,wDAAgG;AAKhG,MAAM,MAAM,GAAG,IAAI,iBAAQ,EAAE,CAAA;AAI7B,MAAsB,aAAa;IAKjC,YACW,OAAkB,EAClB,OAAuB,EACvB,QAAkB,EAClB,WAAoC,EACpC,IAA0B,EAC1B,MAA0B,EAC1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IACvB,CAAC;IAED,gBAAgB,CAAC,KAAc,EAAE,OAAO,GAAG,yBAAyB;QAClE,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;;AAjSH,sCAkSC;AAjSiB,iCAAmB,GAAG,CAAC,cAAc,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;AACrE,8BAAgB,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MessageSender } from './message-sender';
|
|
2
|
+
import type { Payload as SmsPayload } from '../sendSms/generated-types';
|
|
3
|
+
import type { Payload as WhatsappPayload } from '../sendWhatsApp/generated-types';
|
|
4
|
+
export declare abstract class PhoneMessage<Payload extends SmsPayload | WhatsappPayload> extends MessageSender<Payload> {
|
|
5
|
+
private readonly EXTERNAL_ID_KEY;
|
|
6
|
+
private readonly DEFAULT_HOSTNAME;
|
|
7
|
+
private readonly DEFAULT_CONNECTION_OVERRIDES;
|
|
8
|
+
abstract getBody(phone: string): Promise<URLSearchParams>;
|
|
9
|
+
doSend(): Promise<Response | undefined>;
|
|
10
|
+
isValidExternalId(externalId: NonNullable<Payload['externalIds']>[number]): boolean;
|
|
11
|
+
private getSendabilityPayload;
|
|
12
|
+
}
|