Catch outgoing twilio calls status and update into spreadsheet

64 views
Skip to first unread message

Le pirate noir

unread,
Nov 4, 2022, 1:48:37 PM11/4/22
to Google Apps Script Community
Hi team,

I am trying to get the status of my outgoing twilio calls and update them onto a spreadsheet.

I found this related article but not working in my case  

I don't know why but for some reasons Twillio don't send the HTTP request to my app so I can grab the infos i need...

Who can figure out, what's the issue with my code.

function make_call(){

var url = ScriptApp.getService().getUrl()

var payload = {
    "From" :  twilio_number
    ,"To" : mynumber
     ,"Twiml" : '<Response>  <Dial>'+string+'</Dial> </Response>'
    ,"StatusCallback" : url
  };

    var headers = {
    "Authorization" : "Basic " + Utilities.base64Encode(ACCOUNT_SID + ':' + ACCOUNT_TOKEN)
  };

    var options =
      {
        "method" : "post",
        "payload" : payload,
        "headers" : headers
      };         


  var url = 'https://api.twilio.com/2010-04-01/Accounts/'+ACCOUNT_SID+'/Calls.json';
  
     var response = UrlFetchApp.fetch(url, options);
  
}

function doPost(e) {
       var callSid = e.parameter("CallSid");
     let callStatus = e.parameter("CallStatus");

//Here i access the sheet where I want to put the informations in (CallSid, CallStatus)
       SpreadsheetApp.openById("1223Xdwd").getSheetByName("Sheet1").appendRow([callSid,callStatus]);
    return ContentService.createTextOutput('')
 };

Andrew Roberts

unread,
Nov 5, 2022, 3:27:54 AM11/5/22
to google-apps-sc...@googlegroups.com
Try this to get the data from the POST.

const contents = JSON.parse(e.postData.contents)

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ca7c34fe-db28-4c97-a8b3-29a461f204ean%40googlegroups.com.

Stéphane Ray Noel

unread,
Nov 5, 2022, 10:57:01 AM11/5/22
to google-apps-sc...@googlegroups.com
Hi Andrew,

Thanks for your suggestion. I tried it, but still doesn't work...

I can't figure out what it's wrong with the code

function doPost(e) {
  const contents = JSON.parse(e.postData.contents)
   SpreadsheetApp.openById(sheet_residence_ID).getSheetByName("Log").appendRow([contents]);
 };

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/SMuatFumaxo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAN1QPJSYP-2Q9tZ8dPwQviSixh35cjZPyq_3F9gUnpe74cpXuQ%40mail.gmail.com.

Andrew Roberts

unread,
Nov 6, 2022, 3:34:26 AM11/6/22
to google-apps-sc...@googlegroups.com
Are you getting an error in "Executions"? Is anything coming out to the sheet?

What you can do is attach the script to a GCP project and you can then look at a console.log(e.postData.contents) to see what's coming in.

Reply all
Reply to author
Forward
0 new messages