Hi All,
Great discussion! Hmm…
So lets say we want to offer a data service via webhooks, providing the weather to any device:
webhook:
{
"event": "get_weather",
"url": "http://api.openweathermap.org/data/2.5/weather?q={{loc}}&mode=json",
"requestType": "GET",
"responseTemplate": "{{#weather}}{{description}}{{/weather}}",
"mydevices": false
}
So now anyone publishing “get_weather”, with a JSON contents with ‘loc’ set will trigger this hook:
Spark.publish("get_weather", "{ \"loc\": \"Shenzhen\"}");
So, now we have a webhook that anyone or any of your products can share, but we don’t want every single device to hear every single weather response for everyone else, we only want to hear messages relevant to us…
So far, the easiest way to do that is change the client subscription based on the published event name, but that doesn’t work well here. So… Hmmmmm…
We already have the concept of a response template… what if we had a “responseTopic” setting, so you could key in the same way? In this case, we might add this to the hook:
#proposed setting:
responseTopic: "hook/weather/{{loc}}"
So then we’d subscribe to:
Spark.subscribe("hook/weather/Shenzhen", gotWeatherData);
Would that work?
Thanks!
David