-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use webhooks for discord notification #84
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6c704b2
fix: changed bot token to webhook
0xGorilla 537ef50
fix: added discord notifier
0xGorilla 8807e3f
fix: uncommented index
0xGorilla b1757bd
style: lint
0xGorilla 139da81
Merge remote-tracking branch 'origin/dev' into fix/discord-webhook
jahabeebs 27c1f7d
feat: better notification logic
jahabeebs f6ceff2
fix: pr comments
jahabeebs 84c0df8
fix: as unknown
jahabeebs 85fb6cf
fix: excess messages
jahabeebs 1aed46b
chore: docs
jahabeebs b467c85
fix: stringify
jahabeebs 1b1aab9
fix: this.actor and tests
jahabeebs e281b9e
fix: pr comments
jahabeebs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could add some link referring to Discord docs on how to create your Webhook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅