feat: Implement twilio connection
This commit is contained in:
11
packages/backend/src/apps/twilio/assets/favicon.svg
Normal file
11
packages/backend/src/apps/twilio/assets/favicon.svg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-label="Twilio" role="img" viewBox="0 0 512 512">
|
||||||
|
<rect width="512" height="512" rx="15%" fill="#fff"/>
|
||||||
|
<g fill="#f22f46">
|
||||||
|
<circle cx="256" cy="256" r="256"/>
|
||||||
|
<circle cx="256" cy="256" fill="#fff" r="188"/>
|
||||||
|
<circle cx="193" cy="193" r="53" id="c"/>
|
||||||
|
<use xlink:href="#c" x="126"/>
|
||||||
|
<use xlink:href="#c" y="126"/>
|
||||||
|
<use xlink:href="#c" x="126" y="126"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 479 B |
120
packages/backend/src/apps/twilio/auth/index.ts
Normal file
120
packages/backend/src/apps/twilio/auth/index.ts
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import verifyCredentials from './verify-credentials';
|
||||||
|
import isStillVerified from './is-still-verified';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: 'accountSid',
|
||||||
|
label: 'Account SID',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description:
|
||||||
|
'Log into your Twilio account and find "API Credentials" on this page https://www.twilio.com/user/account/settings',
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'authToken',
|
||||||
|
label: 'Auth Token',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description: 'Found directly below your Account SID.',
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
authenticationSteps: [
|
||||||
|
{
|
||||||
|
step: 1,
|
||||||
|
type: 'mutation',
|
||||||
|
name: 'createConnection',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: '{key}',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'formattedData',
|
||||||
|
value: null,
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
name: 'accountSid',
|
||||||
|
value: '{fields.accountSid}',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'authToken',
|
||||||
|
value: '{fields.authToken}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
step: 2,
|
||||||
|
type: 'mutation',
|
||||||
|
name: 'verifyConnection',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
value: '{createConnection.id}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reconnectionSteps: [
|
||||||
|
{
|
||||||
|
step: 1,
|
||||||
|
type: 'mutation',
|
||||||
|
name: 'resetConnection',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
value: '{connection.id}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
step: 2,
|
||||||
|
type: 'mutation',
|
||||||
|
name: 'updateConnection',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
value: '{connection.id}',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'formattedData',
|
||||||
|
value: null,
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
name: 'accountSid',
|
||||||
|
value: '{fields.accountSid}',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'authToken',
|
||||||
|
value: '{fields.authToken}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
step: 3,
|
||||||
|
type: 'mutation',
|
||||||
|
name: 'verifyConnection',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
value: '{connection.id}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
verifyCredentials,
|
||||||
|
isStillVerified,
|
||||||
|
};
|
13
packages/backend/src/apps/twilio/auth/is-still-verified.ts
Normal file
13
packages/backend/src/apps/twilio/auth/is-still-verified.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { IGlobalVariable } from '@automatisch/types';
|
||||||
|
import verifyCredentials from './verify-credentials';
|
||||||
|
|
||||||
|
const isStillVerified = async ($: IGlobalVariable) => {
|
||||||
|
try {
|
||||||
|
await verifyCredentials($);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
20
packages/backend/src/apps/twilio/auth/verify-credentials.ts
Normal file
20
packages/backend/src/apps/twilio/auth/verify-credentials.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { IGlobalVariable } from '@automatisch/types';
|
||||||
|
|
||||||
|
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||||
|
try {
|
||||||
|
await $.http.get('/2010-04-01/Accounts.json?PageSize=1', {
|
||||||
|
auth: {
|
||||||
|
username: $.auth.data.accountSid as string,
|
||||||
|
password: $.auth.data.authToken as string,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
screenName: $.auth.data.accountSid,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(JSON.stringify(error.response.data));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default verifyCredentials;
|
13
packages/backend/src/apps/twilio/index.ts
Normal file
13
packages/backend/src/apps/twilio/index.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import defineApp from '../../helpers/define-app';
|
||||||
|
|
||||||
|
export default defineApp({
|
||||||
|
name: 'Twilio',
|
||||||
|
key: 'twilio',
|
||||||
|
iconUrl: '{BASE_URL}/apps/twilio/assets/favicon.svg',
|
||||||
|
authDocUrl: 'https://automatisch.io/docs/connections/twilio',
|
||||||
|
supportsConnections: true,
|
||||||
|
baseUrl: 'https://twilio.com',
|
||||||
|
apiBaseUrl: 'https://api.twilio.com',
|
||||||
|
primaryColor: 'e1000f',
|
||||||
|
beforeRequest: [],
|
||||||
|
});
|
Reference in New Issue
Block a user