-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
626 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Variables for function "" | ||
# --- | ||
# description: | ||
Password=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |