mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
New examples started
This commit is contained in:
parent
42d16c30d7
commit
2289e89507
2 changed files with 47 additions and 0 deletions
25
examples/action-invokers/imbroadcaster.coffee
Normal file
25
examples/action-invokers/imbroadcaster.coffee
Normal file
|
|
@ -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
|
||||
22
examples/action-invokers/webhook.coffee
Normal file
22
examples/action-invokers/webhook.coffee
Normal file
|
|
@ -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 }'"
|
||||
Loading…
Reference in a new issue