-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprovider.ts
More file actions
34 lines (29 loc) · 1.02 KB
/
provider.ts
File metadata and controls
34 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import NotificationsProvider from 'hawk-worker-sender/src/provider';
import { Notification } from 'hawk-worker-sender/types/template-variables';
import { toDelivery } from './templates';
import WebhookDeliverer from './deliverer';
/**
* Webhook notification provider.
* Supports all notification types via a single generic serializer —
* type comes from notification.type, payload is sanitized automatically.
*/
export default class WebhookProvider extends NotificationsProvider {
/**
* Class with the 'deliver' method for sending HTTP POST requests
*/
private readonly deliverer: WebhookDeliverer;
constructor() {
super();
this.deliverer = new WebhookDeliverer();
}
/**
* Send webhook notification to recipient
*
* @param to - recipient endpoint URL
* @param notification - notification with payload and type
*/
public async send(to: string, notification: Notification): Promise<void> {
const delivery = toDelivery(notification);
await this.deliverer.deliver(to, delivery);
}
}