I had a bit of a lazy morning in bed today, so in response to the surprisingly numerous emails I’ve gotten expressing thanks (or a desire for instructions of use) for the Twilio SMS and media deletion tool I wrote, I decided to tweak things a bit and make it a bit more usable.
Previously, media deletion occurred before SMS deletion, and while the async nature of node didn’t guarantee that everything would happen in the right sequence, the ordering of requests never led to issues until I started using it with larger sequences of texts, and the network bottlenecking threw the rhythm of the script off (obviously no script should have to work with a ‘rhythm’). The script would still run, but it was just messy.
The honorable and cleanly-coded solution would be to set up dynamically chained promises so that once the media deletions were done, THEN the message was deleted. However, one of the requests I got was for the media and SMS deletion functionalities to be separated, so I broke it out into two files — one for media deletion, and another for SMS deletion. Make sure you get the order right. If you accidentally delete all the messages before the media, you’re out of luck and the media will be on the web forever (see my previous griping posts about this; I’ve got three tickets open, all of which have made it past Tier 1 to their dev team and are supposedly on their dev queue… I’ll believe it when I see an API update).
Anyway, usage is a tad different, but more reliable and granular. Happy coding and, as always, be forkful and multiply!