-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use webhooks for discord notification (#84)
- Loading branch information
Showing
18 changed files
with
417 additions
and
236 deletions.
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
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { z } from "zod"; | ||
|
||
const ConfigSchema = z.object({ | ||
DISCORD_BOT_TOKEN: z.string().min(1), | ||
DISCORD_CHANNEL_ID: z.string().min(1), | ||
DISCORD_WEBHOOK: z.string().url().optional(), | ||
}); | ||
|
||
export const config = ConfigSchema.parse(process.env); |
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
6 changes: 6 additions & 0 deletions
6
packages/automated-dispute/src/exceptions/notificationFailure.exception.ts
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,6 @@ | ||
export class NotificationFailureException extends Error { | ||
constructor(message: string) { | ||
super(`Failed to send notification: ${message}`); | ||
this.name = "NotificationFailureException"; | ||
} | ||
} |
74 changes: 68 additions & 6 deletions
74
packages/automated-dispute/src/interfaces/notificationService.ts
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 |
---|---|---|
@@ -1,13 +1,75 @@ | ||
/** | ||
* Interface representing a notification service capable of sending error notifications. | ||
* Represents a notification message. | ||
*/ | ||
export interface IMessage { | ||
/** | ||
* The main content of the message. | ||
*/ | ||
title: string; | ||
/** | ||
* An optional subtitle for the message. | ||
*/ | ||
subtitle?: string; | ||
/** | ||
* An optional description providing more details. | ||
*/ | ||
description?: string; | ||
/** | ||
* The username to display as the sender. | ||
*/ | ||
username?: string; | ||
/** | ||
* The URL of the avatar image to display. | ||
*/ | ||
avatarUrl?: string; | ||
/** | ||
* An optional URL associated with the message. | ||
*/ | ||
actionUrl?: string; | ||
} | ||
|
||
/** | ||
* Interface representing a notification service capable of sending notifications. | ||
*/ | ||
export interface NotificationService { | ||
/** | ||
* Sends an error notification along with optional contextual information. | ||
* Sends a notification message. | ||
* | ||
* @param {IMessage} message - The message to send. | ||
* @returns {Promise<void>} A promise that resolves when the message is sent. | ||
*/ | ||
send(message: IMessage): Promise<void>; | ||
|
||
/** | ||
* Sends a notification message and throws an exception if sending fails. | ||
* | ||
* @param {IMessage} message - The message to send. | ||
* @returns {Promise<void>} A promise that resolves when the message is sent. | ||
* @throws {NotificationFailureException} If sending the message fails. | ||
*/ | ||
sendOrThrow(message: IMessage): Promise<void>; | ||
|
||
/** | ||
* Creates an IMessage from an error. | ||
* | ||
* @param {string} defaultMessage - A default message describing the error context. | ||
* @param {unknown} [context] - Additional context for the error. | ||
* @param {unknown} [err] - The error object. | ||
* @returns {IMessage} An IMessage object ready to be sent via the notifier. | ||
*/ | ||
createErrorMessage(defaultMessage: string, context?: unknown, err?: unknown): IMessage; | ||
|
||
/** | ||
* Sends an error notification message. | ||
* | ||
* @param error - The error object containing information about the error that occurred. | ||
* @param context - Additional context or data related to the error | ||
* @returns A promise that resolves when the notification process is complete. | ||
* @param {string} defaultMessage - A default message describing the error context. | ||
* @param {Record<string, unknown>} [context] - Additional context for the error. | ||
* @param {unknown} [err] - The error object. | ||
* @returns {Promise<void>} A promise that resolves when the message is sent. | ||
*/ | ||
notifyError(error: Error, context: any): Promise<void>; | ||
sendError( | ||
defaultMessage: string, | ||
context?: Record<string, unknown>, | ||
err?: unknown, | ||
): Promise<void>; | ||
} |
Oops, something went wrong.