Skip to content

Commit db77328

Browse files
committed
Set custom message for predIQt alerts
1 parent dac97ff commit db77328

1 file changed

Lines changed: 66 additions & 9 deletions

File tree

β€Žsrc/services/wikiUpdates.tsβ€Ž

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,68 @@ export default class WikiUpdates {
9393
return errorEmbed
9494
}
9595

96+
private async messagePrediqtErrorStyle(url: string, errorCode: string) {
97+
let description = `πŸ“Š Error code: ${errorCode}`
98+
let color: number = 0xff0000
99+
let title = `πŸ“‰ PrediQT API is down πŸ“‰`
100+
101+
if (errorCode === 'TIMEOUT') {
102+
description = `πŸ“Š PredIQt API is unresponsive (timeout after 30 seconds)\nπŸ“‰ The prediction market service is not responding within the expected timeframe.`
103+
color = 0xff6600
104+
title = `πŸ“‰ PredIQt API Timeout`
105+
} else if (errorCode === 'HEALTH_CHECK_FAILED') {
106+
description = `πŸ“Š PredIQt API health check failed - service may be down\nπŸ“‰ Automated monitoring detected an issue with the PredIQt API endpoint.`
107+
color = 0xcc0000
108+
title = `πŸ“‰ PredIQt API Health Check Failed`
109+
}
110+
111+
const errorEmbed = new EmbedBuilder()
112+
.setColor(color)
113+
.setTitle(title)
114+
.setURL(url)
115+
.setDescription(description)
116+
.addFields([
117+
{ name: 'πŸ“Š Service', value: 'PredIQt', inline: true },
118+
{ name: 'πŸ”— URL', value: url, inline: false },
119+
{ name: '⏰ Time', value: new Date().toLocaleString(), inline: true },
120+
])
121+
.setTimestamp()
122+
.setFooter({
123+
text: 'EP Bot PrediQT Monitor',
124+
})
125+
return errorEmbed
126+
}
127+
128+
async notifyPrediqtError(errorCode: string) {
129+
try {
130+
const webhookUrl = this.PROD_ALARMS_WEBHOOK
131+
132+
if (!webhookUrl) {
133+
console.error(`❌ Webhook URL not configured for PrediQT alerts`)
134+
return
135+
}
136+
137+
const webhook = new WebhookClient({ url: webhookUrl })
138+
139+
console.log(`πŸ“‰ Sending PrediQT error notification for ${errorCode}`)
140+
141+
const alertUserId = process.env.ALERT_USER_ID
142+
const mentionText = alertUserId ? `<@${alertUserId}> ` : ''
143+
144+
await webhook.send({
145+
content: mentionText,
146+
embeds: [
147+
await this.messagePrediqtErrorStyle(this.PREDIQT_API_URL, errorCode),
148+
],
149+
})
150+
151+
console.log('βœ… PrediQT alert sent successfully')
152+
webhook.destroy()
153+
} catch (error) {
154+
console.error(`❌ Failed to send PrediQT error notification:`, error)
155+
}
156+
}
157+
96158
async notifyError(
97159
count: number,
98160
channelType: ChannelTypes,
@@ -418,13 +480,8 @@ export default class WikiUpdates {
418480
)
419481

420482
if (!currentStatus?.alertSent) {
421-
console.log(`🚨 Sending initial error alert for PrediQT`)
422-
await this.notifyError(
423-
1,
424-
ChannelTypes.PROD,
425-
this.PREDIQT_API_URL,
426-
'HEALTH_CHECK_FAILED',
427-
)
483+
console.log(`πŸ“‰ Sending initial error alert for PrediQT`)
484+
await this.notifyPrediqtError('HEALTH_CHECK_FAILED')
428485

429486
this.apiHealthStatus.set('PREDIQT', {
430487
isHealthy: false,
@@ -440,12 +497,12 @@ export default class WikiUpdates {
440497
)
441498

442499
if (previousStatus && !previousStatus.isHealthy && previousStatus.alertSent) {
443-
console.log(`πŸŽ‰ PrediQT API has recovered!`)
500+
console.log(`πŸ“ˆ PrediQT API has recovered!`)
444501
const webhookUrl = this.PROD_ALARMS_WEBHOOK
445502
if (webhookUrl) {
446503
const webhook = new WebhookClient({ url: webhookUrl })
447504
await webhook.send(
448-
`βœ… **RECOVERY** - PrediQT API is back online! πŸŽ‰`,
505+
`πŸ“ˆ **RECOVERY** - PrediQT API is back online! πŸ“Š`,
449506
)
450507
webhook.destroy()
451508
}

0 commit comments

Comments
Β (0)