npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-spark-webhook

v1.0.3

Published

Cisco Spark API Webhook Utility Library for Node JS.

Downloads

6

Readme

node-spark-webhook

Cisco Spark API Web Hook Utility Library for Node JS.

This library parses an incoming Cisco Spark API web hook and emits events based on the content. This library does not interface with the Spark API and is intended to simplify functions around web hook parsing and authenticating HMAC secured web hooks only.

Example: (embedded into an express.js app)

"use strict";

var Webhook = require('node-spark-webhook');
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');

var webhook = new Webhook();

// add events
webhook.on('request', function(hook) {
  console.log('%s.%s web hook received', hook.resource, hook.event)
});

var app = express();
app.use(bodyParser.json());

// add route for path that which is listening for web hooks
app.post('/spark', webhook.listen());

// start express server
var server = app.listen('3000', function () {
  console.log('Listening on port %s', '3000');
});

Install:

npm install --save node-spark-webhook

Initialization / Config

The constructor accepts an optional options object.

var Webhook = require('node-spark-webhook');

var options = {
  secret: 'My HMAC Secret',
  reqObjProp: 'params'
};

var webhook = new Webhook(options);

Options Object

  • secret : If specified, the incoming web hook will be authenticated before being processed through the webhook.listen() function.
  • reqObjProp : Property of request object where the string or JSON object of the incoming body is parsed to. If not specified, defaults to "body". Some Connect based libraries (Express/Restify/etc) alter this location based on their defaults and which extensions you have enabled. Typically, if not "body", "params" is the request property where the body is passed.

Reference

webhook.listen()

Returns a function with properties req and res. When embedded in a connect based web app such as express.js, allows easy processing and validation (including HMAC if secret is specified) of an incoming web hook. Once validated, emits events based on the web hook's resource value.

webhook.auth(payload, signature, secret [, callback]))

Should you simply need to authenticate a web hook, you can access the auth function directly.

  • payload : request body in JSON or string format
  • signature : HMAC signature retrieved from the 'x-spark-signature' header property
  • secret : The secret used when creating the web hook from the Spark API
  • callback : (optional) If specified executes a callback with properties (err, body). If not specified, returns a promise fulfilled with the body, or rejected with the error.

Events

The library will emit events based on the value of the resource property of the incoming webhook. For example, to capture a new room membership:

webhook.on('memberships', function(event, membershipObj, req) {
  if(event == 'created') {
    console.log('%s added to room', membershipObj.personDisplayName);
  }
});

Note: The web hooks you receive depend on how you originally created the web hook from the Spark API.

Additionally, a more generic event named "request" is triggered on every validated web hook. This event returns a single property that contains the request body as an object. For example:

webhook.on('request', function(hook, req) {
  console.log('%s.%s web hook received', hook.resource, hook.event)
});

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.