Created
July 25, 2019 09:31
-
-
Save lmj0011/0e2d8ff47e4171a562ebfb546fbde6e6 to your computer and use it in GitHub Desktop.
Delete All Conversations From Your TextNow Account
This file contains hidden or 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
(async function () { | |
let lastGlobalId; | |
let fetchUrl; | |
let bigOleArrayOfContacts = []; | |
const USERNAME_QUERY_SELECTOR = "#recent-header > div.account-details > div.name"; | |
const CSRF_TOKEN_QUERY_SELECTOR = "meta[name=csrf-token]"; | |
console.log("Script has started."); | |
if (!document.querySelector(USERNAME_QUERY_SELECTOR)) { | |
throw Error("was unable to find the username on this HTML page") | |
} | |
if (!document.querySelector(CSRF_TOKEN_QUERY_SELECTOR)) { | |
throw Error("was unable to find the csrf-token on this HTML page") | |
} | |
// update these options, as needed, before running this script | |
const opts = { | |
TEXTNOW_USERNAME: document.querySelector(USERNAME_QUERY_SELECTOR).innerText, | |
// perseve conversations that you have given a name to from use of the "Edit Contact Name" option | |
DELETE_NAMED_CONVERSATIONS: true, | |
// should not need to change this | |
CSRF_TOKEN: document.querySelector(CSRF_TOKEN_QUERY_SELECTOR).content, | |
} | |
console.log("Gathering contacts.\n\n"); | |
do { | |
if(!lastGlobalId) { | |
fetchUrl = 'https://www.textnow.com/api/v3/contacts?page_size=100'; | |
} else { | |
fetchUrl = `https://www.textnow.com/api/v3/contacts?page_size=100&global_id_start=${lastGlobalId}`; | |
} | |
try { | |
await fetch(fetchUrl, | |
{"credentials":"include", | |
"headers":{ | |
"accept":"application/json, text/javascript, */*;q=0.01", | |
"accept-language":"en-US,en;q=0.9", | |
"cache-control":"no-cache", | |
"pragma":"no-cache", | |
"x-requested-with":"XMLHttpRequest" | |
}, | |
"referrer":"https://www.textnow.com/messaging", | |
"referrerPolicy":"no-referrer-when-downgrade", | |
"body": null, | |
"method":"GET", | |
"mode":"cors" | |
}) | |
.then(res => res.json()) | |
.then(data => { | |
if(data.result.length) { | |
bigOleArrayOfContacts = bigOleArrayOfContacts.concat(data.result); | |
lastGlobalId = data.result[(data.result.length - 1)].global_id; | |
} else { | |
lastGlobalId = null | |
} | |
}) | |
} catch(e) { | |
console.log(e); | |
} | |
} while (lastGlobalId); | |
///////////////////////// | |
const contactsToDelete = bigOleArrayOfContacts.filter(contact => { | |
if (!opts.DELETE_NAMED_CONVERSATIONS && (contact.name && contact.name.match(/[a-zA-Z]+/g))){ | |
return false; | |
} else { | |
return true; | |
} | |
}); | |
console.log(`Preparing to delete ${contactsToDelete.length} conversations.\n\n`); | |
for (const contact of contactsToDelete) { | |
let number; | |
if(contact.contact_value[0] === "+") { | |
number = contact.contact_value.slice(1) | |
} else { | |
number = contact.contact_value | |
} | |
try { | |
await fetch(`https://www.textnow.com/api/users/${opts.TEXTNOW_USERNAME}/conversations/%2B${number}`, | |
{"credentials":"include", | |
"headers":{ | |
"accept":"application/json, text/javascript, */*; q=0.01", | |
"accept-language":"en-US,en;q=0.9", | |
"cache-control":"no-cache", | |
"pragma":"no-cache", | |
"x-csrf-token": opts.CSRF_TOKEN, | |
"x-requested-with":"XMLHttpRequest" | |
}, | |
"referrer":"https://www.textnow.com/messaging", | |
"referrerPolicy":"no-referrer-when-downgrade", | |
"body":null, | |
"method":"DELETE", | |
"mode":"cors" | |
}); | |
// add a delay to avoid spamming server | |
await new Promise(resolve => { | |
setTimeout(() => { resolve() }, 1000); | |
}); | |
console.log("deleted! ", contact); | |
} catch (e) { | |
console.log(e); | |
} | |
} | |
console.log("DONE!"); | |
})(); |
ran twice - and still showed deleted same info ... does this mean its not working ?
they are in RED not sure its working - im not experienced in code
@omgitsj the script still works. You have to let it run until you no longer see output like:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How To Use:
In a modern up-to-date browser (ie. Chrome), go to https://www.textnow.com/messaging and log in
copy/paste this script into the browser's web console and hit Enter
observe the web console output:

After script is done, refresh the page and conservation list should be clear.
NOTES
It's questionable whether or not the messages are deleted permanently from TextNow's servers
ref: https://supportwireless.textnow.com/hc/en-us/community/posts/217468966-HOW-DO-I-DELETE-MY-ACCOUNT-
Depending on your log in method you may have your full name and not username show up on your account page, you will need to hardcode the value on line 21 if that's the case
change:
TEXTNOW_USERNAME: document.querySelector(USERNAME_QUERY_SELECTOR).innerText,
to:
TEXTNOW_USERNAME: "MyUsername",
you can get your username from the any of the urls used in making api calls. see Network panel in your web browser's console or by going to Settings > Account from https://www.textnow.com/messaging