4

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?

Steve Nay
  • 2,819
  • 1
  • 30
  • 41

1 Answers1

2

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.

Community
  • 1
  • 1
TelegramSam
  • 2,770
  • 1
  • 17
  • 22
  • Awesome! I didn't know there was a webhook endpoint like this. That solves the problem beautifully. – Steve Nay Apr 09 '11 at 05:48
  • Turns out, you weren't the first one with this problem. :) Happy to have solved your problem in advance of you having it. – TelegramSam Apr 10 '11 at 21:08