Merge pull request #955 from s-schumann/feature/signalwire-integration

feat: add Signalwire integration
This commit is contained in:
Ali BARIN
2023-03-14 09:26:30 +01:00
committed by GitHub
23 changed files with 386 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
import sendSms from './send-sms';
export default [sendSms];

View File

@@ -0,0 +1,63 @@
import defineAction from '../../../../helpers/define-action';
export default defineAction({
name: 'Send an SMS',
key: 'sendSms',
description: 'Sends an SMS',
arguments: [
{
label: 'From Number',
key: 'fromNumber',
type: 'dropdown' as const,
required: true,
description:
'The number to send the SMS from. Include only country code. Example: 491234567890',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listIncomingPhoneNumbers',
},
],
},
},
{
label: 'To Number',
key: 'toNumber',
type: 'string' as const,
required: true,
description:
'The number to send the SMS to. Include only country code. Example: 491234567890',
variables: true,
},
{
label: 'Message',
key: 'message',
type: 'string' as const,
required: true,
description: 'The content of the message.',
variables: true,
},
],
async run($) {
const requestPath = `/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}/Messages`;
const Body = $.step.parameters.message;
const From = $.step.parameters.fromNumber;
const To = '+' + ($.step.parameters.toNumber as string).trim();
const response = await $.http.post(requestPath, null, {
params: {
Body,
From,
To,
}
});
$.setActionItem({ raw: response.data });
},
});

View File

@@ -0,0 +1 @@
<svg id="a1100050-5390-497e-a7fa-2bb69ec95c7c" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 318.33 362.7"><defs><style>.a463a3b0-e95c-44d7-b809-5997966784eb{fill:#044ef4;}.b59fade4-5c2c-49f1-a6bf-917d1f195a19{fill:#f72a72;}</style></defs><path class="a463a3b0-e95c-44d7-b809-5997966784eb" d="M389.17,278c0,10.31-2.8,17.06-8.37,22.62q-50.07,49.95-100.19,99.85C269,412,252.06,412.54,240.55,402c-12.12-11.13-12.6-29.39-.75-41.47,15-15.34,30.32-30.47,45.56-45.63q27.47-27.3,55.06-54.45c8.91-8.75,20.84-11.07,31.77-6.1C383.3,259.36,388.79,268.25,389.17,278Z" transform="translate(-70.83 -46.81)"/><path class="a463a3b0-e95c-44d7-b809-5997966784eb" d="M70.84,172.94c.16-5.21,2.93-11.81,8.36-17.24q49.89-49.77,99.8-99.53c6.92-6.91,15.08-10.45,24.83-9.06,11.55,1.65,19.62,8.12,23.38,19.22s1.16,21.14-7,29.43q-23.87,24.21-48,48.1-26.22,26.07-52.58,52c-8.93,8.76-20.84,10.92-31.8,6.13C77.17,197.35,70.65,187.14,70.84,172.94Z" transform="translate(-70.83 -46.81)"/><path class="b59fade4-5c2c-49f1-a6bf-917d1f195a19" d="M93.68,210.69c3.79-.17,6.91-.08,10-.49a34.39,34.39,0,0,0,20.56-10.34c6.38-6.52,12.79-13,19.33-19.66,1.23,1.09,2,1.7,2.66,2.38q36.92,36.9,73.81,73.83c8.07,8.1,10.9,17.87,7.66,28.86-3.12,10.58-10.39,17.35-21.17,19.77-9.33,2.1-18.23.31-25.07-6.47C152.25,269.64,123.32,240.42,93.68,210.69Z" transform="translate(-70.83 -46.81)"/><path class="b59fade4-5c2c-49f1-a6bf-917d1f195a19" d="M366.57,246c-15-1.53-25.7,4.26-34.72,14.22-4.89,5.4-10.23,10.39-15.51,15.69-1.1-1-1.86-1.59-2.56-2.28q-36.94-36.93-73.86-73.89c-8.07-8.1-10.89-17.89-7.56-28.89,3.19-10.56,10.47-17.31,21.28-19.68,9.56-2.1,18.45,0,25.44,6.92q43,42.57,85.61,85.47C365.12,244,365.44,244.54,366.57,246Z" transform="translate(-70.83 -46.81)"/></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,65 @@
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
export default {
fields: [
{
key: 'accountSid',
label: 'Project ID',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'Log into your SignalWire account and find the Project ID',
clickToCopy: false,
},
{
key: 'authToken',
label: 'API Token',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'API Token in the respective project',
clickToCopy: false,
},
{
key: 'spaceRegion',
label: 'SignalWire Region',
type: 'dropdown' as const,
required: true,
readOnly: false,
value: '',
placeholder: null,
description: 'Most people should choose the default, "US"',
clickToCopy: false,
options: [
{
label: 'US',
value: '',
},
{
label: 'EU',
value: 'eu-',
},
],
},
{
key: 'spaceName',
label: 'Space Name',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'Name of your SignalWire space that contains the project',
clickToCopy: false,
},
],
verifyCredentials,
isStillVerified,
};

View File

@@ -0,0 +1,10 @@
import { IGlobalVariable } from '@automatisch/types';
import verifyCredentials from './verify-credentials';
const isStillVerified = async ($: IGlobalVariable) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -0,0 +1,11 @@
import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => {
const { data } = await $.http.get(`/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}`);
await $.auth.set({
screenName: `${data.friendly_name} (${$.auth.data.accountSid})`,
});
};
export default verifyCredentials;

View File

@@ -0,0 +1,27 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
const authData = $.auth.data || {};
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
if (
authData.accountSid &&
authData.authToken
) {
requestConfig.auth = {
username: authData.accountSid as string,
password: authData.authToken as string,
};
}
if (authData.spaceName) {
const serverUrl = `https://${authData.spaceName}.${authData.spaceRegion}signalwire.com`;
requestConfig.baseURL = serverUrl as string;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -0,0 +1,3 @@
import listIncomingPhoneNumbers from './list-incoming-phone-numbers';
export default [listIncomingPhoneNumbers];

View File

@@ -0,0 +1,57 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
type TAggregatedResponse = {
data: IJSONObject[];
error?: IJSONObject;
};
type TResponse = {
incoming_phone_numbers: TIncomingPhoneNumber[];
next_page_uri: string;
};
type TIncomingPhoneNumber = {
capabilities: {
sms: boolean;
};
sid: string;
friendly_name: string;
phone_number: string;
};
export default {
name: 'List incoming phone numbers',
key: 'listIncomingPhoneNumbers',
async run($: IGlobalVariable) {
let requestPath = `/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}/IncomingPhoneNumbers`;
const aggregatedResponse: TAggregatedResponse = {
data: [],
};
do {
const { data } = await $.http.get<TResponse>(requestPath);
const smsCapableIncomingPhoneNumbers = data.incoming_phone_numbers
.filter((incomingPhoneNumber) => {
return incomingPhoneNumber.capabilities.sms;
})
.map((incomingPhoneNumber) => {
const friendlyName = incomingPhoneNumber.friendly_name;
const phoneNumber = incomingPhoneNumber.phone_number;
const name = [friendlyName, phoneNumber].filter(Boolean).join(' - ');
return {
value: phoneNumber,
name,
};
})
aggregatedResponse.data.push(...smsCapableIncomingPhoneNumbers)
requestPath = data.next_page_uri;
} while (requestPath);
return aggregatedResponse;
},
};

View File

View File

@@ -0,0 +1,22 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import triggers from './triggers';
import actions from './actions';
import dynamicData from './dynamic-data';
export default defineApp({
name: 'SignalWire',
key: 'signalwire',
iconUrl: '{BASE_URL}/apps/signalwire/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/apps/signalwire/connection',
supportsConnections: true,
baseUrl: 'https://signalwire.com',
apiBaseUrl: '',
primaryColor: '044cf6',
beforeRequest: [addAuthHeader],
auth,
triggers,
actions,
dynamicData,
});

View File

@@ -0,0 +1,3 @@
import receiveSms from './receive-sms';
export default [receiveSms];

View File

@@ -0,0 +1,27 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
const fetchMessages = async ($: IGlobalVariable) => {
const toNumber = $.step.parameters.toNumber as string;
let response;
let requestPath = `/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}/Messages?To=${toNumber}`;
do {
response = await $.http.get(requestPath);
response.data.messages.forEach((message: IJSONObject) => {
const dataItem = {
raw: message,
meta: {
internalId: message.date_sent as string,
},
};
$.pushTriggerItem(dataItem);
});
requestPath = response.data.next_page_uri;
} while (requestPath);
};
export default fetchMessages;

View File

@@ -0,0 +1,33 @@
import defineTrigger from '../../../../helpers/define-trigger';
import fetchMessages from './fetch-messages';
export default defineTrigger({
name: 'Receive SMS',
key: 'receiveSms',
pollInterval: 15,
description: 'Triggers when a new SMS is received.',
arguments: [
{
label: 'To Number',
key: 'toNumber',
type: 'dropdown',
required: true,
description:
'The number to receive the SMS on. It should be a SignalWire number in your project.',
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listIncomingPhoneNumbers',
},
],
},
},
],
async run($) {
await fetchMessages($);
},
});

View File

@@ -17,7 +17,9 @@ const createFlow = async (
const connectionId = params?.input?.connectionId;
const appKey = params?.input?.triggerAppKey;
if (appKey) {
await App.findOneByKey(appKey);
}
const flow = await context.currentUser.$relatedQuery('flows').insert({
name: 'Name your flow',

View File

@@ -40,6 +40,8 @@ class App {
static async checkAppAndAction(appKey: string, actionKey: string): Promise<void> {
const app = await this.findOneByKey(appKey);
if (!actionKey) return;
const hasAction = app.actions?.find(action => action.key === actionKey);
if (!hasAction) {
@@ -50,6 +52,8 @@ class App {
static async checkAppAndTrigger(appKey: string, triggerKey: string): Promise<void> {
const app = await this.findOneByKey(appKey);
if (!triggerKey) return;
const hasTrigger = app.triggers?.find(trigger => trigger.key === triggerKey);
if (!hasTrigger) {

View File

@@ -133,6 +133,16 @@ export default defineConfig({
{ text: 'Connection', link: '/apps/scheduler/connection' },
],
},
{
text: 'SignalWire',
collapsible: true,
collapsed: true,
items: [
{ text: 'Triggers', link: '/apps/signalwire/triggers' },
{ text: 'Actions', link: '/apps/signalwire/actions' },
{ text: 'Connection', link: '/apps/signalwire/connection' },
],
},
{
text: 'Slack',
collapsible: true,

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/signalwire.svg
items:
- name: Send an SMS
desc: Sends an SMS
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -0,0 +1,16 @@
# SignalWire
:::info
This page explains the steps you need to follow to set up a SignalWire connection in Automatisch. If any of the steps are outdated, please let us know!
:::
1. Go to the SignalWire API page in your respective project (https://{space}.signalwire.com/credentials)
2. Copy **Project ID** and paste it to the **Project ID** field on the
Automatisch connection creation page.
3. Create/Copy **API Token** and paste it to the **API Token** field on the
Automatisch connection creation page.
4. Select your **Region** (US for most users).
5. Provide your **Space Name** from the URL and paste it to the **Space NAME** field on the
Automatisch connection creation page.
6. Click **Submit** button on Automatisch.
7. Now you can start using the new SignalWire connection!

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/signalwire.svg
items:
- name: Receive SMS
desc: Triggers when a new SMS is received.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -33,6 +33,7 @@ The build integrations section is best understood when read from beginning to en
- [DeepL](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/deepl/auth/index.ts)
- [Twilio](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/twilio/auth/index.ts)
- [SignalWire](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/signalwire/auth/index.ts)
- [SMTP](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/smtp/auth/index.ts)
### Without authentication
@@ -60,6 +61,7 @@ If you are developing a webhook-based trigger, you need to ensure that the webho
- [Search tweets - Twitter](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/twitter/triggers/search-tweets/index.ts)
- [New issues - Github](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/github/triggers/new-issues/index.ts)
- [Receive SMS - Twilio](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/twilio/triggers/receive-sms/index.ts)
- [Receive SMS - SignalWire](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/signalwire/triggers/receive-sms/index.ts)
- [New photos - Flickr](https://github.com/automatisch/automatisch/tree/main/packages/backend/src/apps/flickr/triggers/new-photos/index.ts)
### Pagination with ascending order

View File

@@ -17,6 +17,7 @@ Following integrations are currently supported by Automatisch.
- [RSS](/apps/rss/triggers)
- [Salesforce](/apps/salesforce/triggers)
- [Scheduler](/apps/scheduler/triggers)
- [SignalWire](/apps/signalwire/triggers)
- [Slack](/apps/slack/actions)
- [SMTP](/apps/smtp/actions)
- [Stripe](/apps/stripe/triggers)

View File

@@ -0,0 +1 @@
<svg id="a1100050-5390-497e-a7fa-2bb69ec95c7c" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 318.33 362.7"><defs><style>.a463a3b0-e95c-44d7-b809-5997966784eb{fill:#044ef4;}.b59fade4-5c2c-49f1-a6bf-917d1f195a19{fill:#f72a72;}</style></defs><path class="a463a3b0-e95c-44d7-b809-5997966784eb" d="M389.17,278c0,10.31-2.8,17.06-8.37,22.62q-50.07,49.95-100.19,99.85C269,412,252.06,412.54,240.55,402c-12.12-11.13-12.6-29.39-.75-41.47,15-15.34,30.32-30.47,45.56-45.63q27.47-27.3,55.06-54.45c8.91-8.75,20.84-11.07,31.77-6.1C383.3,259.36,388.79,268.25,389.17,278Z" transform="translate(-70.83 -46.81)"/><path class="a463a3b0-e95c-44d7-b809-5997966784eb" d="M70.84,172.94c.16-5.21,2.93-11.81,8.36-17.24q49.89-49.77,99.8-99.53c6.92-6.91,15.08-10.45,24.83-9.06,11.55,1.65,19.62,8.12,23.38,19.22s1.16,21.14-7,29.43q-23.87,24.21-48,48.1-26.22,26.07-52.58,52c-8.93,8.76-20.84,10.92-31.8,6.13C77.17,197.35,70.65,187.14,70.84,172.94Z" transform="translate(-70.83 -46.81)"/><path class="b59fade4-5c2c-49f1-a6bf-917d1f195a19" d="M93.68,210.69c3.79-.17,6.91-.08,10-.49a34.39,34.39,0,0,0,20.56-10.34c6.38-6.52,12.79-13,19.33-19.66,1.23,1.09,2,1.7,2.66,2.38q36.92,36.9,73.81,73.83c8.07,8.1,10.9,17.87,7.66,28.86-3.12,10.58-10.39,17.35-21.17,19.77-9.33,2.1-18.23.31-25.07-6.47C152.25,269.64,123.32,240.42,93.68,210.69Z" transform="translate(-70.83 -46.81)"/><path class="b59fade4-5c2c-49f1-a6bf-917d1f195a19" d="M366.57,246c-15-1.53-25.7,4.26-34.72,14.22-4.89,5.4-10.23,10.39-15.51,15.69-1.1-1-1.86-1.59-2.56-2.28q-36.94-36.93-73.86-73.89c-8.07-8.1-10.89-17.89-7.56-28.89,3.19-10.56,10.47-17.31,21.28-19.68,9.56-2.1,18.45,0,25.44,6.92q43,42.57,85.61,85.47C365.12,244,365.44,244.54,366.57,246Z" transform="translate(-70.83 -46.81)"/></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB