feat: add Signalwire integration

This commit is contained in:
Sebastian Schumann
2023-02-24 03:39:25 +01:00
parent 831ae96e0f
commit d7e4ae53ce
19 changed files with 286 additions and 0 deletions

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 = 'https://' + $.auth.data.spaceName + '.' + $.auth.data.spaceRegion + 'signalwire.com' + `/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 = 'https://' + $.auth.data.spaceName + '.' + $.auth.data.spaceRegion + 'signalwire.com' + response.data.next_page_uri;
} while (requestPath);
};
export default fetchMessages;

View File

@@ -0,0 +1,23 @@
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: 'string',
required: true,
description:
'The number to receive the SMS on. It should be a Signalwire number in your project.',
},
],
async run($) {
await fetchMessages($);
},
});