-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic webhook notifier --------- Co-authored-by: charlocharlie <[email protected]>
- Loading branch information
1 parent
2734e6b
commit 734c18d
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import axios from 'axios'; | ||
import logger from '../common/logger'; | ||
import { NotifierService } from './notifier-service'; | ||
import { NotificationReason } from '../interfaces/notification-reason'; | ||
import { WebhookConfig } from '../common/config'; | ||
|
||
export class WebhookNotifier extends NotifierService { | ||
private config: WebhookConfig; | ||
|
||
constructor(config: WebhookConfig) { | ||
super(); | ||
this.config = config; | ||
} | ||
|
||
async sendNotification(account: string, reason: NotificationReason, url?: string): Promise<void> { | ||
const L = logger.child({ user: account, reason }); | ||
L.trace('Sending webhook notification'); | ||
|
||
try { | ||
await axios.post( | ||
this.config.url, | ||
{ | ||
account, | ||
reason, | ||
url, | ||
}, | ||
{ | ||
responseType: 'json', | ||
headers: this.config.headers, | ||
} | ||
); | ||
} catch (err) { | ||
L.error(err); | ||
L.error( | ||
{ webhookConfig: this.config }, | ||
'Error sending webhook message. Please check your configuration' | ||
); | ||
throw err; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters