@segment/action-destinations 3.345.2-staging-bca9b38b6.0 → 3.345.6-staging
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/accoil-analytics/postToAccoil/generated-types.d.ts +5 -0
- package/dist/destinations/accoil-analytics/postToAccoil/generated-types.js +3 -0
- package/dist/destinations/accoil-analytics/postToAccoil/generated-types.js.map +1 -0
- package/dist/destinations/accoil-analytics/postToAccoil/index.d.ts +5 -0
- package/dist/destinations/accoil-analytics/postToAccoil/index.js +28 -0
- package/dist/destinations/accoil-analytics/postToAccoil/index.js.map +1 -0
- package/dist/destinations/braze/createAliasV2.types.d.ts +5 -0
- package/dist/destinations/braze/createAliasV2.types.js +3 -0
- package/dist/destinations/braze/createAliasV2.types.js.map +1 -0
- package/dist/destinations/braze/identifyUserV2.types.d.ts +8 -0
- package/dist/destinations/braze/identifyUserV2.types.js +3 -0
- package/dist/destinations/braze/identifyUserV2.types.js.map +1 -0
- package/dist/destinations/campaign-manager-360/common-fields.d.ts +3 -0
- package/dist/destinations/campaign-manager-360/common-fields.js +306 -0
- package/dist/destinations/campaign-manager-360/common-fields.js.map +1 -0
- package/dist/destinations/campaign-manager-360/conversionAdjustmentUpload/generated-types.d.ts +45 -0
- package/dist/destinations/campaign-manager-360/conversionAdjustmentUpload/generated-types.js +3 -0
- package/dist/destinations/campaign-manager-360/conversionAdjustmentUpload/generated-types.js.map +1 -0
- package/dist/destinations/campaign-manager-360/conversionAdjustmentUpload/index.d.ts +5 -0
- package/dist/destinations/campaign-manager-360/conversionAdjustmentUpload/index.js +86 -0
- package/dist/destinations/campaign-manager-360/conversionAdjustmentUpload/index.js.map +1 -0
- package/dist/destinations/campaign-manager-360/conversionUpload/generated-types.d.ts +50 -0
- package/dist/destinations/campaign-manager-360/conversionUpload/generated-types.js +3 -0
- package/dist/destinations/campaign-manager-360/conversionUpload/generated-types.js.map +1 -0
- package/dist/destinations/campaign-manager-360/conversionUpload/index.d.ts +5 -0
- package/dist/destinations/campaign-manager-360/conversionUpload/index.js +131 -0
- package/dist/destinations/campaign-manager-360/conversionUpload/index.js.map +1 -0
- package/dist/destinations/campaign-manager-360/generated-types.d.ts +5 -0
- package/dist/destinations/campaign-manager-360/generated-types.js +3 -0
- package/dist/destinations/campaign-manager-360/generated-types.js.map +1 -0
- package/dist/destinations/campaign-manager-360/index.d.ts +4 -0
- package/dist/destinations/campaign-manager-360/index.js +63 -0
- package/dist/destinations/campaign-manager-360/index.js.map +1 -0
- package/dist/destinations/campaign-manager-360/types.d.ts +116 -0
- package/dist/destinations/campaign-manager-360/types.js +23 -0
- package/dist/destinations/campaign-manager-360/types.js.map +1 -0
- package/dist/destinations/campaign-manager-360/utils.d.ts +21 -0
- package/dist/destinations/campaign-manager-360/utils.js +175 -0
- package/dist/destinations/campaign-manager-360/utils.js.map +1 -0
- package/dist/destinations/first-party-dv360/addToList/generated-types.d.ts +2 -0
- package/dist/destinations/first-party-dv360/addToList/generated-types.js +3 -0
- package/dist/destinations/first-party-dv360/addToList/generated-types.js.map +1 -0
- package/dist/destinations/first-party-dv360/addToList/index.d.ts +5 -0
- package/dist/destinations/first-party-dv360/addToList/index.js +11 -0
- package/dist/destinations/first-party-dv360/addToList/index.js.map +1 -0
- package/dist/destinations/first-party-dv360/addToList.types.d.ts +9 -0
- package/dist/destinations/first-party-dv360/addToList.types.js +3 -0
- package/dist/destinations/first-party-dv360/addToList.types.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/dynamic-fields.d.ts +5 -0
- package/dist/destinations/hubspot/customEvent/dynamic-fields.js +112 -0
- package/dist/destinations/hubspot/customEvent/dynamic-fields.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/event-completion.d.ts +3 -0
- package/dist/destinations/hubspot/customEvent/event-completion.js +17 -0
- package/dist/destinations/hubspot/customEvent/event-completion.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/schema-functions.d.ts +3 -0
- package/dist/destinations/hubspot/customEvent/schema-functions.js +30 -0
- package/dist/destinations/hubspot/customEvent/schema-functions.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/utils.d.ts +14 -0
- package/dist/destinations/hubspot/customEvent/utils.js +303 -0
- package/dist/destinations/hubspot/customEvent/utils.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/validation-functions.d.ts +3 -0
- package/dist/destinations/hubspot/customEvent/validation-functions.js +66 -0
- package/dist/destinations/hubspot/customEvent/validation-functions.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/validation.d.ts +3 -0
- package/dist/destinations/hubspot/customEvent/validation.js +66 -0
- package/dist/destinations/hubspot/customEvent/validation.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/association-functions.d.ts +5 -0
- package/dist/destinations/hubspot/upsertObject/association-functions.js +136 -0
- package/dist/destinations/hubspot/upsertObject/association-functions.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/cache-functions.d.ts +3 -0
- package/dist/destinations/hubspot/upsertObject/cache-functions.js +20 -0
- package/dist/destinations/hubspot/upsertObject/cache-functions.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/dynamic-fields.d.ts +7 -0
- package/dist/destinations/hubspot/upsertObject/dynamic-fields.js +222 -0
- package/dist/destinations/hubspot/upsertObject/dynamic-fields.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-association-functions.d.ts +5 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-association-functions.js +136 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-association-functions.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-properties-functions.d.ts +4 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-properties-functions.js +159 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-properties-functions.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-record-functions.d.ts +4 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-record-functions.js +100 -0
- package/dist/destinations/hubspot/upsertObject/hubspot-record-functions.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/schema-functions.d.ts +3 -0
- package/dist/destinations/hubspot/upsertObject/schema-functions.js +80 -0
- package/dist/destinations/hubspot/upsertObject/schema-functions.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/send-from-record-functions.d.ts +4 -0
- package/dist/destinations/hubspot/upsertObject/send-from-record-functions.js +100 -0
- package/dist/destinations/hubspot/upsertObject/send-from-record-functions.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/utils.d.ts +13 -0
- package/dist/destinations/hubspot/upsertObject/utils.js +547 -0
- package/dist/destinations/hubspot/upsertObject/utils.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/validation-functions.d.ts +2 -0
- package/dist/destinations/hubspot/upsertObject/validation-functions.js +67 -0
- package/dist/destinations/hubspot/upsertObject/validation-functions.js.map +1 -0
- package/dist/destinations/responsys/shared_properties.d.ts +3 -0
- package/dist/destinations/responsys/shared_properties.js +19 -0
- package/dist/destinations/responsys/shared_properties.js.map +1 -0
- package/dist/destinations/s3/client.d.ts +2 -1
- package/dist/destinations/s3/client.js.map +1 -1
- package/dist/destinations/s3/functions.d.ts +2 -1
- package/dist/destinations/s3/functions.js +14 -22
- package/dist/destinations/s3/functions.js.map +1 -1
- package/dist/destinations/s3/index.js +1 -1
- package/dist/destinations/s3/syncAudienceToS3/generated-types.d.ts +53 -0
- package/dist/destinations/s3/syncAudienceToS3/generated-types.js +3 -0
- package/dist/destinations/s3/syncAudienceToS3/generated-types.js.map +1 -0
- package/dist/destinations/s3/syncAudienceToS3/index.d.ts +5 -0
- package/dist/destinations/s3/syncAudienceToS3/index.js +22 -0
- package/dist/destinations/s3/syncAudienceToS3/index.js.map +1 -0
- package/dist/destinations/s3/syncEventsToS3/generated-types.d.ts +44 -0
- package/dist/destinations/s3/syncEventsToS3/generated-types.js +3 -0
- package/dist/destinations/s3/syncEventsToS3/generated-types.js.map +1 -0
- package/dist/destinations/s3/syncEventsToS3/index.d.ts +5 -0
- package/dist/destinations/s3/syncEventsToS3/index.js +19 -0
- package/dist/destinations/s3/syncEventsToS3/index.js.map +1 -0
- package/dist/destinations/s3/syncToS3.types.d.ts +44 -0
- package/dist/destinations/s3/syncToS3.types.js +3 -0
- package/dist/destinations/s3/syncToS3.types.js.map +1 -0
- package/dist/destinations/singlestore/sendData/generated-types.d.ts +2 -0
- package/dist/destinations/singlestore/sendData/generated-types.js +3 -0
- package/dist/destinations/singlestore/sendData/generated-types.js.map +1 -0
- package/dist/destinations/singlestore/sendData/index.d.ts +5 -0
- package/dist/destinations/singlestore/sendData/index.js +65 -0
- package/dist/destinations/singlestore/sendData/index.js.map +1 -0
- package/dist/destinations/singlestore/utils.d.ts +0 -0
- package/dist/destinations/singlestore/utils.js +2 -0
- package/dist/destinations/singlestore/utils.js.map +1 -0
- package/dist/destinations/twilio-messaging/generated-types.d.ts +6 -0
- package/dist/destinations/twilio-messaging/generated-types.js +3 -0
- package/dist/destinations/twilio-messaging/generated-types.js.map +1 -0
- package/dist/destinations/twilio-messaging/index.d.ts +4 -0
- package/dist/destinations/twilio-messaging/index.js +61 -0
- package/dist/destinations/twilio-messaging/index.js.map +1 -0
- package/dist/destinations/twilio-messaging/sendMessage/constants.d.ts +45 -0
- package/dist/destinations/twilio-messaging/sendMessage/constants.js +99 -0
- package/dist/destinations/twilio-messaging/sendMessage/constants.js.map +1 -0
- package/dist/destinations/twilio-messaging/sendMessage/dynamic-fields.d.ts +11 -0
- package/dist/destinations/twilio-messaging/sendMessage/dynamic-fields.js +209 -0
- package/dist/destinations/twilio-messaging/sendMessage/dynamic-fields.js.map +1 -0
- package/dist/destinations/twilio-messaging/sendMessage/fields.d.ts +2 -0
- package/dist/destinations/twilio-messaging/sendMessage/fields.js +261 -0
- package/dist/destinations/twilio-messaging/sendMessage/fields.js.map +1 -0
- package/dist/destinations/twilio-messaging/sendMessage/generated-types.d.ts +24 -0
- package/dist/destinations/twilio-messaging/sendMessage/generated-types.js +3 -0
- package/dist/destinations/twilio-messaging/sendMessage/generated-types.js.map +1 -0
- package/dist/destinations/twilio-messaging/sendMessage/index.d.ts +5 -0
- package/dist/destinations/twilio-messaging/sendMessage/index.js +42 -0
- package/dist/destinations/twilio-messaging/sendMessage/index.js.map +1 -0
- package/dist/destinations/twilio-messaging/sendMessage/types.d.ts +34 -0
- package/dist/destinations/twilio-messaging/sendMessage/types.js +3 -0
- package/dist/destinations/twilio-messaging/sendMessage/types.js.map +1 -0
- package/dist/destinations/twilio-messaging/sendMessage/utils.d.ts +6 -0
- package/dist/destinations/twilio-messaging/sendMessage/utils.js +154 -0
- package/dist/destinations/twilio-messaging/sendMessage/utils.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fields_1 = require("./fields");
|
|
4
|
+
const dynamic_fields_1 = require("./dynamic-fields");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const action = {
|
|
7
|
+
title: 'Send message',
|
|
8
|
+
description: "Send messages with Twilio's REST API.",
|
|
9
|
+
fields: fields_1.fields,
|
|
10
|
+
dynamicFields: {
|
|
11
|
+
senderType: async (_, { payload }) => {
|
|
12
|
+
return await dynamic_fields_1.dynamicSenderType(payload);
|
|
13
|
+
},
|
|
14
|
+
fromPhoneNumber: async (request, { payload, settings }) => {
|
|
15
|
+
return await dynamic_fields_1.dynamicFromPhoneNumber(request, payload, settings);
|
|
16
|
+
},
|
|
17
|
+
messagingServiceSid: async (request, { settings }) => {
|
|
18
|
+
return await dynamic_fields_1.dynamicMessagingServiceSid(request, settings);
|
|
19
|
+
},
|
|
20
|
+
contentTemplateType: async (_, { payload }) => {
|
|
21
|
+
return await dynamic_fields_1.dynamicContentTemplateType(payload);
|
|
22
|
+
},
|
|
23
|
+
contentSid: async (request, { payload }) => {
|
|
24
|
+
return await dynamic_fields_1.dynamicContentSid(request, payload);
|
|
25
|
+
},
|
|
26
|
+
mediaUrls: {
|
|
27
|
+
url: async (request, { payload }) => {
|
|
28
|
+
return await dynamic_fields_1.dynamicMediaUrls(request, payload);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
contentVariables: {
|
|
32
|
+
__keys__: async (request, { payload }) => {
|
|
33
|
+
return await dynamic_fields_1.dynamicContentVariables(request, payload);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
perform: async (request, { payload, settings }) => {
|
|
38
|
+
return await utils_1.send(request, payload, settings);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.default = action;
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/twilio-messaging/sendMessage/index.ts"],"names":[],"mappings":";;AAGA,qCAAiC;AACjC,qDAQyB;AACzB,mCAA8B;AAE9B,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,cAAc;IACrB,WAAW,EAAE,uCAAuC;IACpD,MAAM,EAAN,eAAM;IACN,aAAa,EAAE;QACb,UAAU,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACnC,OAAO,MAAM,kCAAiB,CAAC,OAAO,CAAC,CAAA;QACzC,CAAC;QACD,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;YACxD,OAAO,MAAM,uCAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QACjE,CAAC;QACD,mBAAmB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;YACnD,OAAO,MAAM,2CAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC5D,CAAC;QACD,mBAAmB,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YAC5C,OAAO,MAAM,2CAA0B,CAAC,OAAO,CAAC,CAAA;QAClD,CAAC;QACD,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACzC,OAAO,MAAM,kCAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAClD,CAAC;QACD,SAAS,EAAE;YACT,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;gBAClC,OAAO,MAAM,iCAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YACjD,CAAC;SACF;QACD,gBAAgB,EAAE;YAChB,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;gBACvC,OAAO,MAAM,wCAAuB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YACxD,CAAC;SACF;KACF;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;QAChD,OAAO,MAAM,YAAI,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PREDEFINED_CONTENT_TYPES, CHANNELS } from './constants';
|
|
2
|
+
export declare type TwilioPayload = {
|
|
3
|
+
To: string;
|
|
4
|
+
SendAt?: string;
|
|
5
|
+
ValidityPeriod?: number;
|
|
6
|
+
MediaUrl?: string[];
|
|
7
|
+
} & Sender & Content;
|
|
8
|
+
export declare type Sender = FromPhone | FromMessagingService;
|
|
9
|
+
declare type FromMessagingService = {
|
|
10
|
+
MessagingServiceSid: string;
|
|
11
|
+
};
|
|
12
|
+
declare type FromPhone = {
|
|
13
|
+
From: string;
|
|
14
|
+
};
|
|
15
|
+
export declare type Content = ContentTemplateMessage | InlineMessage;
|
|
16
|
+
declare type ContentTemplateMessage = {
|
|
17
|
+
ContentSid: string;
|
|
18
|
+
ContentVariables?: string;
|
|
19
|
+
};
|
|
20
|
+
declare type InlineMessage = {
|
|
21
|
+
Body: string;
|
|
22
|
+
};
|
|
23
|
+
export declare type PredefinedContentTypes = {
|
|
24
|
+
[key: string]: PredefinedContentTypeItem;
|
|
25
|
+
};
|
|
26
|
+
export declare type Channel = typeof CHANNELS[keyof typeof CHANNELS];
|
|
27
|
+
export declare type PredefinedContentTypeItem = {
|
|
28
|
+
friendly_name: string;
|
|
29
|
+
name: string;
|
|
30
|
+
supports_media: boolean;
|
|
31
|
+
supported_channels: Array<Channel>;
|
|
32
|
+
};
|
|
33
|
+
export declare type ContentTypeName = typeof PREDEFINED_CONTENT_TYPES[keyof typeof PREDEFINED_CONTENT_TYPES]['name'];
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/destinations/twilio-messaging/sendMessage/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RequestClient } from '@segment/actions-core';
|
|
2
|
+
import { Payload } from './generated-types';
|
|
3
|
+
import { Settings } from '../generated-types';
|
|
4
|
+
export declare function send(request: RequestClient, payload: Payload, settings: Settings): Promise<import("@segment/actions-core").ModifiedResponse<unknown>>;
|
|
5
|
+
export declare function parseFieldValue(value: string | undefined | null): string | undefined;
|
|
6
|
+
export declare function validateContentSid(contentSid: string): boolean;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateContentSid = exports.parseFieldValue = exports.send = void 0;
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
async function send(request, payload, settings) {
|
|
7
|
+
let { toPhoneNumber, fromPhoneNumber, fromMessengerSenderId, messagingServiceSid, contentSid } = payload;
|
|
8
|
+
const { channel, senderType, toMessengerPageUserId, contentTemplateType, contentVariables, inlineBody, inlineVariables, validityPeriod, sendAt, mediaUrls, inlineMediaUrls } = payload;
|
|
9
|
+
const getTo = () => {
|
|
10
|
+
switch (channel) {
|
|
11
|
+
case 'SMS':
|
|
12
|
+
case 'MMS': {
|
|
13
|
+
toPhoneNumber = toPhoneNumber?.trim() ?? '';
|
|
14
|
+
if (!(constants_1.E164_REGEX.test(toPhoneNumber) || constants_1.TWILIO_SHORT_CODE_REGEX.test(toPhoneNumber))) {
|
|
15
|
+
throw new actions_core_1.PayloadValidationError("'To' field should be a valid phone number in E.164 format or a Twilio Short Code");
|
|
16
|
+
}
|
|
17
|
+
return toPhoneNumber;
|
|
18
|
+
}
|
|
19
|
+
case 'Whatsapp': {
|
|
20
|
+
toPhoneNumber = toPhoneNumber?.trim() ?? '';
|
|
21
|
+
if (!constants_1.E164_REGEX.test(toPhoneNumber)) {
|
|
22
|
+
throw new actions_core_1.PayloadValidationError("'To' field should be a valid phone number in E.164 format");
|
|
23
|
+
}
|
|
24
|
+
return `whatsapp:${toPhoneNumber}`;
|
|
25
|
+
}
|
|
26
|
+
case 'Messenger': {
|
|
27
|
+
if (!toMessengerPageUserId) {
|
|
28
|
+
throw new actions_core_1.PayloadValidationError("'Messenger Page or User ID' field is required when Channel field set to 'Messenger'");
|
|
29
|
+
}
|
|
30
|
+
return `messenger:${toMessengerPageUserId.trim()}`;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
throw new actions_core_1.PayloadValidationError('Unsupported Channel');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const getSendAt = () => (sendAt ? { SendAt: sendAt } : {});
|
|
38
|
+
const getValidityPeriod = () => (validityPeriod ? { ValidityPeriod: validityPeriod } : {});
|
|
39
|
+
const getSender = () => {
|
|
40
|
+
if (senderType === constants_1.SENDER_TYPE.PHONE_NUMBER) {
|
|
41
|
+
fromPhoneNumber = fromPhoneNumber?.trim();
|
|
42
|
+
if (!fromPhoneNumber) {
|
|
43
|
+
throw new actions_core_1.PayloadValidationError("'From Phone Number' field is required when sending from a phone number.");
|
|
44
|
+
}
|
|
45
|
+
if (!constants_1.E164_REGEX.test(fromPhoneNumber)) {
|
|
46
|
+
throw new actions_core_1.PayloadValidationError("'From' field should be a valid phone number in E.164 format");
|
|
47
|
+
}
|
|
48
|
+
return channel === constants_1.CHANNELS.WHATSAPP ? { From: `whatsapp:${fromPhoneNumber}` } : { From: fromPhoneNumber };
|
|
49
|
+
}
|
|
50
|
+
if (senderType === constants_1.SENDER_TYPE.MESSENGER_SENDER_ID) {
|
|
51
|
+
fromMessengerSenderId = fromMessengerSenderId?.trim();
|
|
52
|
+
if (!fromMessengerSenderId) {
|
|
53
|
+
throw new actions_core_1.PayloadValidationError("'From Messenger Sender ID' field is required when sending from a Messenger Sender ID.");
|
|
54
|
+
}
|
|
55
|
+
return { From: `messenger:${fromMessengerSenderId}` };
|
|
56
|
+
}
|
|
57
|
+
if (senderType === constants_1.SENDER_TYPE.MESSAGING_SERVICE) {
|
|
58
|
+
messagingServiceSid = parseFieldValue(messagingServiceSid);
|
|
59
|
+
if (!messagingServiceSid) {
|
|
60
|
+
throw new actions_core_1.PayloadValidationError("'Messaging Service SID' field is required when 'Choose Sender' field = Messaging Service SID");
|
|
61
|
+
}
|
|
62
|
+
if (!constants_1.MESSAGING_SERVICE_SID_REGEX.test(messagingServiceSid ?? '')) {
|
|
63
|
+
throw new actions_core_1.PayloadValidationError("'Messaging Service SID' field value should start with 'MG' followed by 32 hexadecimal characters, totaling 34 characters.");
|
|
64
|
+
}
|
|
65
|
+
return { MessagingServiceSid: messagingServiceSid };
|
|
66
|
+
}
|
|
67
|
+
throw new actions_core_1.PayloadValidationError('Unsupported Sender Type');
|
|
68
|
+
};
|
|
69
|
+
const getContent = () => {
|
|
70
|
+
contentSid = parseFieldValue(contentSid);
|
|
71
|
+
if (contentSid && !constants_1.CONTENT_SID_REGEX.test(contentSid)) {
|
|
72
|
+
throw new actions_core_1.PayloadValidationError("Content SID should start with 'HX' followed by 32 hexadecimal characters.");
|
|
73
|
+
}
|
|
74
|
+
if (contentTemplateType === constants_1.INLINE_CONTENT_TYPES.INLINE.friendly_name && inlineBody) {
|
|
75
|
+
return { Body: encodeURIComponent(replaceTokens(inlineBody, inlineVariables)) };
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return {
|
|
79
|
+
ContentSid: contentSid,
|
|
80
|
+
...(Object.keys(contentVariables ?? {}).length > 0 && { ContentVariables: JSON.stringify(contentVariables) })
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const getMediaUrl = () => {
|
|
85
|
+
const supportsMedia = Object.values(constants_1.ALL_CONTENT_TYPES).find((type) => type.supports_media);
|
|
86
|
+
if (supportsMedia) {
|
|
87
|
+
const urls = contentTemplateType === constants_1.ALL_CONTENT_TYPES.INLINE.friendly_name
|
|
88
|
+
? inlineMediaUrls
|
|
89
|
+
?.filter((item) => item.trim() !== '')
|
|
90
|
+
.map((item) => replaceTokens(item.trim(), inlineVariables)) ?? []
|
|
91
|
+
: mediaUrls?.map((item) => item.url.trim()) ?? [];
|
|
92
|
+
if (urls.length > 10) {
|
|
93
|
+
throw new actions_core_1.PayloadValidationError('Media URL cannot contain more than 10 URLs');
|
|
94
|
+
}
|
|
95
|
+
urls
|
|
96
|
+
.filter((url) => url.trim() !== '')
|
|
97
|
+
.some((url) => {
|
|
98
|
+
try {
|
|
99
|
+
new URL(url);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
throw new actions_core_1.PayloadValidationError(`Media URL ${url} is not a valid URL.`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return urls.length > 0 ? { MediaUrl: urls } : {};
|
|
107
|
+
}
|
|
108
|
+
return {};
|
|
109
|
+
};
|
|
110
|
+
const twilioPayload = (() => ({
|
|
111
|
+
To: getTo(),
|
|
112
|
+
...getSendAt(),
|
|
113
|
+
...getValidityPeriod(),
|
|
114
|
+
...getSender(),
|
|
115
|
+
...getContent(),
|
|
116
|
+
...getMediaUrl()
|
|
117
|
+
}))();
|
|
118
|
+
const encodedBody = encode(twilioPayload);
|
|
119
|
+
return await request(constants_1.SEND_SMS_URL.replace(constants_1.ACCOUNT_SID_TOKEN, settings.accountSID), {
|
|
120
|
+
method: 'post',
|
|
121
|
+
body: encodedBody
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
exports.send = send;
|
|
125
|
+
function parseFieldValue(value) {
|
|
126
|
+
if (!value) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const match = constants_1.FIELD_REGEX.exec(value);
|
|
130
|
+
return match ? match[1] : value;
|
|
131
|
+
}
|
|
132
|
+
exports.parseFieldValue = parseFieldValue;
|
|
133
|
+
function replaceTokens(str, tokens) {
|
|
134
|
+
return str.replace(constants_1.TOKEN_REGEX, (_, key) => String(tokens?.[key] ?? ''));
|
|
135
|
+
}
|
|
136
|
+
function encode(twilioPayload) {
|
|
137
|
+
const encodedSmsBody = new URLSearchParams();
|
|
138
|
+
Object.entries(twilioPayload).forEach(([key, value]) => {
|
|
139
|
+
if (key === 'MediaUrl' && Array.isArray(value)) {
|
|
140
|
+
value.forEach((url) => {
|
|
141
|
+
encodedSmsBody.append(`MediaUrl`, url);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
encodedSmsBody.append(key, String(value));
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return encodedSmsBody.toString();
|
|
149
|
+
}
|
|
150
|
+
function validateContentSid(contentSid) {
|
|
151
|
+
return /^HX[0-9a-fA-F]{32}$/.test(contentSid);
|
|
152
|
+
}
|
|
153
|
+
exports.validateContentSid = validateContentSid;
|
|
154
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/destinations/twilio-messaging/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,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;SAC1C;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAA;AAClC,CAAC;AACD,SAAgB,kBAAkB,CAAC,UAAkB;IACnD,OAAO,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAC/C,CAAC;AAFD,gDAEC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segment/action-destinations",
|
|
3
3
|
"description": "Destination Actions engine and definitions.",
|
|
4
|
-
"version": "3.345.
|
|
4
|
+
"version": "3.345.6-staging",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/segmentio/action-destinations",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"__tests__/__helpers__/"
|
|
89
89
|
]
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "9c04e12c4a0e81f6b68dca0a297fb2c0209d2431"
|
|
92
92
|
}
|