diff --git a/examples/action-invokers/imbroadcaster.coffee b/examples/action-invokers/imbroadcaster.coffee new file mode 100644 index 0000000..88e2acc --- /dev/null +++ b/examples/action-invokers/imbroadcaster.coffee @@ -0,0 +1,25 @@ +arrHooks = [] + +broadcast = ( msg ) -> + log 'broadcasting: ' + msg + for hook in arrHooks + log '... to ' + hook + options = + method: 'POST' + json: true + jar: true + url: hook + body: msg + request options, ( err, resp, body ) -> + if err or resp.statusCode isnt 200 + log "Error in pushing data to webhook '#{ url }'!" + else + log "Successfully posted data to '#{ url }'" + +exports.message = ( msg ) -> + if msg.webhook + hook = msg.webhook.replace /(\r\n|\n|\r|\s)/gm, "" + log 'Registering new IM webhook: ' + hook + arrHooks.push hook + else if msg.message + broadcast msg.message diff --git a/examples/action-invokers/webhook.coffee b/examples/action-invokers/webhook.coffee new file mode 100644 index 0000000..0164d06 --- /dev/null +++ b/examples/action-invokers/webhook.coffee @@ -0,0 +1,22 @@ + +# Webhook Action Invoker +# ---------------------- + +# Sends data to a remote Webhook + +options = + method: 'POST' + json: true + jar: true + +exports.post = ( url, data ) -> + if not data + data = {} + + options.url = url + options.body = data + request options, ( err, resp, body ) -> + if err or resp.statusCode isnt 200 + log "Error in pushing data to webhook '#{ url }'!" + else + log "Successfully posted data to '#{ url }'"