Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 35 36 37 | import { env } from "../../config"
import { AbstractNotifier } from "./notifier"
export class DiscordNotifier extends AbstractNotifier {
constructor() {
super()
}
override async sendMessage(content: string): Promise<string> {
const result = await fetch(`${env.discordWebhook}?wait=true`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content }),
})
if (!result.ok) {
throw new Error(`Failed to send message to Discord webhook: ${result.status} ${result.statusText}`)
}
const data = await result.json()
return data.id
}
override async deleteMessage(id: string): Promise<void> {
const result = await fetch(`${env.discordWebhook}/messages/${id}`, { method: "DELETE" })
if (!result.ok) {
throw new Error(`Failed to delete message with ID ${id} from Discord webhook: ${result.status} ${result.statusText}`)
}
}
override async deleteAllMessages(): Promise<void> {
throw new Error("Bulk deletion of messages is not supported by Discord webhooks.")
}
override async hasMessageId(_messageId: string): Promise<boolean> {
throw new Error("Checking message existence is not supported by Discord webhooks.")
}
}
|