toggl-webhook-express
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

toggl-webhook-express

Install

npm install --save toggl-webhook

Usage

import express from 'express';
import { webhookHandler } from 'toggl-webhook-express';

const app = express();
const port = 3001;

app.use(express.json());

const webhook = webhookHandler({
  secretProvider: 'shhhh' // same secret as used in your webhook subscription
});

app.post('/hook/', webhook, (req, res) => {
  const { body } = req;

  console.log('valid webhook event recieved', {date: new Date(), body});
  res.json({status: 'OK'});
});

Provide a secret based on incoming request

const webhook = webhookHandler({
  secretProvider: async (req: Request): Promise<string | null> => {
    // return secret based on request params (eg. based on userId)
  }
});

Disable autoValidate

By default all incoming ping requests that have a validation_code set in the body are validated by default. All other ping requests are just logged. To disable this feature set autoValidate to false.

const webhook = webhookHandler({
  autoValidate: false
});

Provide a custom logger

import { Logger } from 'toggl-webhook-express';

class MyLogger implements Logger {
  info(msg: string, tag: string, meta: unknown) {
    console.info(tag, msg, meta);
  }
  warning(msg: string, tag: string, meta: unknown) {
    console.warn(tag, msg, meta);
  }
}

const webhook = webhookHandler({
  logger: new MyLogger()
});

Create a subscription

toggl-webhook provides a node.js API wrapper for the toggl webhook api.

Package Sidebar

Install

npm i toggl-webhook-express

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

10 kB

Total Files

11

Last publish

Collaborators

  • pixtron