-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Twilio Messaging] - new Twilio Messaging Destination (#2612)
* Twilio Messaging init * updates * saving progress * saving progress * saving progress * adding field UI dependencies * minor refactor * after some initial testing * refactoring dynamic functions * refactoring * refactoring * saving progress * saving progress * saving progress * spelling correction * renaming Action and removing tests for now * removing console logs * fixing typing issue
- Loading branch information
1 parent
eee15fa
commit 0904d4e
Showing
14 changed files
with
1,123 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/destination-actions/src/destinations/twilio-messaging/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('Twilio Messaging', () => { | ||
describe('testAuthentication', () => { | ||
it('should pass', () => { | ||
expect(true).toBe(true) | ||
}) | ||
}) | ||
}) |
20 changes: 20 additions & 0 deletions
20
packages/destination-actions/src/destinations/twilio-messaging/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
packages/destination-actions/src/destinations/twilio-messaging/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { DestinationDefinition } from '@segment/actions-core' | ||
import type { Settings } from './generated-types' | ||
|
||
import sendMessage from './sendMessage' | ||
|
||
const destination: DestinationDefinition<Settings> = { | ||
name: 'Twilio Messaging', | ||
slug: 'actions-twilio-messaging', | ||
mode: 'cloud', | ||
description: 'Send SMS, MMS, Whatsapp and Messenger messages with Twilio', | ||
authentication: { | ||
scheme: 'basic', | ||
fields: { | ||
accountSID: { | ||
label: 'Twilio Account SID', | ||
description: 'Twilio Account SID', | ||
type: 'string', | ||
required: true | ||
}, | ||
apiKeySID: { | ||
label: 'Twilio API Key SID', | ||
description: 'Twilio API Key SID', | ||
type: 'string', | ||
required: true | ||
}, | ||
apiKeySecret: { | ||
label: 'Twilio API Key Secret', | ||
description: 'Twilio API Key Secret', | ||
type: 'password', | ||
required: true | ||
}, | ||
region: { | ||
label: 'Region', | ||
description: 'The region where the message is originating from', | ||
type: 'string', | ||
choices: [ | ||
{ value: 'us-west-2', label: 'US West 2' }, | ||
{ value: 'eu-west-1', label: 'EU West 1' } | ||
], | ||
default: 'us-west-2', | ||
required: true | ||
} | ||
}, | ||
testAuthentication: (request) => { | ||
return request(`https://api.twilio.com/2010-04-01`) | ||
} | ||
}, | ||
extendRequest: ({ settings }) => { | ||
return { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
username: settings.apiKeySID, | ||
password: settings.apiKeySecret | ||
} | ||
}, | ||
actions: { | ||
sendMessage | ||
} | ||
} | ||
|
||
export default destination |
8 changes: 8 additions & 0 deletions
8
...destination-actions/src/destinations/twilio-messaging/sendMessage/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
describe('TwilioMessaging.sendMessage', () => { | ||
// TODO: Implement tests | ||
it('should pass', () => { | ||
expect(true).toBe(true) | ||
}) | ||
}) |
110 changes: 110 additions & 0 deletions
110
packages/destination-actions/src/destinations/twilio-messaging/sendMessage/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { PredefinedContentTypes } from './types' | ||
|
||
export const CONTENT_SID_TOKEN = '{accountSid}' | ||
|
||
export const ACCOUNT_SID_TOKEN = '{accountSid}' | ||
|
||
export const SEND_SMS_URL = `https://api.twilio.com/2010-04-01/Accounts/${ACCOUNT_SID_TOKEN}/Messages.json` | ||
|
||
export const FIELD_REGEX = /\[(.*?)\]/ | ||
|
||
export const TOKEN_REGEX = /{{(.*?)}}/g | ||
|
||
export const E164_REGEX = /^\+?[1-9]\d{1,14}$/ | ||
|
||
export const MESSAGING_SERVICE_SID_REGEX = /^MG[0-9a-fA-F]{32}$/ | ||
|
||
export const CONTENT_SID_REGEX = /^HX[0-9a-fA-F]{32}$/ | ||
|
||
export const GET_INCOMING_PHONE_NUMBERS_URL = `https://api.twilio.com/2010-04-01/Accounts/${ACCOUNT_SID_TOKEN}/IncomingPhoneNumbers.json?PageSize=1000` | ||
|
||
export const GET_MESSAGING_SERVICE_SIDS_URL = 'https://messaging.twilio.com/v1/Services?PageSize=1000' | ||
|
||
export const GET_ALL_CONTENTS_URL = 'https://content.twilio.com/v1/Content?PageSize=1000' | ||
|
||
export const GET_CONTENT_URL = `https://content.twilio.com/v1/Content/${CONTENT_SID_TOKEN}` | ||
|
||
export const GET_CONTENT_VARIABLES_URL = `https://content.twilio.com/v1/Content/${CONTENT_SID_TOKEN}` | ||
|
||
export const CHANNELS = { | ||
SMS: 'SMS', | ||
MMS: 'MMS', | ||
WHATSAPP: 'Whatsapp', | ||
MESSENGER: 'Messenger' | ||
} as const | ||
|
||
export const PREDEFINED_CONTENT_TYPES: PredefinedContentTypes = { | ||
TEXT: { | ||
friendly_name: 'Text', | ||
name: 'twilio/text', | ||
supports_media: false, | ||
supported_channels: [CHANNELS.SMS, CHANNELS.WHATSAPP, CHANNELS.MESSENGER] | ||
}, | ||
MEDIA: { | ||
friendly_name: 'Media', | ||
name: 'twilio/media', | ||
supports_media: true, | ||
supported_channels: [CHANNELS.MMS, CHANNELS.WHATSAPP, CHANNELS.MESSENGER] | ||
}, | ||
QUICK_REPLY: { | ||
friendly_name: 'Quick Reply', | ||
name: 'twilio/quick-reply', | ||
supports_media: false, | ||
supported_channels: [CHANNELS.WHATSAPP, CHANNELS.MESSENGER] | ||
}, | ||
CALL_TO_ACTION: { | ||
friendly_name: 'Call to Action', | ||
name: 'twilio/call-to-action', | ||
supports_media: false, | ||
supported_channels: [CHANNELS.WHATSAPP, CHANNELS.MESSENGER] | ||
}, | ||
LIST_PICKER: { | ||
friendly_name: 'List Picker', | ||
name: 'twilio/list-picker', | ||
supports_media: false, | ||
supported_channels: [CHANNELS.WHATSAPP] | ||
}, | ||
CARD: { | ||
friendly_name: 'Card', | ||
name: 'twilio/card', | ||
supports_media: true, | ||
supported_channels: [CHANNELS.WHATSAPP, CHANNELS.MESSENGER] | ||
}, | ||
WHATSAPP_CARD: { | ||
friendly_name: 'WhatsApp Card', | ||
name: 'whatsapp/card', | ||
supports_media: true, | ||
supported_channels: [CHANNELS.WHATSAPP] | ||
}, | ||
WHATSAPP_AUTHENTICATION: { | ||
friendly_name: 'WhatsApp Authentication', | ||
name: 'whatsapp/authentication', | ||
supports_media: false, | ||
supported_channels: [CHANNELS.WHATSAPP] | ||
}, | ||
CATALOG: { | ||
friendly_name: 'Catalog', | ||
name: 'twilio/catalog', | ||
supports_media: false, | ||
supported_channels: [CHANNELS.WHATSAPP] | ||
} | ||
} | ||
|
||
export const INLINE_CONTENT_TYPES = { | ||
INLINE: { | ||
friendly_name: 'Inline', | ||
name: undefined, | ||
supports_media: true, | ||
supported_channels: [CHANNELS.SMS, CHANNELS.MMS, CHANNELS.WHATSAPP, CHANNELS.MESSENGER] | ||
} | ||
} | ||
|
||
export const ALL_CONTENT_TYPES = { | ||
...PREDEFINED_CONTENT_TYPES, | ||
...INLINE_CONTENT_TYPES | ||
} | ||
|
||
export const SENDER_TYPE = { | ||
PHONE_NUMBER: 'Phone number', | ||
MESSAGING_SERVICE: 'Messaging Service' | ||
} |
Oops, something went wrong.