-1

I've set up my Photon to control a neopixel and want to changed the color based on a parameter sent by the user via SMS.

I know how to send SMS from my particle to my phone using a Twilio POST webhook (hook1Ask() below is working), but I can't find anything online about communication going the other way around (GET webhook for SMS).

I read the particle docs on webhooks and Particle.subscribe, and scoured the inter webs for any answer, but so far, nada.

Here's my code:

//States keep it from sending too many messages
# define STATE_1 1
# define STATE_2 2    
int state = 1; 

//Variables to keep things tidy
String HOOK_1_ASK = "HOOK_1_ASK";  
String HOOK_1_REPLY = "HOOK_1_REPLY";
String data = String(10);

void setup()
{
  Serial.begin(9600);
  Particle.subscribe("HOOK_1_REPLY", myHandler);
}

void loop()
{
   hook1Ask();
   delay(100);
}


//***************************************************
// Webhook event trigger
//***************************************************

void hook1Ask(){   
  if( state == 1 ){
    String data = "What's your favorite color? 1=Blue 2=Green 3=Something else";
    Particle.publish("HOOK_1_ASK", data, PRIVATE);
    state = STATE_2;
  }

}

//***************************************************
// myHandler for the subscribe event
//***************************************************

int i = 0;

void myHandler(const char *event, const char *data)
{
  i++;
  Serial.print(i);
  Serial.print(event);
  Serial.print(", data: ");
  if (data)
    Serial.println(data);
  else
    Serial.println("NULL");
}

1 Answers1

0

Twilio developer evangelist here.

I'm not sure if I'm right here, as I've not used a Particle, but it seems that "webhooks" in Particle terms are endpoints in the Particle service that receive data from the Particle device itself.

You can make external API calls to your Particle via the Particle Cloud API. This requires an OAuth token to authenticate, so you can't connect a Twilio SMS Webhook (an HTTP request that Twilio sends when it receives an SMS message) directly to the API. However you could build a small web server that received Twilio webhooks and then made an authorised request on to the Particle Cloud API with the details you want.

Does that help at all?

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks for clarifying! I forgot to close the loop here but I ended up figuring it out. TLDR I created a ruby app with Twilio and Heroku and used the particle gem to get it to play nicely with my photon. Here are the details on the ruby gem I used in case anyone wants to take a look: https://github.com/monkbroc/particlerb Thanks again! – MelissaP May 29 '17 at 17:32
  • Hey @MelissaP, that's awesome. Did my answer help enough that you'd mark it as correct? I'd love to see a write up on how you achieved this too, if you were planning a blog post perhaps? – philnash May 30 '17 at 19:54