Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
dsTw5 authored Oct 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ee40351 commit b770f64
Showing 9 changed files with 626 additions and 0 deletions.
426 changes: 426 additions & 0 deletions transfers/assets/index.html

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions transfers/assets/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pre {
white-space: pre-wrap;
}

.alert {
padding: 15px;
margin-top: 10px;
border: 1px solid transparent;
border-radius: 4px;
}

.alert-info {
border-color: #bce8f1;
color: #31708f;
background-color: #d9edf7;
}

.alert-error {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
4 changes: 4 additions & 0 deletions transfers/env.variables
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Variables for function ""
# ---
# description:
Password=1
82 changes: 82 additions & 0 deletions transfers/functions/fetch_sid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
exports.handler = async function (context, event, callback) {
let phoneNumber = event.phone;
let finalData = null;
let allAccounts = [];
let i = 0;
let numAccounts = 1;
let subA = null;
let subClient = null;
let sSid = null;
let pNum = null;
let numStatus = null;
let addReq=null;
let sub = null;
let subResp = null;
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require("twilio")(accountSid, authToken);
const password = event.pass;
const response = new Twilio.Response();

response.appendHeader("Content-Type", "application/json");

if (password != process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}

try {
sub = await client.api.v2010.accounts
.list()
.then((accounts) => accounts.forEach((a) => (allAccounts[i++] = a.sid)));

numAccounts = allAccounts.length;
try {
for (let j = 0; j < numAccounts; j++) {
subA = allAccounts[j].replace(/\"/g, "");

subClient = require("twilio")(accountSid, authToken, {
accountSid: subA,
});

subResp = await subClient.incomingPhoneNumbers
.list({ phoneNumber: phoneNumber })
.then((incomingPhoneNumbers) =>
incomingPhoneNumbers.forEach((k) => {
pNum = k.phoneNumber;
sSid = k.sid;
numStatus = k.status;
addReq = k.addressRequirements;
}),
);

finalData = {
Acc: subA,
pnumber: pNum,
SID: sSid,
status: numStatus,
addressReq: addReq,
};
if (pNum != null) {
response.setStatusCode(200);
response.setBody(sSid);
return callback(null, finalData);
}
}

response.setStatusCode(200);
response.setBody("number not found");
return callback(null, response);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
18 changes: 18 additions & 0 deletions transfers/functions/get_account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
exports.handler = async function (context, event, callback) {
let finalData = null;
const accountSid = { acc: process.env.ACCOUNT_SID };
const password = event.pass;

if (password != process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}
try {
return callback(null, accountSid);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
12 changes: 12 additions & 0 deletions transfers/functions/mask_account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exports.handler = async function (context, event, callback) {
const accountSid = { acc: process.env.ACCOUNT_SID };

try {
return callback(null, accountSid);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
36 changes: 36 additions & 0 deletions transfers/functions/transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
exports.handler = async function (context, event, callback) {
let finalData = null;
let resp = null;
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const response = new Twilio.Response();
response.appendHeader("Content-Type", "application/json");

if (event.pass != process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}

try {
const client = require("twilio")(accountSid, authToken, {
accountSid: event.laccount,
});

resp = await client
.incomingPhoneNumbers(event.phone) //number SID
.update({
accountSid: event.gaccount,
bundleSid: event.bSID,
addressSid: event.aSID,
}); //account sid where the number should be transferred to

response.setStatusCode(200);
response.setBody(resp);
return callback(null, response);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
9 changes: 9 additions & 0 deletions transfers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": "1.0.0",
"private": true,
"dependencies": {
"twilio": "^3.61.0",
"scripts": {
"e2e": "node e2e.js"
}
}
17 changes: 17 additions & 0 deletions transfers/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Instructions

On index.html you will see various fields and buttons that you can use.

The 1st one is to insert the password. This is important as the app will not work without a correct password.
To change the password, you need to open your function, click on Environmental Variables and edit the Password variable.

The 2nd one is the section that shows which Main account you are working with.
Because this is a public URL, your account SID is masked by default and you can unmask it by inserting the correct password and clicking on "Show Account" button. If the password is incorrect, the message "Wrong password" will be displayed.

The next section is to find out the SID of a number. You can insert the number in question (international format, for example +123456789), and when you press "Fetch" the number, numberSID, number status, address requirements, and account SID where the number is located will be displayed.

In the following field, you need to insert the SID of the number you want to transfer, the SID of the losing account, the SID of the gaining account, as well the BundleSID and AddressSID that will be associated with the number on the new account (depends on the regulatory requirements of the number).

When you click "Transfer", a pop up will be displayed where you need to confirm that you want to transfer the number.

Be careful, as the number configurations will be lost as well the opt-out and A2P registrations (A2P registrations are related to US LongCodes only).

0 comments on commit b770f64

Please sign in to comment.