-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
122 additions
and
78 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -10,22 +10,8 @@ | |
rel="icon" | ||
href="https://twilio-labs.github.io/function-templates/static/v1/favicon.ico" | ||
/> | ||
<link | ||
rel="stylesheet" | ||
href="https://twilio-labs.github.io/function-templates/static/v1/ce-paste-theme.css" | ||
/> | ||
<link rel="stylesheet" href="https://twilio-labs.github.io/function-templates/static/v1/ce-paste-theme.css" /> | ||
<link rel="stylesheet" href="styles.css" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/[email protected]/build/css/intlTelInput.min.css" | ||
integrity="sha256-xpVuhxDPR39wFEQDha4W7kuMx+z9Av3dTS8MbH/RWEU=" | ||
crossorigin="anonymous" | ||
/> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]/build/js/intlTelInput.min.js" | ||
integrity="sha256-uPbemOnf3P4eaeLHebLwPC71YRbu3WNBvO4ibYeBnGs=" | ||
crossorigin="anonymous" | ||
></script> | ||
<style> | ||
.success { | ||
border-color: #bce8f1; | ||
|
@@ -95,7 +81,7 @@ <h1> | |
<p> | ||
Before you start, make sure that the checkbox "Add my Twilio | ||
Credentials (ACCOUNT_SID) and (AUTH_TOKEN) to ENV" is checked in the | ||
"Environmental Variables" section of this Function. If it's not checked, | ||
"Environmental Variables" of this Function. If it's not checked, | ||
enable it and click "Deploy All" at the bottom. | ||
</p> | ||
<h2> | ||
|
@@ -114,40 +100,32 @@ <h2> | |
<a | ||
target="_blank" | ||
href="https://console.twilio.com/us1/develop/functions/services" | ||
>Function</a | ||
> | ||
>Function</a> | ||
- open the Function and click on "Environment Variables" in the bottom | ||
left corner, and change the value of Password. Click on "Deploy All" | ||
button afterwards in the bottom left corner. | ||
left corner, and change the value of Password. Click on "Deploy All" button afterwards in the bottom left corner. <br />The default | ||
Password is <i><b>1</b></i>. | ||
</p> | ||
Password:<input id="password" type="password" name="password" /> | ||
<br /> | ||
<div><p>You are working with account:</p></div> | ||
<div id="masking"></div> | ||
<div><button onclick="unmask()">Show Account</button></div> | ||
<div | ||
id="status_acc" | ||
style=" | ||
color: #a94442; | ||
background-color: #f2dede; | ||
border-color: #ebccd1; | ||
" | ||
></div> | ||
<div id="status_acc" style="color: #a94442; background-color: #f2dede; border-color: #ebccd1;"></div> | ||
<div><h3>Fetch Number SID</h3></div> | ||
<div> | ||
<form id="fetchSID" action="javascript:number_fetch()"> | ||
<p> | ||
In the below field, enter the number to get the SID that you need | ||
to use to transfer it. The search is done on your main account and | ||
its subaccounts automatically. <br /><b>Be carefull</b>, if you | ||
insert an incomplete number, the system will search for a number | ||
on your accounts (main account and subaccounts) that starts with | ||
what you inserted. <br /> | ||
In the below field, enter the number to get the SID that you need to use to transfer | ||
it. The search is done on your main account and its | ||
subaccounts automatically. <br /><b>Be carefull</b>, if you insert an | ||
incomplete number, the system will search for a number on your | ||
accounts (main account and subaccounts) that starts with what you | ||
inserted. <br /> | ||
For example, if you have a number +123456789, and you insert | ||
+1234567, the details of the complete number will be returned. | ||
Make sure you check what is the number in the result. | ||
</p> | ||
<input id="fphone" type="text" name="fphone" /> | ||
<input id="fphone" type="text" name="fphone" oninput="checkFormat()" /> | ||
<br /> | ||
<input id="tbutton" type="submit" value="Fetch" /> | ||
</form> | ||
|
@@ -172,9 +150,7 @@ <h2> | |
href="https://support.twilio.com/hc/en-us/articles/223135327-Moving-Twilio-Phone-Numbers-to-another-Twilio-Account" | ||
>FAQ page</a | ||
>. <br /> | ||
<b>Hosted Numbers should not</b> be transferred with this tool or | ||
the API. Contact Twilio Support if you want to transfer a Hosted | ||
number. | ||
<b>Hosted Numbers should not</b> be transferred with this tool or the API. Contact Twilio Support if you want to transfer a Hosted number. | ||
</p> | ||
<p> | ||
Enter the SID of the phone number you would like to transfer | ||
|
@@ -212,14 +188,19 @@ <h2> | |
Insert the Address SID (depends on regulatory requirements of the | ||
number): | ||
</p> | ||
<input id="addressSID" type="text" name="addressSID" value="" /> | ||
<input | ||
id="addressSID" | ||
type="text" | ||
name="addressSID" | ||
value="" | ||
/> | ||
<input id="transfer" type="submit" value="Transfer" /> | ||
</form> | ||
<div class="alert alert-info" style="display: none"></div> | ||
<div class="alert alert-error" style="display: none"></div> | ||
</div> | ||
<div> | ||
<!-- EDIT_CODE_V2 --> | ||
<!-- EDIT_CODE --> | ||
</div> | ||
</div> | ||
</main> | ||
|
@@ -232,6 +213,16 @@ <h2> | |
const success = document.querySelector(".alert-success"); | ||
const warning = document.querySelector(".alert-warning"); | ||
|
||
|
||
async function checkFormat(){ | ||
if(!/^\+\d+$/.test(document.getElementById("fphone").value)){ | ||
document.getElementById("fphone").style.background = "Tomato"; | ||
} | ||
else { | ||
document.getElementById("fphone").style.background = ""; | ||
} | ||
} | ||
|
||
async function transfer() { | ||
let alertConfirm = | ||
"You requested to transfer a number. If there is a Whatsapp configuration on the number, it will be lost on transfer. If there are opt-outs and/or A2P registrations (US LongCodes only) on the number, those will also be lost. You will need to setup Opt-Outs and re-register the numbers on the new account before they will work. Please find more information in the linked FAQ page. \n\n Do you want to proceed with the transfer?"; | ||
|
@@ -310,46 +301,71 @@ <h2> | |
let aresponse = null; | ||
let fresponse = null; | ||
let json2 = null; | ||
let ajson = null; | ||
let ajson = []; | ||
let sid = null; | ||
let asid = null; | ||
let phoneNumber = null; | ||
let phoneNumber = document.getElementById("fphone").value; | ||
let numStatus = null; | ||
let addReq = null; | ||
let insertedNumber = phoneNumber; | ||
let subPage = 0; | ||
let subPageToken = ''; | ||
let subPageAll = 0; | ||
let subData = null; | ||
let aPageJson = null; | ||
|
||
const password = document.getElementById("password").value; | ||
phoneNumber = document.getElementById("fphone").value; | ||
|
||
try { | ||
success.style.display = "none"; | ||
warning.style.display = "none"; | ||
status_acc.style.display = "none"; | ||
|
||
aresponse = await fetch("./list_accounts", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": password, | ||
while (subPageAll === 0) { | ||
|
||
subData = { | ||
pageSize: 20, | ||
page: subPage, | ||
pageToken: decodeURIComponent(subPageToken), | ||
}; | ||
aresponse = await fetch("./list_accounts", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: password, | ||
}, | ||
body: JSON.stringify(subData), | ||
}); | ||
console.log("return from Acc function"); | ||
if (aresponse.status === 200) { | ||
aPageJson = await aresponse.json(); | ||
if (aPageJson.er === 0) { | ||
warning.style.display = ""; | ||
status_acc.style.display="none"; | ||
success.style.display = "none"; | ||
warning.innerHTML = `Wrong password.`; | ||
return; | ||
} | ||
if (aPageJson[aPageJson.length-1] !== "end") { | ||
subPageToken = aPageJson[aPageJson.length-1]; | ||
console.log(subPageToken); | ||
} else { | ||
subPageAll = 1; | ||
subPageToken = ''; | ||
} | ||
subPage += 1; | ||
aPageJson.pop(); | ||
console.log(aPageJson); | ||
for(let z in aPageJson){ | ||
ajson.push(aPageJson[z]); | ||
} | ||
console.log(ajson); | ||
} else { | ||
warning.style.display = ""; | ||
warning.innerHTML = `Something went wrong with getting the list of accounts:<br /> Server error is ${aresponse.message}<br /> Server status is ${aresponse.status}`; | ||
return; | ||
} | ||
} | ||
}); | ||
console.log("return from Acc function"); | ||
console.log(aresponse); | ||
if (aresponse.status === 200) { | ||
ajson = await aresponse.json(); | ||
console.log(ajson); | ||
|
||
if (ajson.er === 0) { | ||
warning.style.display = ""; | ||
status_acc.style.display="none"; | ||
success.style.display = "none"; | ||
warning.innerHTML = `Wrong password.`; | ||
return; | ||
} | ||
} else { | ||
warning.style.display = ""; | ||
warning.innerHTML = `Something went wrong with getting the list of accounts:<br /> Server error is ${aresponse.message}<br /> Server status is ${aresponse.status}`; | ||
return; | ||
} | ||
|
||
for (a = 0; a < ajson.length; a++) { | ||
fdata = { | ||
|
@@ -397,6 +413,12 @@ <h2> | |
warning.innerHTML = `<pre> ${JSON.stringify(json2, null, 2)}</pre>`; | ||
} else { | ||
if (fresponse.status === 200) { | ||
if (insertedNumber !== phoneNumber.substring(0, insertedNumber.length,)){ | ||
warning.style.display = ""; | ||
success.style.display = "none"; | ||
warning.innerHTML = `Number not found.`; | ||
return; | ||
} | ||
success.style.display = ""; | ||
success.innerHTML = `<pre>Number ${JSON.stringify( | ||
phoneNumber, | ||
|
@@ -473,4 +495,4 @@ <h2> | |
} | ||
</script> | ||
</body> | ||
</html> | ||
</html> |
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