diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..7665bc7 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "@activepieces/piece-contiguity", + "version": "0.1.13", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@activepieces/piece-contiguity", + "version": "0.1.13" + } + } +} diff --git a/package.json b/package.json index fcb1b80..022dac6 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { "name": "@activepieces/piece-contiguity", - "version": "0.1.12" + "version": "0.1.13" } diff --git a/src/index.ts b/src/index.ts index 4924eaf..4d84725 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,29 +5,29 @@ import { sendText } from './lib/actions/send/text'; import { send_iMessage } from './lib/actions/send/imessage'; export const contiguityAuth = PieceAuth.SecretText({ - displayName: 'API Key', - required: true, - description: 'Authenticate with the Contiguity API using a revocable key. Create one at console.contiguity.com/dashboard/tokens', + displayName: 'API Key', + required: true, + description: 'Authenticate with the Contiguity API using a revocable key. Create one at console.contiguity.com/dashboard/tokens', }); export const contiguity = createPiece({ - displayName: 'Contiguity', - description: 'Communications for what you\'re building', - auth: contiguityAuth, - minimumSupportedRelease: '0.30.0', - logoUrl: 'https://cdn.activepieces.com/pieces/contiguity.png', - authors: ["Owlcept", "Ozak93", "kishanprmr", "MoShizzle", "abuaboud", "Contiguity"], - categories: [PieceCategory.MARKETING], - actions: [ - sendText, - send_iMessage, - createCustomApiCallAction({ + displayName: 'Contiguity', + description: 'Communications for what you\'re building', + auth: contiguityAuth, + minimumSupportedRelease: '0.30.0', + logoUrl: 'https://cdn.activepieces.com/pieces/contiguity.png', + authors: ["Owlcept","Ozak93","kishanprmr","MoShizzle","abuaboud","Contiguity"], + categories: [PieceCategory.MARKETING], + actions: [ + sendText, + send_iMessage, + createCustomApiCallAction({ baseUrl: () => 'https://api.contiguity.com', auth: contiguityAuth, authMapping: async (auth) => ({ authorization: `Bearer ${auth}`, }), - }), - ], - triggers: [], + }), + ], + triggers: [], }); diff --git a/src/lib/actions/send/imessage.ts b/src/lib/actions/send/imessage.ts index 15b341a..9c7dbde 100644 --- a/src/lib/actions/send/imessage.ts +++ b/src/lib/actions/send/imessage.ts @@ -4,6 +4,7 @@ import { } from '@activepieces/pieces-common'; import { contiguityAuth } from '../../..'; import { + InputPropertyMap, Property, createAction, } from '@activepieces/pieces-framework'; @@ -31,25 +32,45 @@ export const send_iMessage = createAction({ description: 'iMessage content', required: true, }), - fallback: Property.Object({ + fallback: Property.Checkbox({ displayName: 'SMS/RCS Fallback', description: 'Fallback to SMS/RCS when iMessage fails or unsupported', required: false, - properties: { - when: Property.MultiSelectDropdown({ - displayName: 'When to Fallback', - description: 'Conditions that trigger SMS/RCS fallback', - required: true, - options: [ - { label: 'iMessage Unsupported', value: 'imessage_unsupported' }, - { label: 'iMessage Fails', value: 'imessage_fails' }, - ], - }), - from: Property.ShortText({ - displayName: 'Fallback From Number', - description: 'SMS/RCS number for fallback', - required: false, - }), + defaultValue: false, + }), + fallback_when: Property.DynamicProperties({ + displayName: "When to fallback", + description: 'Conditions that trigger SMS/RCS fallback', + required: true, + refreshers: ['fallback'], + props: async (propsValue): Promise => { + const fallback = propsValue['fallback'] as unknown as boolean; + + if (!fallback){ + return{} + } + + if (fallback){ + return{ + when: Property.StaticMultiSelectDropdown({ + displayName: "When to fallback", + description: "Conditions that trigger SMS/RCS fallback", + required: true, + options: { + options:[ + { label: 'iMessage Unsupported', value: 'imessage_unsupported' }, + { label: 'iMessage Fails', value: 'imessage_fails' }, + ] + } + }), + from: Property.ShortText({ + displayName: 'Fallback From Number', + description: 'SMS/RCS number for fallback', + required: false, + }), + }; + } + return{}; }, }), attachments: Property.Array({ @@ -83,14 +104,13 @@ export const send_iMessage = createAction({ ).max(10, 'Maximum 10 attachments').optional(), }); - const { to, from, message, fallback, attachments } = context.propsValue; + const { to, from, message, attachments } = context.propsValue; const body: any = { to, message }; if (from) body.from = from; - if (fallback) body.fallback = fallback; if (attachments?.length) { - body.attachments = attachments.map(attachment => attachment.url); + body.attachments = attachments.map(attachment => (attachment as {url: string}).url); } return await _fetch({ diff --git a/src/lib/actions/send/text.ts b/src/lib/actions/send/text.ts index eec7a89..3f3647a 100644 --- a/src/lib/actions/send/text.ts +++ b/src/lib/actions/send/text.ts @@ -67,10 +67,9 @@ export const sendText = createAction({ const { to, from, message, attachments } = context.propsValue; const body: any = { to, message }; - if (from) body.from = from; if (attachments?.length) { - body.attachments = attachments.map(attachment => attachment.url); + body.attachments = attachments.map(attachment => (attachment as {url: string}).url); } return await _fetch({