@segment/action-destinations 3.261.0 → 3.262.0-staging-dbf2c12ff

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.
Files changed (61) hide show
  1. package/dist/destinations/amazon-ads/utils.d.ts +25 -0
  2. package/dist/destinations/amazon-ads/utils.js +8 -0
  3. package/dist/destinations/amazon-ads/utils.js.map +1 -0
  4. package/dist/destinations/customerio/utils.d.ts +1 -1
  5. package/dist/destinations/engage/utils/track.d.ts +17 -17
  6. package/dist/destinations/engage-messaging-sendgrid/sendEmail/generated-types.d.ts +36 -0
  7. package/dist/destinations/engage-messaging-sendgrid/sendEmail/generated-types.js +3 -0
  8. package/dist/destinations/engage-messaging-sendgrid/sendEmail/generated-types.js.map +1 -0
  9. package/dist/destinations/engage-messaging-sendgrid/sendEmail/index.d.ts +5 -0
  10. package/dist/destinations/engage-messaging-sendgrid/sendEmail/index.js +452 -0
  11. package/dist/destinations/engage-messaging-sendgrid/sendEmail/index.js.map +1 -0
  12. package/dist/destinations/engage-messaging-twilio/sendSms/generated-types.d.ts +22 -0
  13. package/dist/destinations/engage-messaging-twilio/sendSms/generated-types.js +3 -0
  14. package/dist/destinations/engage-messaging-twilio/sendSms/generated-types.js.map +1 -0
  15. package/dist/destinations/engage-messaging-twilio/sendSms/index.d.ts +5 -0
  16. package/dist/destinations/engage-messaging-twilio/sendSms/index.js +131 -0
  17. package/dist/destinations/engage-messaging-twilio/sendSms/index.js.map +1 -0
  18. package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.d.ts +23 -0
  19. package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.js +131 -0
  20. package/dist/destinations/engage-messaging-twilio/sendSms/sms-sender.js.map +1 -0
  21. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/generated-types.d.ts +24 -0
  22. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/generated-types.js +3 -0
  23. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/generated-types.js.map +1 -0
  24. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/index.d.ts +5 -0
  25. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/index.js +133 -0
  26. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/index.js.map +1 -0
  27. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.d.ts +21 -0
  28. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.js +75 -0
  29. package/dist/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.js.map +1 -0
  30. package/dist/destinations/engage-messaging-twilio/utils/message-sender.d.ts +24 -0
  31. package/dist/destinations/engage-messaging-twilio/utils/message-sender.js +111 -0
  32. package/dist/destinations/engage-messaging-twilio/utils/message-sender.js.map +1 -0
  33. package/dist/destinations/hubspot/helperFunctions.d.ts +7 -0
  34. package/dist/destinations/hubspot/helperFunctions.js +27 -0
  35. package/dist/destinations/hubspot/helperFunctions.js.map +1 -0
  36. package/dist/destinations/inleads-ai/index.js +5 -4
  37. package/dist/destinations/inleads-ai/index.js.map +1 -1
  38. package/dist/destinations/koala/identify/index.js +6 -1
  39. package/dist/destinations/koala/identify/index.js.map +1 -1
  40. package/dist/destinations/mixpanel/utils.d.ts +13 -0
  41. package/dist/destinations/mixpanel/utils.js +117 -0
  42. package/dist/destinations/mixpanel/utils.js.map +1 -0
  43. package/dist/destinations/snap-conversions-api/snap-capi-properties.d.ts +30 -0
  44. package/dist/destinations/snap-conversions-api/snap-capi-properties.js +316 -0
  45. package/dist/destinations/snap-conversions-api/snap-capi-properties.js.map +1 -0
  46. package/dist/destinations/tiktok-conversions/reportWebEvent/formatter.d.ts +3 -0
  47. package/dist/destinations/tiktok-conversions/reportWebEvent/formatter.js +34 -0
  48. package/dist/destinations/tiktok-conversions/reportWebEvent/formatter.js.map +1 -0
  49. package/dist/destinations/vernst-test/generated-types.d.ts +2 -0
  50. package/dist/destinations/vernst-test/generated-types.js +3 -0
  51. package/dist/destinations/vernst-test/generated-types.js.map +1 -0
  52. package/dist/destinations/vernst-test/index.d.ts +4 -0
  53. package/dist/destinations/vernst-test/index.js +20 -0
  54. package/dist/destinations/vernst-test/index.js.map +1 -0
  55. package/dist/destinations/vernst-test/pingWebhook/generated-types.d.ts +3 -0
  56. package/dist/destinations/vernst-test/pingWebhook/generated-types.js +3 -0
  57. package/dist/destinations/vernst-test/pingWebhook/generated-types.js.map +1 -0
  58. package/dist/destinations/vernst-test/pingWebhook/index.d.ts +5 -0
  59. package/dist/destinations/vernst-test/pingWebhook/index.js +21 -0
  60. package/dist/destinations/vernst-test/pingWebhook/index.js.map +1 -0
  61. package/package.json +3 -3
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendSms/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { ActionDefinition } from '@segment/actions-core';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ declare const action: ActionDefinition<Settings, Payload>;
5
+ export default action;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const sms_sender_1 = require("./sms-sender");
4
+ const action = {
5
+ title: 'Send SMS',
6
+ description: 'Send SMS using Twilio',
7
+ defaultSubscription: 'type = "track" and event = "Audience Entered"',
8
+ fields: {
9
+ userId: {
10
+ label: 'User ID',
11
+ description: 'User ID in Segment',
12
+ type: 'string',
13
+ default: { '@path': '$.userId' }
14
+ },
15
+ toNumber: {
16
+ label: 'Test Number',
17
+ description: 'Number to send SMS to when testing',
18
+ type: 'string'
19
+ },
20
+ from: {
21
+ label: 'From',
22
+ description: 'The Twilio Phone Number, Short Code, or Messaging Service to send SMS from.',
23
+ type: 'string',
24
+ required: true
25
+ },
26
+ body: {
27
+ label: 'Message',
28
+ description: 'Message to send',
29
+ type: 'text',
30
+ required: false
31
+ },
32
+ contentSid: {
33
+ label: 'SMS content template SID',
34
+ description: 'Content template SID for Twilio Content API',
35
+ type: 'string',
36
+ required: false
37
+ },
38
+ customArgs: {
39
+ label: 'Custom Arguments',
40
+ description: 'Additional custom arguments that will be opaquely sent back on webhook events',
41
+ type: 'object',
42
+ required: false
43
+ },
44
+ connectionOverrides: {
45
+ label: 'Connection Overrides',
46
+ description: 'Connection overrides are configuration supported by twilio webhook services. Must be passed as fragments on the callback url',
47
+ type: 'string',
48
+ required: false
49
+ },
50
+ send: {
51
+ label: 'Send Message',
52
+ description: 'Whether or not the message should actually get sent.',
53
+ type: 'boolean',
54
+ required: false,
55
+ default: false
56
+ },
57
+ traitEnrichment: {
58
+ label: 'Trait Enrich',
59
+ description: 'Whether or not trait enrich from event (i.e without profile api call)',
60
+ type: 'boolean',
61
+ required: false,
62
+ default: true
63
+ },
64
+ externalIds: {
65
+ label: 'External IDs',
66
+ description: 'An array of user profile identity information.',
67
+ type: 'object',
68
+ multiple: true,
69
+ properties: {
70
+ id: {
71
+ label: 'ID',
72
+ description: 'A unique identifier for the collection.',
73
+ type: 'string'
74
+ },
75
+ type: {
76
+ label: 'type',
77
+ description: 'The external ID contact type.',
78
+ type: 'string'
79
+ },
80
+ subscriptionStatus: {
81
+ label: 'ID',
82
+ description: 'The subscription status for the identity.',
83
+ type: 'string'
84
+ }
85
+ },
86
+ default: {
87
+ '@arrayPath': [
88
+ '$.external_ids',
89
+ {
90
+ id: {
91
+ '@path': '$.id'
92
+ },
93
+ type: {
94
+ '@path': '$.type'
95
+ },
96
+ subscriptionStatus: {
97
+ '@path': '$.isSubscribed'
98
+ }
99
+ }
100
+ ]
101
+ }
102
+ },
103
+ traits: {
104
+ label: 'Traits',
105
+ description: "A user profile's traits",
106
+ type: 'object',
107
+ required: false,
108
+ default: { '@path': '$.properties' }
109
+ },
110
+ eventOccurredTS: {
111
+ label: 'Event Timestamp',
112
+ description: 'Time of when the actual event happened.',
113
+ type: 'string',
114
+ required: false,
115
+ default: {
116
+ '@path': '$.timestamp'
117
+ }
118
+ }
119
+ },
120
+ perform: async (request, { settings, payload, statsContext, logger }) => {
121
+ const statsClient = statsContext?.statsClient;
122
+ const tags = statsContext?.tags || [];
123
+ if (!settings.region) {
124
+ settings.region = 'us-west-1';
125
+ }
126
+ tags.push(`space_id:${settings.spaceId}`, `projectid:${settings.sourceId}`, `region:${settings.region}`);
127
+ return new sms_sender_1.SmsMessageSender(request, payload, settings, statsClient, tags, logger).send();
128
+ }
129
+ };
130
+ exports.default = action;
131
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendSms/index.ts"],"names":[],"mappings":";;AAIA,6CAA+C;AAE/C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,UAAU;IACjB,WAAW,EAAE,uBAAuB;IACpC,mBAAmB,EAAE,+CAA+C;IACpE,MAAM,EAAE;QACN,MAAM,EAAE;YACN,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,oBAAoB;YACjC,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;SACjC;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,aAAa;YACpB,WAAW,EAAE,oCAAoC;YACjD,IAAI,EAAE,QAAQ;SACf;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,MAAM;YACb,WAAW,EAAE,6EAA6E;YAC1F,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,KAAK;SAChB;QACD,UAAU,EAAE;YACV,KAAK,EAAE,0BAA0B;YACjC,WAAW,EAAE,6CAA6C;YAC1D,IAAI,EAA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yBAC1B;qBACF;iBACF;aACF;SACF;QACD,MAAM,EAAE;YACN,KAAK,EAAE,QAAQ;YACf,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE;SACrC;QACD,eAAe,EAAE;YACf,KAAK,EAAE,iBAAiB;YACxB,WAAW,EAAE,yCAAyC;YACtD,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE;gBACP,OAAO,EAAE,aAAa;aACvB;SACF;KACF;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE;QACtE,MAAM,WAAW,GAAG,YAAY,EAAE,WAAW,CAAA;QAC7C,MAAM,IAAI,GAAG,YAAY,EAAE,IAAI,IAAI,EAAE,CAAA;QACrC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YACpB,QAAQ,CAAC,MAAM,GAAG,WAAW,CAAA;SAC9B;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,QAAQ,CAAC,OAAO,EAAE,EAAE,aAAa,QAAQ,CAAC,QAAQ,EAAE,EAAE,UAAU,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;QACxG,OAAO,IAAI,6BAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;IAC3F,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,23 @@
1
+ import type { Settings } from '../generated-types';
2
+ import type { Payload } from './generated-types';
3
+ import { Logger, StatsClient, StatsContext } from '@segment/actions-core/src/destination-kit';
4
+ import { MessageSender, RequestFn } from '../utils/message-sender';
5
+ export declare class SmsMessageSender extends MessageSender<Payload> {
6
+ readonly request: RequestFn;
7
+ readonly payload: Payload;
8
+ readonly settings: Settings;
9
+ readonly statsClient: StatsClient | undefined;
10
+ readonly tags: StatsContext['tags'];
11
+ readonly logger: Logger | undefined;
12
+ constructor(request: RequestFn, payload: Payload, settings: Settings, statsClient: StatsClient | undefined, tags: StatsContext['tags'], logger: Logger | undefined);
13
+ getExternalId: () => {
14
+ id?: string | undefined;
15
+ type?: string | undefined;
16
+ subscriptionStatus?: string | undefined;
17
+ } | undefined;
18
+ getBody: (phone: string) => Promise<URLSearchParams>;
19
+ private getProfileTraits;
20
+ private getContentTemplate;
21
+ private getUnparsedContent;
22
+ private parseContent;
23
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmsMessageSender = void 0;
4
+ const liquidjs_1 = require("liquidjs");
5
+ const actions_core_1 = require("@segment/actions-core");
6
+ const message_sender_1 = require("../utils/message-sender");
7
+ const Liquid = new liquidjs_1.Liquid();
8
+ class SmsMessageSender extends message_sender_1.MessageSender {
9
+ constructor(request, payload, settings, statsClient, tags, logger) {
10
+ super(request, payload, settings, statsClient, tags, logger);
11
+ this.request = request;
12
+ this.payload = payload;
13
+ this.settings = settings;
14
+ this.statsClient = statsClient;
15
+ this.tags = tags;
16
+ this.logger = logger;
17
+ this.getExternalId = () => this.payload.externalIds?.find(({ type }) => type === 'phone');
18
+ this.getBody = async (phone) => {
19
+ if (!this.payload.body && !this.payload.contentSid) {
20
+ this.logger?.error(`TE Messaging: Unable to process SMS, no body provided and no content sid provided - ${this.settings.spaceId}`);
21
+ throw new actions_core_1.PayloadValidationError('Unable to process sms, no body provided and no content sid provided');
22
+ }
23
+ let traits;
24
+ if (this.payload.traitEnrichment) {
25
+ traits = this.payload?.traits ? this.payload?.traits : {};
26
+ }
27
+ else {
28
+ traits = await this.getProfileTraits();
29
+ }
30
+ const profile = {
31
+ user_id: this.payload.userId ?? undefined,
32
+ phone,
33
+ traits
34
+ };
35
+ let parsedBody;
36
+ let parsedMedia = [];
37
+ if (this.payload.contentSid) {
38
+ const data = await this.getContentTemplate();
39
+ const parsed = await this.parseContent(this.getUnparsedContent(data), profile);
40
+ parsedBody = parsed.body;
41
+ parsedMedia = parsed.media;
42
+ }
43
+ else {
44
+ parsedBody = (await this.parseContent({ body: this.payload.body ?? '' }, profile)).body;
45
+ }
46
+ const body = new URLSearchParams({
47
+ Body: parsedBody,
48
+ From: this.payload.from,
49
+ To: phone,
50
+ ShortenUrls: 'true'
51
+ });
52
+ parsedMedia?.forEach((media) => {
53
+ body.append('MediaUrl', media);
54
+ });
55
+ return body;
56
+ };
57
+ this.getProfileTraits = async () => {
58
+ if (!this.payload.userId) {
59
+ this.logger?.error(`TE Messaging: Unable to process SMS, no userId provided and no traits provided - ${this.settings.spaceId}`);
60
+ throw new actions_core_1.IntegrationError('Unable to process sms, no userId provided and no traits provided', 'Invalid parameters', 400);
61
+ }
62
+ try {
63
+ const { region, profileApiEnvironment, spaceId, profileApiAccessToken } = this.settings;
64
+ const domainName = region === 'eu-west-1' ? 'profiles.euw1.segment' : 'profiles.segment';
65
+ const topLevelName = profileApiEnvironment === 'production' ? 'com' : 'build';
66
+ const response = await this.request(`https://${domainName}.${topLevelName}/v1/spaces/${spaceId}/collections/users/profiles/user_id:${encodeURIComponent(this.payload.userId)}/traits?limit=200`, {
67
+ headers: {
68
+ authorization: `Basic ${Buffer.from(profileApiAccessToken + ':').toString('base64')}`,
69
+ 'content-type': 'application/json'
70
+ }
71
+ });
72
+ this.tags.push(`profile_status_code:${response.status}`);
73
+ this.statsClient?.incr('actions-personas-messaging-twilio.profile_invoked', 1, this.tags);
74
+ const body = await response.json();
75
+ return body.traits;
76
+ }
77
+ catch (error) {
78
+ this.statsClient?.incr('actions-personas-messaging-twilio.profile_error', 1, this.tags);
79
+ this.logger?.error(`TE Messaging: SMS profile traits request failure - ${this.settings.spaceId} - [${error}]`);
80
+ throw new actions_core_1.IntegrationError('Unable to get profile traits for SMS message', 'SMS trait fetch failure', 500);
81
+ }
82
+ };
83
+ this.getContentTemplate = async () => {
84
+ const twilioToken = Buffer.from(`${this.settings.twilioApiKeySID}:${this.settings.twilioApiKeySecret}`).toString('base64');
85
+ try {
86
+ const response = await this.request(`https://content.twilio.com/v1/Content/${this.payload.contentSid}`, {
87
+ method: 'GET',
88
+ headers: {
89
+ authorization: `Basic ${twilioToken}`
90
+ }
91
+ });
92
+ const data = await response.json();
93
+ return data;
94
+ }
95
+ catch (error) {
96
+ this.tags.push('reason:get_content_template');
97
+ this.statsClient?.incr('actions-personas-messaging-twilio.error', 1, this.tags);
98
+ this.logger?.error(`TE Messaging: SMS failed request to fetch content template from Twilio Content API - ${this.settings.spaceId} - [${error}]`);
99
+ throw new actions_core_1.IntegrationError('Unable to fetch content template', 'Twilio Content API request failure', 500);
100
+ }
101
+ };
102
+ this.getUnparsedContent = (data) => {
103
+ if (!data.types) {
104
+ this.logger?.error(`TE Messaging: SMS template from Twilio Content API does not contain a template type - ${this.settings.spaceId} - [${JSON.stringify(data)}]`);
105
+ throw new actions_core_1.IntegrationError('Unexpected response from Twilio Content API', `SMS template does not contain a template type`, 500);
106
+ }
107
+ const type = Object.keys(data.types)[0];
108
+ if (type === 'twilio/text' || type === 'twilio/media') {
109
+ return { body: data.types[type].body, media: data.types[type].media };
110
+ }
111
+ else {
112
+ this.logger?.error(`TE Messaging: SMS unsupported content template type '${type}' - ${this.settings.spaceId}`);
113
+ throw new actions_core_1.IntegrationError('Unsupported content type', `Sending templates with '${type}' content type is not supported by SMS`, 400);
114
+ }
115
+ };
116
+ }
117
+ async parseContent(content, profile) {
118
+ try {
119
+ return {
120
+ body: await Liquid.parseAndRender(content.body, { profile }),
121
+ media: await Promise.all(content.media?.map((media) => Liquid.parseAndRender(media, { profile })) || [])
122
+ };
123
+ }
124
+ catch (error) {
125
+ this.logger?.error(`TE Messaging: SMS templating parse failure - ${this.settings.spaceId} - [${error}]`);
126
+ throw new actions_core_1.IntegrationError(`Unable to parse templating in SMS`, `SMS templating parse failure`, 400);
127
+ }
128
+ }
129
+ }
130
+ exports.SmsMessageSender = SmsMessageSender;
131
+ //# sourceMappingURL=sms-sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sms-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendSms/sms-sender.ts"],"names":[],"mappings":";;;AACA,uCAA6C;AAG7C,wDAAgF;AAEhF,4DAAkE;AAElE,MAAM,MAAM,GAAG,IAAI,iBAAQ,EAAE,CAAA;AAiB7B,MAAa,gBAAiB,SAAQ,8BAAsB;IAC1D,YACW,OAAkB,EAClB,OAAgB,EAChB,QAAkB,EAClB,WAAoC,EACpC,IAA0B,EAC1B,MAA0B;QAEnC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;QAPnD,YAAO,GAAP,OAAO,CAAW;QAClB,YAAO,GAAP,OAAO,CAAS;QAChB,aAAQ,GAAR,QAAQ,CAAU;QAClB,gBAAW,GAAX,WAAW,CAAyB;QACpC,SAAI,GAAJ,IAAI,CAAsB;QAC1B,WAAM,GAAN,MAAM,CAAoB;QAKrC,kBAAa,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;QAEpF,YAAO,GAAG,KAAK,EAAE,KAAa,EAAE,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;gBAClD,IAAI,CAAC,MAAM,EAAE,KAAK,CAChB,uFAAuF,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAC/G,CAAA;gBACD,MAAM,IAAI,qCAAsB,CAAC,qEAAqE,CAAC,CAAA;aACxG;YAID,IAAI,MAAM,CAAA;YACV,IAAI,IAAI,CAAC,OAAO,CA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AAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;aACzG,CAAA;SACF;QAAC,OAAO,KAAc,EAAE;YACvB,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,gDAAgD,IAAI,CAAC,QAAQ,CAAC,OAAO,OAAO,KAAK,GAAG,CAAC,CAAA;YACxG,MAAM,IAAI,+BAAgB,CAAC,mCAAmC,EAAE,8BAA8B,EAAE,GAAG,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AApKD,4CAoKC"}
@@ -0,0 +1,24 @@
1
+ export interface Payload {
2
+ contentSid: string;
3
+ contentVariables?: {
4
+ [k: string]: unknown;
5
+ };
6
+ toNumber?: string;
7
+ from: string;
8
+ customArgs?: {
9
+ [k: string]: unknown;
10
+ };
11
+ connectionOverrides?: string;
12
+ send?: boolean;
13
+ traitEnrichment?: boolean;
14
+ externalIds?: {
15
+ id?: string;
16
+ type?: string;
17
+ channelType?: string;
18
+ subscriptionStatus?: string;
19
+ }[];
20
+ traits?: {
21
+ [k: string]: unknown;
22
+ };
23
+ eventOccurredTS?: string;
24
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendWhatsApp/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { ActionDefinition } from '@segment/actions-core';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ declare const action: ActionDefinition<Settings, Payload>;
5
+ export default action;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const whatsapp_sender_1 = require("./whatsapp-sender");
4
+ const action = {
5
+ title: 'Send WhatsApp',
6
+ description: 'Send WhatsApp using Twilio',
7
+ defaultSubscription: 'type = "track" and event = "Audience Entered"',
8
+ fields: {
9
+ contentSid: {
10
+ label: 'WhatsApp template Content Sid',
11
+ description: 'The template you sending through WhatsApp',
12
+ type: 'string',
13
+ required: true
14
+ },
15
+ contentVariables: {
16
+ label: 'WhatsApp template variables',
17
+ description: 'Content personalization variables/merge tags for your WhatsApp message',
18
+ type: 'object',
19
+ required: false
20
+ },
21
+ toNumber: {
22
+ label: 'Test Number',
23
+ description: 'Number to send WhatsApp to when testing',
24
+ type: 'string'
25
+ },
26
+ from: {
27
+ label: 'From',
28
+ description: 'The Twilio Phone Number, Short Code, or Messaging Service to send WhatsApp from.',
29
+ type: 'string',
30
+ required: true
31
+ },
32
+ customArgs: {
33
+ label: 'Custom Arguments',
34
+ description: 'Additional custom arguments that will be opaquely sent back on webhook events',
35
+ type: 'object',
36
+ required: false
37
+ },
38
+ connectionOverrides: {
39
+ label: 'Connection Overrides',
40
+ description: 'Connection overrides are configuration supported by twilio webhook services. Must be passed as fragments on the callback url',
41
+ type: 'string',
42
+ required: false
43
+ },
44
+ send: {
45
+ label: 'Send Message',
46
+ description: 'Whether or not the message should actually get sent.',
47
+ type: 'boolean',
48
+ required: false,
49
+ default: false
50
+ },
51
+ traitEnrichment: {
52
+ label: 'Trait Enrich',
53
+ description: 'Whether or not trait enrich from event (i.e without profile api call)',
54
+ type: 'boolean',
55
+ required: false,
56
+ default: true
57
+ },
58
+ externalIds: {
59
+ label: 'External IDs',
60
+ description: 'An array of user profile identity information.',
61
+ type: 'object',
62
+ multiple: true,
63
+ properties: {
64
+ id: {
65
+ label: 'ID',
66
+ description: 'A unique identifier for the collection.',
67
+ type: 'string'
68
+ },
69
+ type: {
70
+ label: 'type',
71
+ description: 'The external ID contact type.',
72
+ type: 'string'
73
+ },
74
+ channelType: {
75
+ label: 'type',
76
+ description: 'The external ID contact channel type (SMS, WHATSAPP, etc).',
77
+ type: 'string'
78
+ },
79
+ subscriptionStatus: {
80
+ label: 'ID',
81
+ description: 'The subscription status for the identity.',
82
+ type: 'string'
83
+ }
84
+ },
85
+ default: {
86
+ '@arrayPath': [
87
+ '$.external_ids',
88
+ {
89
+ id: {
90
+ '@path': '$.id'
91
+ },
92
+ type: {
93
+ '@path': '$.type'
94
+ },
95
+ channelType: {
96
+ '@path': '$.channelType'
97
+ },
98
+ subscriptionStatus: {
99
+ '@path': '$.isSubscribed'
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ },
105
+ traits: {
106
+ label: 'Traits',
107
+ description: "A user profile's traits",
108
+ type: 'object',
109
+ required: false,
110
+ default: { '@path': '$.properties' }
111
+ },
112
+ eventOccurredTS: {
113
+ label: 'Event Timestamp',
114
+ description: 'Time of when the actual event happened.',
115
+ type: 'string',
116
+ required: false,
117
+ default: {
118
+ '@path': '$.timestamp'
119
+ }
120
+ }
121
+ },
122
+ perform: async (request, { settings, payload, statsContext, logger }) => {
123
+ const statsClient = statsContext?.statsClient;
124
+ const tags = statsContext?.tags || [];
125
+ if (!settings.region) {
126
+ settings.region = 'us-west-1';
127
+ }
128
+ tags.push(`space_id:${settings.spaceId}`, `projectid:${settings.sourceId}`, `region:${settings.region}`);
129
+ return new whatsapp_sender_1.WhatsAppMessageSender(request, payload, settings, statsClient, tags, logger).send();
130
+ }
131
+ };
132
+ exports.default = action;
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendWhatsApp/index.ts"],"names":[],"mappings":";;AAIA,uDAAyD;AAEzD,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,4BAA4B;IACzC,mBAAmB,EAAE,+CAA+C;IACpE,MAAM,EAAE;QACN,UAAU,EAAE;YACV,KAAK,EAAE,+BAA+B;YACtC,WAAW,EAAE,2CAA2C;YACxD,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SAC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AQ,EAAE,EAAE,UAAU,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;QAExG,OAAO,IAAI,uCAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;IAChG,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,21 @@
1
+ import type { Settings } from '../generated-types';
2
+ import type { Payload } from './generated-types';
3
+ import { RequestFn, MessageSender } from '../utils/message-sender';
4
+ import { Logger, StatsClient, StatsContext } from '@segment/actions-core/src/destination-kit';
5
+ export declare class WhatsAppMessageSender extends MessageSender<Payload> {
6
+ readonly request: RequestFn;
7
+ readonly payload: Payload;
8
+ readonly settings: Settings;
9
+ readonly statsClient: StatsClient | undefined;
10
+ readonly tags: StatsContext['tags'];
11
+ readonly logger: Logger | undefined;
12
+ constructor(request: RequestFn, payload: Payload, settings: Settings, statsClient: StatsClient | undefined, tags: StatsContext['tags'], logger: Logger | undefined);
13
+ getExternalId: () => {
14
+ id?: string | undefined;
15
+ type?: string | undefined;
16
+ channelType?: string | undefined;
17
+ subscriptionStatus?: string | undefined;
18
+ } | undefined;
19
+ getBody: (phone: string) => Promise<URLSearchParams>;
20
+ private getVariables;
21
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WhatsAppMessageSender = void 0;
4
+ const liquidjs_1 = require("liquidjs");
5
+ const actions_core_1 = require("@segment/actions-core");
6
+ const message_sender_1 = require("../utils/message-sender");
7
+ const google_libphonenumber_1 = require("google-libphonenumber");
8
+ const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
9
+ const Liquid = new liquidjs_1.Liquid();
10
+ class WhatsAppMessageSender extends message_sender_1.MessageSender {
11
+ constructor(request, payload, settings, statsClient, tags, logger) {
12
+ super(request, payload, settings, statsClient, tags, logger);
13
+ this.request = request;
14
+ this.payload = payload;
15
+ this.settings = settings;
16
+ this.statsClient = statsClient;
17
+ this.tags = tags;
18
+ this.logger = logger;
19
+ this.getExternalId = () => this.payload.externalIds?.find(({ type, channelType }) => channelType?.toLowerCase() === 'whatsapp' && type === 'phone');
20
+ this.getBody = async (phone) => {
21
+ let parsedPhone;
22
+ try {
23
+ parsedPhone = phoneUtil.parse(phone, 'US');
24
+ parsedPhone = phoneUtil.format(parsedPhone, google_libphonenumber_1.PhoneNumberFormat.E164);
25
+ parsedPhone = `whatsapp:${parsedPhone}`;
26
+ }
27
+ catch (error) {
28
+ this.tags.push('type:invalid_phone_e164');
29
+ this.logger?.error(`TE Messaging: WhatsApp invalid phone number - ${this.settings.spaceId} - [${error}]`);
30
+ this.statsClient?.incr('actions-personas-messaging-twilio.error', 1, this.tags);
31
+ 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);
32
+ }
33
+ if (!this.payload.contentSid) {
34
+ this.logger?.error(`TE Messaging: A valid WhatsApp Content SID was not provided - ${this.settings.spaceId}`);
35
+ throw new actions_core_1.IntegrationError('A valid whatsApp Content SID was not provided.', `INVALID_CONTENT_SID`, 400);
36
+ }
37
+ const params = {
38
+ ContentSid: this.payload.contentSid,
39
+ From: this.payload.from,
40
+ To: parsedPhone
41
+ };
42
+ const contentVariables = await this.getVariables();
43
+ if (contentVariables)
44
+ params['ContentVariables'] = contentVariables;
45
+ return new URLSearchParams(params);
46
+ };
47
+ this.getVariables = async () => {
48
+ try {
49
+ if (!this.payload.traitEnrichment && this.payload.contentVariables)
50
+ return JSON.stringify(this.payload.contentVariables) ?? null;
51
+ if (!this.payload.contentVariables || !this.payload.traits)
52
+ return null;
53
+ const profile = {
54
+ profile: {
55
+ traits: this.payload.traits
56
+ }
57
+ };
58
+ const mapping = {};
59
+ for (const [key, val] of Object.entries(this.payload.contentVariables)) {
60
+ const parsed = await Liquid.parseAndRender(val, profile);
61
+ if (parsed?.length) {
62
+ mapping[key] = parsed;
63
+ }
64
+ }
65
+ return JSON.stringify(mapping);
66
+ }
67
+ catch (error) {
68
+ this.logger?.error(`TE Messaging: Failed to parse WhatsApp template with content variables - ${this.settings.spaceId} - [${error}]`);
69
+ throw new actions_core_1.IntegrationError(`Unable to parse templating in content variables`, `Content variables templating parse failure`, 400);
70
+ }
71
+ };
72
+ }
73
+ }
74
+ exports.WhatsAppMessageSender = WhatsAppMessageSender;
75
+ //# sourceMappingURL=whatsapp-sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whatsapp-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendWhatsApp/whatsapp-sender.ts"],"names":[],"mappings":";;;AACA,uCAA6C;AAG7C,wDAAwD;AACxD,4DAAkE;AAClE,iEAA0E;AAG1E,MAAM,SAAS,GAAG,uCAAe,CAAC,WAAW,EAAE,CAAA;AAC/C,MAAM,MAAM,GAAG,IAAI,iBAAQ,EAAE,CAAA;AAE7B,MAAa,qBAAsB,SAAQ,8BAAsB;IAC/D,YACW,OAAkB,EAClB,OAAgB,EAChB,QAAkB,EAClB,WAAoC,EACpC,IAA0B,EAC1B,MAA0B;QAEnC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;QAPnD,YAAO,GAAP,OAAO,CAAW;QAClB,YAAO,GAAP,OAAO,CAAS;QAChB,aAAQ,GAAR,QAAQ,CAAU;QAClB,gBAAW,GAAX,WAAW,CAAyB;QACpC,SAAI,GAAJ,IAAI,CAAsB;QAC1B,WAAM,GAAN,MAAM,CAAoB;QAKrC,kBAAa,GAAG,GAAG,EAAE,CACnB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAC5B,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,UAAU,IAAI,IAAI,KAAK,OAAO,CAC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@@
1
+ import type { RequestOptions } from '@segment/actions-core';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from '../sendSms/generated-types';
4
+ import { Logger, StatsClient, StatsContext } from '@segment/actions-core/src/destination-kit';
5
+ export declare type RequestFn = (url: string, options?: RequestOptions) => Promise<Response>;
6
+ declare type MinimalPayload = Pick<Payload, 'from' | 'toNumber' | 'customArgs' | 'externalIds' | 'traits' | 'send' | 'eventOccurredTS'>;
7
+ export declare abstract class MessageSender<SmsPayload extends MinimalPayload> {
8
+ readonly request: RequestFn;
9
+ readonly payload: SmsPayload;
10
+ readonly settings: Settings;
11
+ readonly statsClient: StatsClient | undefined;
12
+ readonly tags: StatsContext['tags'];
13
+ readonly logger: Logger | undefined;
14
+ private readonly EXTERNAL_ID_KEY;
15
+ private readonly DEFAULT_HOSTNAME;
16
+ private readonly DEFAULT_CONNECTION_OVERRIDES;
17
+ constructor(request: RequestFn, payload: SmsPayload, settings: Settings, statsClient: StatsClient | undefined, tags: StatsContext['tags'], logger: Logger | undefined);
18
+ abstract getBody: (phone: string) => Promise<URLSearchParams>;
19
+ abstract getExternalId: () => NonNullable<MinimalPayload['externalIds']>[number] | undefined;
20
+ send: () => Promise<Response | undefined>;
21
+ private getSendabilityPayload;
22
+ private getWebhookUrlWithParams;
23
+ }
24
+ export {};