@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
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const sendSms_1 = __importDefault(require("./sendSms"));
|
|
7
7
|
const sendWhatsApp_1 = __importDefault(require("./sendWhatsApp"));
|
|
8
|
+
const sendMobilePush_1 = __importDefault(require("./sendMobilePush"));
|
|
8
9
|
const getRange = (val) => {
|
|
9
10
|
return Array(val)
|
|
10
11
|
.fill(1)
|
|
@@ -166,7 +167,8 @@ const destination = {
|
|
|
166
167
|
},
|
|
167
168
|
actions: {
|
|
168
169
|
sendSms: sendSms_1.default,
|
|
169
|
-
sendWhatsApp: sendWhatsApp_1.default
|
|
170
|
+
sendWhatsApp: sendWhatsApp_1.default,
|
|
171
|
+
sendMobilePush: sendMobilePush_1.default
|
|
170
172
|
}
|
|
171
173
|
};
|
|
172
174
|
exports.default = destination;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/engage-messaging-twilio/index.ts"],"names":[],"mappings":";;;;;AAEA,wDAA+B;AAC/B,kEAAyC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/engage-messaging-twilio/index.ts"],"names":[],"mappings":";;;;;AAEA,wDAA+B;AAC/B,kEAAyC;AACzC,sEAA6C;AAE7C,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAsC,EAAE;IACnE,OAAO,KAAK,CAAC,GAAG,CAAC;SACd,IAAI,CAAC,CAAC,CAAC;SACP,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACzD,CAAC,CAAA;AAED,MAAM,6BAA6B,GAA+B;IAChE,EAAE,EAAE;QACF,KAAK,EAAE,oBAAoB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E,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,KAAK;aAChB;YACD,cAAc,EAAE;gBACd,KAAK,EAAE,kBAAkB;gBACzB,WAAW,EACT,sGAAsG;gBACxG,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,gBAAgB;gBACzB,QAAQ,EAAE,KAAK;aAChB;YACD,mBAAmB,EAAE;gBACnB,KAAK,EAAE,sBAAsB;gBAC7B,WAAW,EACT,8HAA8H;gBAChI,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,aAAa;gBACtB,UAAU,EAAE,6BAA6B;aAC1C;YACD,MAAM,EAAE;gBACN,KAAK,EAAE,QAAQ;gBACf,WAAW,EAAE,kDAAkD;gBAC/D,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE;oBACP,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE;oBAC1C,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE;iBAC3C;gBACD,OAAO,EAAE,WAAW;gBACpB,QAAQ,EAAE,KAAK;aAChB;SACF;QACD,kBAAkB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;YACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,cAAc,IAAI,gBAAgB,CAAA;YACpE,OAAO,OAAO,CAAC,WAAW,QAAQ,aAAa,CAAC,CAAA;QAClD,CAAC;KACF;IASD,OAAO,EAAE;QACP,OAAO,EAAP,iBAAO;QACP,YAAY,EAAZ,sBAAY;QACZ,cAAc,EAAd,wBAAc;KACf;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface Payload {
|
|
2
|
+
contentSid?: string;
|
|
3
|
+
from: string;
|
|
4
|
+
customizations?: {
|
|
5
|
+
title?: string;
|
|
6
|
+
body?: string;
|
|
7
|
+
media?: string[];
|
|
8
|
+
tapAction?: string;
|
|
9
|
+
deepLink?: string;
|
|
10
|
+
sound?: string;
|
|
11
|
+
priority?: string;
|
|
12
|
+
badgeAmount?: number;
|
|
13
|
+
badgeStrategy?: string;
|
|
14
|
+
ttl?: number;
|
|
15
|
+
};
|
|
16
|
+
customArgs?: {
|
|
17
|
+
[k: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
connectionOverrides?: string;
|
|
20
|
+
send?: boolean;
|
|
21
|
+
externalIds?: {
|
|
22
|
+
id?: string;
|
|
23
|
+
type?: string;
|
|
24
|
+
channelType?: string;
|
|
25
|
+
subscriptionStatus?: string;
|
|
26
|
+
}[];
|
|
27
|
+
traits?: {
|
|
28
|
+
[k: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
eventOccurredTS?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendMobilePush/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const push_sender_1 = require("./push-sender");
|
|
4
|
+
const action = {
|
|
5
|
+
title: 'Send Mobile Push Notification',
|
|
6
|
+
description: 'Send a push notification to a mobile device using Twilio',
|
|
7
|
+
defaultSubscription: 'type = "track" and event = "Audience Entered"',
|
|
8
|
+
fields: {
|
|
9
|
+
contentSid: {
|
|
10
|
+
label: 'Content template Sid',
|
|
11
|
+
description: 'The template to be sent',
|
|
12
|
+
type: 'string',
|
|
13
|
+
required: false
|
|
14
|
+
},
|
|
15
|
+
from: {
|
|
16
|
+
label: 'From',
|
|
17
|
+
description: 'The Push Service Sid to send the push notification from.',
|
|
18
|
+
type: 'string',
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
customizations: {
|
|
22
|
+
label: 'Customizations',
|
|
23
|
+
description: 'Customizations for the notification',
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
title: {
|
|
27
|
+
label: 'Notification title',
|
|
28
|
+
description: 'The title to be displayed for your notification',
|
|
29
|
+
type: 'string',
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
body: {
|
|
33
|
+
label: 'Notification body',
|
|
34
|
+
description: 'The body to be displayed for your notification',
|
|
35
|
+
type: 'string',
|
|
36
|
+
required: false
|
|
37
|
+
},
|
|
38
|
+
media: {
|
|
39
|
+
label: 'Media urls',
|
|
40
|
+
description: 'Media to display to notification',
|
|
41
|
+
type: 'string',
|
|
42
|
+
required: false,
|
|
43
|
+
multiple: true
|
|
44
|
+
},
|
|
45
|
+
tapAction: {
|
|
46
|
+
label: 'Notification open action',
|
|
47
|
+
description: 'Sets the noitfication click action/category',
|
|
48
|
+
type: 'string',
|
|
49
|
+
required: false
|
|
50
|
+
},
|
|
51
|
+
deepLink: {
|
|
52
|
+
label: 'Notification title',
|
|
53
|
+
description: 'Sets the deep link',
|
|
54
|
+
type: 'string',
|
|
55
|
+
required: false
|
|
56
|
+
},
|
|
57
|
+
sound: {
|
|
58
|
+
label: 'Notification sound',
|
|
59
|
+
description: 'Sets the sound played when the notification arrives',
|
|
60
|
+
type: 'string',
|
|
61
|
+
required: false
|
|
62
|
+
},
|
|
63
|
+
priority: {
|
|
64
|
+
label: 'Notification priority',
|
|
65
|
+
description: 'Sets the priority of the message',
|
|
66
|
+
type: 'string',
|
|
67
|
+
required: false,
|
|
68
|
+
choices: [
|
|
69
|
+
{ label: 'low', value: 'low' },
|
|
70
|
+
{ label: 'high', value: 'high' }
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
badgeAmount: {
|
|
74
|
+
label: 'Badge amount',
|
|
75
|
+
description: 'The badge count which is used in combination with badge strategy to determine the final badge',
|
|
76
|
+
type: 'number',
|
|
77
|
+
required: false
|
|
78
|
+
},
|
|
79
|
+
badgeStrategy: {
|
|
80
|
+
label: 'Badge strategy',
|
|
81
|
+
description: 'Sets the badge count strategy in the notification',
|
|
82
|
+
type: 'string',
|
|
83
|
+
required: false,
|
|
84
|
+
choices: [
|
|
85
|
+
{
|
|
86
|
+
value: 'inc',
|
|
87
|
+
label: 'increment'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
value: 'dec',
|
|
91
|
+
label: 'decrement'
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
value: 'set',
|
|
95
|
+
label: 'set'
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
ttl: {
|
|
100
|
+
label: 'Time to live',
|
|
101
|
+
description: 'Sets the time to live for the notification',
|
|
102
|
+
type: 'number',
|
|
103
|
+
required: false
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
customArgs: {
|
|
108
|
+
label: 'Custom Arguments',
|
|
109
|
+
description: 'Additional custom arguments that will be opaquely sent back on webhook events',
|
|
110
|
+
type: 'object',
|
|
111
|
+
required: false
|
|
112
|
+
},
|
|
113
|
+
connectionOverrides: {
|
|
114
|
+
label: 'Connection Overrides',
|
|
115
|
+
description: 'Connection overrides are configuration supported by twilio webhook services. Must be passed as fragments on the callback url',
|
|
116
|
+
type: 'string',
|
|
117
|
+
required: false
|
|
118
|
+
},
|
|
119
|
+
send: {
|
|
120
|
+
label: 'Send Notification',
|
|
121
|
+
description: 'Whether or not the notification should actually get sent.',
|
|
122
|
+
type: 'boolean',
|
|
123
|
+
required: false,
|
|
124
|
+
default: false
|
|
125
|
+
},
|
|
126
|
+
externalIds: {
|
|
127
|
+
label: 'External IDs',
|
|
128
|
+
description: 'An array of user profile identity information.',
|
|
129
|
+
type: 'object',
|
|
130
|
+
multiple: true,
|
|
131
|
+
properties: {
|
|
132
|
+
id: {
|
|
133
|
+
label: 'ID',
|
|
134
|
+
description: 'A unique identifier for the collection.',
|
|
135
|
+
type: 'string'
|
|
136
|
+
},
|
|
137
|
+
type: {
|
|
138
|
+
label: 'type',
|
|
139
|
+
description: 'The external ID contact type.',
|
|
140
|
+
type: 'string'
|
|
141
|
+
},
|
|
142
|
+
channelType: {
|
|
143
|
+
label: 'type',
|
|
144
|
+
description: 'The external ID contact channel type (SMS, WHATSAPP, etc).',
|
|
145
|
+
type: 'string'
|
|
146
|
+
},
|
|
147
|
+
subscriptionStatus: {
|
|
148
|
+
label: 'ID',
|
|
149
|
+
description: 'The subscription status for the identity.',
|
|
150
|
+
type: 'string'
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
default: {
|
|
154
|
+
'@arrayPath': [
|
|
155
|
+
'$.external_ids',
|
|
156
|
+
{
|
|
157
|
+
id: {
|
|
158
|
+
'@path': '$.id'
|
|
159
|
+
},
|
|
160
|
+
type: {
|
|
161
|
+
'@path': '$.type'
|
|
162
|
+
},
|
|
163
|
+
channelType: {
|
|
164
|
+
'@path': '$.channelType'
|
|
165
|
+
},
|
|
166
|
+
subscriptionStatus: {
|
|
167
|
+
'@path': '$.isSubscribed'
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
traits: {
|
|
174
|
+
label: 'Traits',
|
|
175
|
+
description: "A user profile's traits",
|
|
176
|
+
type: 'object',
|
|
177
|
+
required: false,
|
|
178
|
+
default: { '@path': '$.properties' }
|
|
179
|
+
},
|
|
180
|
+
eventOccurredTS: {
|
|
181
|
+
label: 'Event Timestamp',
|
|
182
|
+
description: 'Time of when the actual event happened.',
|
|
183
|
+
type: 'string',
|
|
184
|
+
required: false,
|
|
185
|
+
default: {
|
|
186
|
+
'@path': '$.timestamp'
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
perform: async (request, data) => {
|
|
191
|
+
const { settings, payload, statsContext, logger } = data;
|
|
192
|
+
const statsClient = statsContext?.statsClient;
|
|
193
|
+
const tags = statsContext?.tags || [];
|
|
194
|
+
if (!settings.region) {
|
|
195
|
+
settings.region = 'us-west-1';
|
|
196
|
+
}
|
|
197
|
+
tags.push(`space_id:${settings.spaceId}`, `projectid:${settings.sourceId}`, `region:${settings.region}`);
|
|
198
|
+
return new push_sender_1.PushSender(request, payload, settings, statsClient, tags, logger, data).send();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
exports.default = action;
|
|
202
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendMobilePush/index.ts"],"names":[],"mappings":";;AAIA,+CAA0C;AAE1C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,+BAA+B;IACtC,WAAW,EAAE,0DAA0D;IACvE,mBAAmB,EAAE,+CAA+C;IACpE,MAAM,EAAE;QACN,UAAU,EAAE;YACV,KAAK,EAAE,sBAAsB;YAC7B,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;SAChB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,MAAM;YACb,WAAW,EAAE,0DAA0D;YACvE,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf;QACD,cAAc,EAAE;YACd,KAAK,EAAE,gBAAgB;YACvB,WAAW,EAAE,qCAAqC;YAClD,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,KAAK,EAAE,oBAAoB;oBAC3B,WAAW,EAAE,iDAAiD;oBAC9D,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,KAAK;iBAChB;gBACD,IAAI,EAAE;oBACJ,KAAK,EAAE,mBAAmB;oBAC1B,WAAW,EAAE,gDAAgD;oBAC7D,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,KAAK;iBAChB;gBACD,KAAK,EAAE;oBACL,KAAK,EAAE,YAAY;oBACnB,WAAW,EAAE,kCAAkC;oBAC/C,IAAI,EAAE,QAAQ;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Payload } from './generated-types';
|
|
3
|
+
interface BodyCustomDataBundle {
|
|
4
|
+
requestBody: URLSearchParams;
|
|
5
|
+
customData: object;
|
|
6
|
+
}
|
|
7
|
+
export declare class PushSender<Payload extends PushPayload> extends MessageSender<Payload> {
|
|
8
|
+
static readonly externalIdTypes: string[];
|
|
9
|
+
protected supportedTemplateTypes: string[];
|
|
10
|
+
private retryableStatusCodes;
|
|
11
|
+
private DEFAULT_HOSTNAME;
|
|
12
|
+
getChannelType(): string;
|
|
13
|
+
doSend(): Promise<Response[] | undefined>;
|
|
14
|
+
getBody(): Promise<BodyCustomDataBundle>;
|
|
15
|
+
private removeEmpties;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PushSender = void 0;
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
const message_sender_1 = require("../utils/message-sender");
|
|
6
|
+
const actions_core_2 = require("@segment/actions-core");
|
|
7
|
+
class PushApiError extends actions_core_1.HTTPError {
|
|
8
|
+
}
|
|
9
|
+
class PushSender extends message_sender_1.MessageSender {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.supportedTemplateTypes = ['twilio/text', 'twilio/media'];
|
|
13
|
+
this.retryableStatusCodes = [500, 429];
|
|
14
|
+
this.DEFAULT_HOSTNAME = 'push.ashburn.us1.twilio.com';
|
|
15
|
+
}
|
|
16
|
+
getChannelType() {
|
|
17
|
+
return 'mobilepush';
|
|
18
|
+
}
|
|
19
|
+
async doSend() {
|
|
20
|
+
if (!this.payload.send) {
|
|
21
|
+
this.logInfo(`not sending push notification, payload.send = ${this.payload.send} - ${this.settings.spaceId}`);
|
|
22
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.send_disabled', 1, this.tags);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const allPushDevices = this.payload.externalIds?.filter((extId) => extId.type && PushSender.externalIdTypes.includes(extId.type)) || [];
|
|
26
|
+
const recipientDevices = allPushDevices?.filter((extId) => extId.subscriptionStatus && message_sender_1.MessageSender.sendableStatuses.includes(extId.subscriptionStatus?.toLowerCase())) || [];
|
|
27
|
+
if (recipientDevices.length) {
|
|
28
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.subscribed', 1, this.tags);
|
|
29
|
+
}
|
|
30
|
+
const totalUnsubscribed = allPushDevices.length - recipientDevices.length;
|
|
31
|
+
if (totalUnsubscribed > 0) {
|
|
32
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.notsubscribed', totalUnsubscribed, this.tags);
|
|
33
|
+
}
|
|
34
|
+
if (!recipientDevices?.length) {
|
|
35
|
+
this.logInfo(`not sending push notification, no devices are subscribed - ${this.settings.spaceId}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { requestBody, customData } = await this.getBody();
|
|
39
|
+
const twilioHostname = this.settings.twilioHostname?.length ? this.settings.twilioHostname : this.DEFAULT_HOSTNAME;
|
|
40
|
+
const twilioToken = Buffer.from(`${this.settings.twilioApiKeySID}:${this.settings.twilioApiKeySecret}`).toString('base64');
|
|
41
|
+
const responses = [];
|
|
42
|
+
const failedSends = [];
|
|
43
|
+
let failureIsRetryable = true;
|
|
44
|
+
for (const recipientDevice of recipientDevices) {
|
|
45
|
+
const webhookUrl = this.getWebhookUrlWithParams(recipientDevice.type, recipientDevice.id);
|
|
46
|
+
try {
|
|
47
|
+
const body = new URLSearchParams(requestBody);
|
|
48
|
+
if (recipientDevice?.type?.toLowerCase() === 'ios.push_token') {
|
|
49
|
+
body.append('Recipients', JSON.stringify({
|
|
50
|
+
apn: [{ addr: recipientDevice.id }]
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
body.append('Recipients', JSON.stringify({
|
|
55
|
+
fcm: [{ addr: recipientDevice.id }]
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
body.append('CustomData', JSON.stringify({
|
|
59
|
+
...customData,
|
|
60
|
+
__segment_internal_external_id_key__: recipientDevice.type,
|
|
61
|
+
__segment_internal_external_id_value__: recipientDevice.id
|
|
62
|
+
}));
|
|
63
|
+
if (webhookUrl) {
|
|
64
|
+
body.append('DeliveryCallbackUrl', webhookUrl);
|
|
65
|
+
}
|
|
66
|
+
this.statsClient?.set('actions_personas_messaging_twilio.message_body_size', body?.toString().length, this.tags);
|
|
67
|
+
const response = await this.request(`https://${twilioHostname}/v1/Services/${this.payload.from}/Notifications`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
authorization: `Basic ${twilioToken}`
|
|
71
|
+
},
|
|
72
|
+
body
|
|
73
|
+
});
|
|
74
|
+
this.tags.push(`twilio_status_code:${response.status}`);
|
|
75
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.response', 1, this.tags);
|
|
76
|
+
responses.push(response);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (error instanceof Object) {
|
|
80
|
+
const apiError = error;
|
|
81
|
+
responses.push(apiError.response);
|
|
82
|
+
const errorStatus = apiError.response?.status ?? apiError.response?.data?.status;
|
|
83
|
+
failureIsRetryable = failureIsRetryable && this.retryableStatusCodes.includes(errorStatus);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
failureIsRetryable = false;
|
|
87
|
+
}
|
|
88
|
+
failedSends.push({ ...recipientDevice, id: this.redactPii(recipientDevice.id) });
|
|
89
|
+
this.logDetails['failed-recipient-devices'] = failedSends;
|
|
90
|
+
this.logTwilioError(error, 'Twilio Push API');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (failedSends.length === recipientDevices.length) {
|
|
94
|
+
this.logError(`failed to send to all subscribed devices - ${this.settings.spaceId}`);
|
|
95
|
+
if (failureIsRetryable) {
|
|
96
|
+
throw new actions_core_1.RetryableError('Unexpected response from Twilio Push API');
|
|
97
|
+
}
|
|
98
|
+
throw new actions_core_1.IntegrationError('Unexpected response from Twilio Push API', 'UNEXPECTED_ERROR', responses.find((resp) => !this.retryableStatusCodes.includes(resp.status))?.status || 400);
|
|
99
|
+
}
|
|
100
|
+
this.tags.push(`total_succeeded:${recipientDevices.length - failedSends.length}`);
|
|
101
|
+
this.tags.push(`total_failed:${failedSends.length}`);
|
|
102
|
+
if (this.payload.eventOccurredTS != undefined) {
|
|
103
|
+
this.statsClient?.histogram('actions_personas_messaging_twilio.eventDeliveryTS', Date.now() - new Date(this.payload.eventOccurredTS).getTime(), this.tags);
|
|
104
|
+
}
|
|
105
|
+
return responses;
|
|
106
|
+
}
|
|
107
|
+
async getBody() {
|
|
108
|
+
let templateTypes;
|
|
109
|
+
if (this.payload.contentSid) {
|
|
110
|
+
templateTypes = await this.getContentTemplateTypes();
|
|
111
|
+
}
|
|
112
|
+
const profile = { traits: this.payload.traits };
|
|
113
|
+
const parsedTemplateContent = await this.parseContent({
|
|
114
|
+
title: this.payload.customizations?.title,
|
|
115
|
+
body: this.payload.customizations?.body,
|
|
116
|
+
media: this.payload.customizations?.media,
|
|
117
|
+
...templateTypes
|
|
118
|
+
}, profile);
|
|
119
|
+
try {
|
|
120
|
+
const customData = this.removeEmpties({
|
|
121
|
+
...this.payload.customArgs,
|
|
122
|
+
space_id: this.settings.spaceId,
|
|
123
|
+
badgeAmount: this.payload.customizations?.badgeAmount,
|
|
124
|
+
badgeStrategy: this.payload.customizations?.badgeStrategy,
|
|
125
|
+
media: parsedTemplateContent.media?.length ? parsedTemplateContent.media : undefined,
|
|
126
|
+
deepLink: this.payload.customizations?.deepLink
|
|
127
|
+
});
|
|
128
|
+
const body = this.removeEmpties({
|
|
129
|
+
Body: parsedTemplateContent.body,
|
|
130
|
+
Action: this.payload.customizations?.tapAction,
|
|
131
|
+
Title: parsedTemplateContent.title,
|
|
132
|
+
Sound: this.payload.customizations?.sound,
|
|
133
|
+
Priority: this.payload.customizations?.priority,
|
|
134
|
+
TimeToLive: this.payload.customizations?.ttl,
|
|
135
|
+
FcmPayload: this.removeEmpties({
|
|
136
|
+
mutable_content: true,
|
|
137
|
+
notification: {
|
|
138
|
+
badge: this.payload.customizations?.badgeAmount
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
ApnPayload: {
|
|
142
|
+
aps: {
|
|
143
|
+
'mutable-content': 1,
|
|
144
|
+
badge: this.payload.customizations?.badgeAmount
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
const requestBody = new URLSearchParams({
|
|
149
|
+
...body,
|
|
150
|
+
FcmPayload: JSON.stringify(body.FcmPayload),
|
|
151
|
+
ApnPayload: JSON.stringify(body.ApnPayload)
|
|
152
|
+
});
|
|
153
|
+
return { requestBody, customData };
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.tags.push('reason:invalid_payload');
|
|
157
|
+
this.statsClient?.incr('actions_personas_messaging_twilio.error', 1, this.tags);
|
|
158
|
+
this.logError(`unable to construct Notify API request body - ${this.settings.spaceId}`, JSON.stringify(error));
|
|
159
|
+
throw new actions_core_2.PayloadValidationError('Unable to construct Notify API request body');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
removeEmpties(obj) {
|
|
163
|
+
return JSON.parse(JSON.stringify(obj, (_, value) => {
|
|
164
|
+
if (value == null || value?.length === 0 || (typeof value === 'object' && Object.keys(value).length === 0)) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.PushSender = PushSender;
|
|
172
|
+
PushSender.externalIdTypes = ['ios.push_token', 'android.push_token'];
|
|
173
|
+
//# sourceMappingURL=push-sender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-sender.js","sourceRoot":"","sources":["../../../../src/destinations/engage-messaging-twilio/sendMobilePush/push-sender.ts"],"names":[],"mappings":";;;AACA,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C,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,yCAAyC,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;YAC/E,IAAI,CAAC,QAAQ,CAAC,iDAAiD,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;YAC9G,MAAM,IAAI,qCAAsB,CAAC,6CAA6C,CAAC,CAAA;SAChF;IACH,CAAC;IAMO,aAAa,CAAC,GAA4B;QAChD,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YAC/B,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE;gBAC1G,OAAO,SAAS,CAAA;aACjB;YACD,OAAO,KAAK,CAAA;QACd,CAAC,CAAC,CACH,CAAA;IACH,CAAC;;AA3OH,gCA4OC;AA3OiB,0BAAe,GAAG,CAAC,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
|
}
|