feat: Convert all app files to JS
This commit is contained in:
3
packages/backend/src/apps/signalwire/actions/index.js
Normal file
3
packages/backend/src/apps/signalwire/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import sendSms from './send-sms/index.js';
|
||||
|
||||
export default [sendSms];
|
@@ -1,3 +0,0 @@
|
||||
import sendSms from './send-sms';
|
||||
|
||||
export default [sendSms];
|
@@ -1,4 +1,4 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Send an SMS',
|
||||
@@ -8,7 +8,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'From Number',
|
||||
key: 'fromNumber',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description:
|
||||
'The number to send the SMS from. Include only country code. Example: 491234567890',
|
||||
@@ -27,7 +27,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'To Number',
|
||||
key: 'toNumber',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description:
|
||||
'The number to send the SMS to. Include only country code. Example: 491234567890',
|
||||
@@ -36,7 +36,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Message',
|
||||
key: 'message',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The content of the message.',
|
||||
variables: true,
|
||||
@@ -48,14 +48,14 @@ export default defineAction({
|
||||
|
||||
const Body = $.step.parameters.message;
|
||||
const From = $.step.parameters.fromNumber;
|
||||
const To = '+' + ($.step.parameters.toNumber as string).trim();
|
||||
const To = '+' + $.step.parameters.toNumber.trim();
|
||||
|
||||
const response = await $.http.post(requestPath, null, {
|
||||
params: {
|
||||
Body,
|
||||
From,
|
||||
To,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
@@ -1,24 +1,23 @@
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'accountSid',
|
||||
label: 'Project ID',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description:
|
||||
'Log into your SignalWire account and find the Project ID',
|
||||
description: 'Log into your SignalWire account and find the Project ID',
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'authToken',
|
||||
label: 'API Token',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -29,7 +28,7 @@ export default {
|
||||
{
|
||||
key: 'spaceRegion',
|
||||
label: 'SignalWire Region',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: '',
|
||||
@@ -50,7 +49,7 @@ export default {
|
||||
{
|
||||
key: 'spaceName',
|
||||
label: 'Space Name',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,9 @@
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
await verifyCredentials($);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,10 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await verifyCredentials($);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -0,0 +1,11 @@
|
||||
const verifyCredentials = async ($) => {
|
||||
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;
|
@@ -1,11 +0,0 @@
|
||||
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;
|
@@ -1,24 +1,19 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
const authData = $.auth.data || {};
|
||||
|
||||
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
if (
|
||||
authData.accountSid &&
|
||||
authData.authToken
|
||||
) {
|
||||
if (authData.accountSid && authData.authToken) {
|
||||
requestConfig.auth = {
|
||||
username: authData.accountSid as string,
|
||||
password: authData.authToken as string,
|
||||
username: authData.accountSid,
|
||||
password: authData.authToken,
|
||||
};
|
||||
}
|
||||
|
||||
if (authData.spaceName) {
|
||||
const serverUrl = `https://${authData.spaceName}.${authData.spaceRegion}signalwire.com`;
|
||||
|
||||
requestConfig.baseURL = serverUrl as string;
|
||||
requestConfig.baseURL = serverUrl;
|
||||
}
|
||||
|
||||
return requestConfig;
|
@@ -1,3 +1,3 @@
|
||||
import listIncomingPhoneNumbers from './list-incoming-phone-numbers';
|
||||
import listIncomingPhoneNumbers from './list-incoming-phone-numbers/index.js';
|
||||
|
||||
export default [listIncomingPhoneNumbers];
|
@@ -1,37 +1,16 @@
|
||||
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) {
|
||||
async run($) {
|
||||
let requestPath = `/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}/IncomingPhoneNumbers`;
|
||||
|
||||
const aggregatedResponse: TAggregatedResponse = {
|
||||
const aggregatedResponse = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get<TResponse>(requestPath);
|
||||
const { data } = (await $.http.get) < TResponse > requestPath;
|
||||
|
||||
const smsCapableIncomingPhoneNumbers = data.incoming_phone_numbers
|
||||
.filter((incomingPhoneNumber) => {
|
||||
@@ -46,8 +25,8 @@ export default {
|
||||
value: phoneNumber,
|
||||
name,
|
||||
};
|
||||
})
|
||||
aggregatedResponse.data.push(...smsCapableIncomingPhoneNumbers)
|
||||
});
|
||||
aggregatedResponse.data.push(...smsCapableIncomingPhoneNumbers);
|
||||
|
||||
requestPath = data.next_page_uri;
|
||||
} while (requestPath);
|
@@ -1,9 +1,9 @@
|
||||
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';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import actions from './actions/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'SignalWire',
|
3
packages/backend/src/apps/signalwire/triggers/index.js
Normal file
3
packages/backend/src/apps/signalwire/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import receiveSms from './receive-sms/index.js';
|
||||
|
||||
export default [receiveSms];
|
@@ -1,3 +0,0 @@
|
||||
import receiveSms from './receive-sms';
|
||||
|
||||
export default [receiveSms];
|
@@ -1,7 +1,5 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
const fetchMessages = async ($: IGlobalVariable) => {
|
||||
const toNumber = $.step.parameters.toNumber as string;
|
||||
const fetchMessages = async ($) => {
|
||||
const toNumber = $.step.parameters.toNumber;
|
||||
|
||||
let response;
|
||||
let requestPath = `/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}/Messages?To=${toNumber}`;
|
||||
@@ -9,11 +7,11 @@ const fetchMessages = async ($: IGlobalVariable) => {
|
||||
do {
|
||||
response = await $.http.get(requestPath);
|
||||
|
||||
response.data.messages.forEach((message: IJSONObject) => {
|
||||
response.data.messages.forEach((message) => {
|
||||
const dataItem = {
|
||||
raw: message,
|
||||
meta: {
|
||||
internalId: message.date_sent as string,
|
||||
internalId: message.date_sent,
|
||||
},
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import fetchMessages from './fetch-messages';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import fetchMessages from './fetch-messages.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Receive SMS',
|
Reference in New Issue
Block a user