refactor(signalwire): add dynamic api base url
This commit is contained in:
@@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials';
|
|||||||
|
|
||||||
const isStillVerified = async ($: IGlobalVariable) => {
|
const isStillVerified = async ($: IGlobalVariable) => {
|
||||||
await verifyCredentials($);
|
await verifyCredentials($);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
import { IGlobalVariable } from '@automatisch/types';
|
||||||
|
|
||||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||||
await $.http.get('https://' + $.auth.data.spaceName + '.' + $.auth.data.spaceRegion + 'signalwire.com' + '/api/laml/2010-04-01/Accounts');
|
const { data } = await $.http.get(`/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}`);
|
||||||
|
|
||||||
await $.auth.set({
|
await $.auth.set({
|
||||||
screenName: $.auth.data.accountSid,
|
screenName: `${data.friendly_name} (${$.auth.data.accountSid})`,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,19 +1,26 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
import { TBeforeRequest } from '@automatisch/types';
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||||
if (
|
const authData = $.auth.data || {};
|
||||||
requestConfig.headers &&
|
|
||||||
$.auth.data?.accountSid &&
|
|
||||||
$.auth.data?.authToken
|
|
||||||
) {
|
|
||||||
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||||
|
|
||||||
|
if (
|
||||||
|
authData.accountSid &&
|
||||||
|
authData.authToken
|
||||||
|
) {
|
||||||
requestConfig.auth = {
|
requestConfig.auth = {
|
||||||
username: $.auth.data.accountSid as string,
|
username: authData.accountSid as string,
|
||||||
password: $.auth.data.authToken as string,
|
password: authData.authToken as string,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (authData.spaceName) {
|
||||||
|
const serverUrl = `https://${authData.spaceName}.${authData.spaceRegion}signalwire.com`;
|
||||||
|
|
||||||
|
requestConfig.baseURL = serverUrl as string;
|
||||||
|
}
|
||||||
|
|
||||||
return requestConfig;
|
return requestConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ const fetchMessages = async ($: IGlobalVariable) => {
|
|||||||
const toNumber = $.step.parameters.toNumber as string;
|
const toNumber = $.step.parameters.toNumber as string;
|
||||||
|
|
||||||
let response;
|
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}`;
|
let requestPath = `/api/laml/2010-04-01/Accounts/${$.auth.data.accountSid}/Messages?To=${toNumber}`;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
response = await $.http.get(requestPath);
|
response = await $.http.get(requestPath);
|
||||||
@@ -20,7 +20,7 @@ const fetchMessages = async ($: IGlobalVariable) => {
|
|||||||
$.pushTriggerItem(dataItem);
|
$.pushTriggerItem(dataItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
requestPath = 'https://' + $.auth.data.spaceName + '.' + $.auth.data.spaceRegion + 'signalwire.com' + response.data.next_page_uri;
|
requestPath = response.data.next_page_uri;
|
||||||
} while (requestPath);
|
} while (requestPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user