feat: Implement twilio connection

This commit is contained in:
Faruk AYDIN
2022-10-25 20:03:08 +02:00
committed by Ali BARIN
parent 8fb58cf662
commit 30d2740368
5 changed files with 177 additions and 0 deletions

View 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

View 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,
};

View 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;

View 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;

View 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: [],
});