I'd like to write a ruleset that can respond to webhook events with raw data. The event might come in from a URL like the following:
http://cs.kobj.net/blue/event/rest/echo/a163x85/?a163x85:kynetx_app_version=dev&body=hi%20there
I can use the send_directive()
action, but that returns a lot of JSON that I don't necessarily want:
// KNS Fri Apr 8 19:40:40 2011
{"directives":[{"options":{"body":"hi there"},"name":"echo","meta":{"rule_name":"echo","txn_id":"154CEDCC-6218-11E0-9E71-726A5E50CE3F","rid":"a163x85"}}]}
Is there a way to respond with just raw data, rather than with a whole directive structure?
The answer is to use the Webhook Endpoint to interact with KNS, not directly signal an event.
You would signal your event like so:
http://webhooks.kynetxapps.net/h/a163x85.dev/echo?body=hi%20there
And a rule like so:
rule x {
select when webhook echo
pre {
body = event:param("body");
response = { 'thebody': body };
rjson = response.encode();
}
send_directive("json") with body = rjson;
}
For a response like:
{"thebody":"hi there"}
Note the .dev
in the URL for indicating the dev version of the app, echo
as the event name, and the event domain of webhook
.
The endpoint will even serve it with the proper mime/type for json.
Also note you can return html, xml, js, plain text, and even a redirect. Check the Webhook Endpoint Docs for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.