Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Last active December 30, 2020 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adrian-Samuel/2295cef3edfa0c41a8428f0109fd9e12 to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/2295cef3edfa0c41a8428f0109fd9e12 to your computer and use it in GitHub Desktop.
A script to extract all the responses to a certain number to a spreadsheet using the twilio cli
#! /bin/bash
read -p "Please enter in the full number " assignedNumber
smsExportFile="$assignedNumber"_Responses_$(date +'%Y-%m-%d')".csv"
twilio api:core:messages:list --to=$number --properties=body,from,dateSent -o=tsv > $smsExportFile
# no need to custom parse the JSON
# twilio api:core:messages:list |
# grep "inbound" |
# grep "$assignedNumber" |
# awk '{print $1}' |
# xargs -I {} twilio api:core:messages:fetch --sid {} -o json |
# jq '.[]| "\"" + .body + "\"" + "," + "\"" + .from + "\"" + "," + "\"" + (.dateSent|tostring) + "\""' |
# sed 's/\\//g' |
# sed -E 's/^"(.*)"$/\1/g' >> $smsExportFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment