Make a Twilio phone call when movement detected

Hi all

after sending SMS when a movement is detected, I would like to make a phone call instead! :=)
On my Twilio dashboard, the following json request makes a phone call :

{
  "sid": "CA76ed3f291e6738edbc85a8f1a5fbeec5",
  "date_created": null,
  "date_updated": null,
  "parent_call_sid": null,
  "account_sid": "ACddd5df3d096d9daf908cb1f07e553900",
  "to": "+33676801613",
  "to_formatted": "+3367xxx613",
  "from": "+33644605349",
  "from_formatted": "+336xxx5349",
  "phone_number_sid": "PN8ca405d90817xxxxxf0ec3ac",
  "status": "queued",
  "start_time": null,
  "end_time": null,
  "duration": null,
  "price": null,
  "price_unit": "USD",
  "direction": "outbound-api",
  "answered_by": null,
  "api_version": "2010-04-01",
  "annotation": null,
  "forwarded_from": null,
  "group_sid": null,
  "caller_name": null,
  "uri": "/2010-04-01/Accounts/ACddd5df3d096d9daf90xxxxx6ed3f291e6738edbc85a8f1a5fbeec5.json",
  "subresource_uris": {
    "notifications": "/2010-04-01/Accounts/ACddd5df3d096d9daf908cb1f07e5539xxxxd3f291e6738edbc85a8f1a5fbeec5/Notifications.json",
    "recordings": "/2010-04-01/Accounts/ACddd5df3d096d9daf908cb1f07e553900/Calls/xxxxx38edbc85a8f1a5fbeec5/Recordings.json"
  }
}  

Using this, could you help me to create the right webhook and firmware code allowing me do that ? the firmware code I used to send a SMS was the following, but not sure what I need to modify to do a phone call :

void setup() {
    pinMode(A0, INPUT);
}

void loop() {
    if (digitalRead(A0) == HIGH) {
        Spark.publish("twiliosms", "something just happens", 60, PRIVATE);
        while (digitalRead(D0) == HIGH); // hang tight here until motion stops
    }
} 

Thanks a lot for your great help ! It could be a great tutorial at the end of the day, and for sure I will write if we success to make it happen, thanks !

What have you tried so far, and what hasn’t worked? Have you tried changing the SMS code you’ve got?

the problem is I don’t really see what to change, what fields are mandatory etc… I read the Call request tutorial on Twilio https://www.twilio.com/docs/quickstart/php/rest/call-request

On my dashboard to make it work, I use http://demo.twilio.com/welcome/voice/ in POST URL, but except that I don’t really see what I need to put in my webhook and firmware code … :frowning:

I tried something like that…of course didnt work :

firmware :

void setup() {
    pinMode(A0, INPUT);
}

void loop() {
    if (digitalRead(A0) == HIGH) {
        Spark.publish("twiliocall", "something just happens", 60, PRIVATE);
        while (digitalRead(A0) == HIGH); // hang tight here until motion stops
    }
} 

and the code which generated the webhook

{
    "eventName": "twiliocall",
    "url": "https://api.twilio.com/2010-04-01/Accounts/ACddd5xxxx1f07e553900/Calls",
    "uri": "https://api.twilio.com/2010-04-01/Accounts/Calls",
    "requestType": "POST",
    "auth": {
        "username": "ACddd5df3dxxxxx08cb1f07e553900",
        "password": "434298c14e25bxxxx2a71d"
    },
    "form": {
  "to": "+3367xxx613",
  "to_formatted": "+33676xxx13",
  "from": "+3364xx49",
  "from_formatted": "+33644xxx349",
  "phone_number_sid": "PN8ca405xxx9e5a47cc369f0ec3ac"
    },
    "mydevices": true
}

yep,

anyone would have an idea ? or already done it ? thanks a lof for your feedback

Hi all, up for this post, if anyone already worked on this kind of project or know how to do it;…thanks

Editing the SMS code, I came up with this. Keep in mind that it’s untested, and I don’t guarantee it’ll work. I combined it with some things from @hoxworth’s tutorial. Then I’ve checked the REST API specs from Twilio, which tells you the requirements.
You’ll have to go through this and make edits where necessary, but this should work (I hope):

{
  "eventName": "twilio",
  "url": "https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Calls",
  "requestType": "POST",
  "auth": {
    "username": "ACCOUNT_SID",
    "password": "AUTH_TOKEN"
  },
  "form": {
    "From" : "FROM_TWILIO_NUMBER",
    "To" : "TO_NUMBER",
    "ApplicationSid": "ApplicationDif_HERE", //if you use this, you don't need the following URL
    "url": "URL_HERE"
    //check here for more information about the URL parameters: https://www.twilio.com/docs/api/rest/making-calls#application-sid-parameter
  },
  "mydevices": true
}

Hi Moors, thanks a lot I’m testing it right now, then it don’t work for moment, but maybe I missed something.:
AT the line ApplicationSID, I need to enter the App Sid coming from the TWIML app I created. But what I need to fill in in the Voice request URL field ?

Also, the value “url” should be used for what ?
OK I’m sure we are close the a working solution, almost…THANKS a lot for your feedback! :slight_smile:

Here’s some of the official info about the ApplicationSID, and here’s some about the URL. Note that you only need one of them, and which one you prefer is up to you.
Regarding the Voice request URL, clich the question mark to see what it does(?). I’ve never used Twilio, so I’m afraid I can’t help you there.