segment-webhook

1.0.0 • Public • Published

segment-webhook

NPM version Build status Test coverage Dependency Status License Downloads Gittip

Koa middleware for Segment Webhooks Integration.

API

const JSONStream = require('JSONStream')
const app = require('koa')()
 
const webhooks = new Map()
webhooks.set('/webhooks/production', 'production')
webhooks.set('/webhooks/debug', 'debug')
 
const webhook = require('segment-webhook')(webhooks)
 
app.use(webhook)
 
webhook.pipe(JSONStream.stringify()).pipe(process.stdout)
 
webhook.stream.on('data', function (obj) {
  console.log(JSON.stringify(obj))
})

Returns Koa middlweare.

const fn = SegmentWebhooks(webhooks)

webhooks is a required Map of path -> project_name. The project_name will be set on each object as .project. This allows you to differentiate against different projects and environments while using the same webhook for all of them.

fn.pipe([dest])

Pipe all the objects into another stream. The destination must also be in objectMode

fn.stream.on('data', obj => )

Listen for all objects being passed.

fn.stream.on(type, obj => )

Filter by data types, ex. page, identify, track, etc.

Package Sidebar

Install

npm i segment-webhook

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • jongleberry