Skip to content

Commit

Permalink
forward errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vaaski committed Apr 10, 2024
1 parent 72db149 commit cc46e90
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/botutil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Chat, Message } from "grammy/types"
import { ADMIN_ID } from "./environment"
import { bot } from "./setup"

export const deleteMessage = (message: Message) => {
Expand All @@ -9,7 +10,16 @@ export const errorMessage = (chat: Chat, error?: string) => {
let message = bold("An error occurred.")
if (error) message += `\n\n${code(error)}`

return bot.api.sendMessage(chat.id, message, { parse_mode: "HTML" })
const tasks = [() => bot.api.sendMessage(chat.id, message, { parse_mode: "HTML" })]

if (chat.id === ADMIN_ID) {
let adminMessage = `Error in chat ${mention("user", chat.id)}`
if (error) adminMessage += `\n\n${code(error)}`

tasks.push(() => bot.api.sendMessage(ADMIN_ID, adminMessage, { parse_mode: "HTML" }))
}

return Promise.all(tasks.map((task) => task()))
}

// prettier-ignore
Expand Down

0 comments on commit cc46e90

Please sign in to comment.