https://github.com/pixtron/toggl-webhook-express
Express middleware to validate toggl webhook requests
https://github.com/pixtron/toggl-webhook-express
express middleware toggl webhook
Last synced: 2 months ago
JSON representation
Express middleware to validate toggl webhook requests
- Host: GitHub
- URL: https://github.com/pixtron/toggl-webhook-express
- Owner: pixtron
- License: mit
- Created: 2022-06-26T14:24:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-27T15:48:41.000Z (almost 4 years ago)
- Last Synced: 2025-10-10T20:57:50.671Z (8 months ago)
- Topics: express, middleware, toggl, webhook
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/toggl-webhook-express
- Size: 144 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# toggl-webhook-express
## Install
```
npm install --save toggl-webhook
```
## Usage
```ts
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
```ts
const webhook = webhookHandler({
secretProvider: async (req: Request): Promise => {
// 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](https://developers.track.toggl.com/docs/webhooks_start/url_endpoint_validation) by default. All other ping requests are just logged. To disable this feature set `autoValidate` to false.
```ts
const webhook = webhookHandler({
autoValidate: false
});
```
### Provide a custom logger
```ts
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](https://www.npmjs.com/package/toggl-webhook) provides a node.js API wrapper for the [toggl webhook api](https://developers.track.toggl.com/docs/webhooks/subscriptions).