feat: Convert all app files to JS
This commit is contained in:
3
packages/backend/src/apps/twilio/actions/index.js
Normal file
3
packages/backend/src/apps/twilio/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,5 +1,5 @@
|
||||
import { URLSearchParams } from 'node:url';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Send an SMS',
|
||||
@@ -9,7 +9,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 country code. Example: 15551234567',
|
||||
@@ -28,7 +28,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 country code. Example: 15551234567',
|
||||
@@ -37,7 +37,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Message',
|
||||
key: 'message',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The message to send.',
|
||||
variables: true,
|
||||
@@ -46,10 +46,10 @@ export default defineAction({
|
||||
|
||||
async run($) {
|
||||
const requestPath = `/2010-04-01/Accounts/${$.auth.data.accountSid}/Messages.json`;
|
||||
const messageBody = $.step.parameters.message as string;
|
||||
const messageBody = $.step.parameters.message;
|
||||
|
||||
const fromNumber = ($.step.parameters.fromNumber as string).trim();
|
||||
const toNumber = ($.step.parameters.toNumber as string).trim();
|
||||
const fromNumber = $.step.parameters.fromNumber.trim();
|
||||
const toNumber = $.step.parameters.toNumber.trim();
|
||||
|
||||
const payload = new URLSearchParams({
|
||||
Body: messageBody,
|
||||
@@ -57,10 +57,7 @@ export default defineAction({
|
||||
To: toNumber,
|
||||
}).toString();
|
||||
|
||||
const response = await $.http.post(
|
||||
requestPath,
|
||||
payload,
|
||||
);
|
||||
const response = await $.http.post(requestPath, payload);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
@@ -1,12 +1,12 @@
|
||||
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: 'Account SID',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -18,7 +18,7 @@ export default {
|
||||
{
|
||||
key: 'authToken',
|
||||
label: 'Auth Token',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,8 @@
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
await verifyCredentials($);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await verifyCredentials($);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const verifyCredentials = async ($) => {
|
||||
await $.http.get('/2010-04-01/Accounts.json?PageSize=1');
|
||||
|
||||
await $.auth.set({
|
@@ -1,6 +1,4 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
if (
|
||||
requestConfig.headers &&
|
||||
$.auth.data?.accountSid &&
|
||||
@@ -9,8 +7,8 @@ const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
requestConfig.auth = {
|
||||
username: $.auth.data.accountSid as string,
|
||||
password: $.auth.data.authToken as string,
|
||||
username: $.auth.data.accountSid,
|
||||
password: $.auth.data.authToken,
|
||||
};
|
||||
}
|
||||
|
@@ -0,0 +1,7 @@
|
||||
export default async function getIncomingPhoneNumber($) {
|
||||
const phoneNumberSid = $.step.parameters.phoneNumberSid;
|
||||
const path = `/2010-04-01/Accounts/${$.auth.data.accountSid}/IncomingPhoneNumbers/${phoneNumberSid}.json`;
|
||||
const response = await $.http.get(path);
|
||||
|
||||
return response.data;
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
import { IGlobalVariable } from "@automatisch/types";
|
||||
|
||||
type Response = {
|
||||
sid: string;
|
||||
phone_number: string;
|
||||
};
|
||||
|
||||
export default async function getIncomingPhoneNumber($: IGlobalVariable) {
|
||||
const phoneNumberSid = $.step.parameters.phoneNumberSid as string;
|
||||
const path = `/2010-04-01/Accounts/${$.auth.data.accountSid}/IncomingPhoneNumbers/${phoneNumberSid}.json`;
|
||||
const response = await $.http.get<Response>(path);
|
||||
|
||||
return response.data;
|
||||
};
|
@@ -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 TResponse = {
|
||||
data: IJSONObject[];
|
||||
error?: IJSONObject;
|
||||
};
|
||||
|
||||
type TIncomingPhoneNumber = {
|
||||
phone_number: string;
|
||||
friendly_name: string;
|
||||
sid: string;
|
||||
capabilities: {
|
||||
sms: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
type TResponseData = {
|
||||
incoming_phone_numbers: TIncomingPhoneNumber[];
|
||||
next_page_uri: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'List incoming phone numbers',
|
||||
key: 'listIncomingPhoneNumbers',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const valueType = $.step.parameters.valueType as string;
|
||||
async run($) {
|
||||
const valueType = $.step.parameters.valueType;
|
||||
const isSid = valueType === 'sid';
|
||||
|
||||
const aggregatedResponse: TResponse = { data: [] };
|
||||
const aggregatedResponse = { data: [] };
|
||||
let pathname = `/2010-04-01/Accounts/${$.auth.data.accountSid}/IncomingPhoneNumbers.json`;
|
||||
|
||||
do {
|
||||
const response = await $.http.get<TResponseData>(pathname);
|
||||
const response = (await $.http.get) < TResponseData > pathname;
|
||||
|
||||
for (const incomingPhoneNumber of response.data.incoming_phone_numbers) {
|
||||
if (incomingPhoneNumber.capabilities.sms === false) {
|
@@ -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: 'Twilio',
|
3
packages/backend/src/apps/twilio/triggers/index.js
Normal file
3
packages/backend/src/apps/twilio/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,6 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import getIncomingPhoneNumber from '../../common/get-incoming-phone-number';
|
||||
import getIncomingPhoneNumber from '../../common/get-incoming-phone-number.js';
|
||||
|
||||
const fetchMessages = async ($: IGlobalVariable) => {
|
||||
const fetchMessages = async ($) => {
|
||||
const incomingPhoneNumber = await getIncomingPhoneNumber($);
|
||||
|
||||
let response;
|
||||
@@ -10,7 +9,7 @@ const fetchMessages = async ($: IGlobalVariable) => {
|
||||
do {
|
||||
response = await $.http.get(requestPath);
|
||||
|
||||
response.data.messages.forEach((message: IJSONObject) => {
|
||||
response.data.messages.forEach((message) => {
|
||||
const computedMessage = {
|
||||
To: message.to,
|
||||
Body: message.body,
|
||||
@@ -26,7 +25,7 @@ const fetchMessages = async ($: IGlobalVariable) => {
|
||||
const dataItem = {
|
||||
raw: computedMessage,
|
||||
meta: {
|
||||
internalId: message.date_sent as string,
|
||||
internalId: message.date_sent,
|
||||
},
|
||||
};
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { URLSearchParams } from 'node:url';
|
||||
import Crypto from 'crypto';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import fetchMessages from './fetch-messages';
|
||||
import isEmpty from 'lodash/isEmpty.js';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import fetchMessages from './fetch-messages.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Receive SMS',
|
||||
@@ -13,7 +13,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'To Number',
|
||||
key: 'phoneNumberSid',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description:
|
||||
'The number to receive the SMS on. It should be a Twilio number.',
|
||||
@@ -65,7 +65,7 @@ export default defineTrigger({
|
||||
},
|
||||
|
||||
async registerHook($) {
|
||||
const phoneNumberSid = $.step.parameters.phoneNumberSid as string;
|
||||
const phoneNumberSid = $.step.parameters.phoneNumberSid;
|
||||
const payload = new URLSearchParams({
|
||||
SmsUrl: $.webhookUrl,
|
||||
}).toString();
|
||||
@@ -77,7 +77,7 @@ export default defineTrigger({
|
||||
},
|
||||
|
||||
async unregisterHook($) {
|
||||
const phoneNumberSid = $.step.parameters.phoneNumberSid as string;
|
||||
const phoneNumberSid = $.step.parameters.phoneNumberSid;
|
||||
const payload = new URLSearchParams({
|
||||
SmsUrl: '',
|
||||
}).toString();
|
Reference in New Issue
Block a user