-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bot-monitor: persist same webKey in db as used in emails
- Loading branch information
1 parent
03afa7f
commit 5f736ba
Showing
3 changed files
with
9 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,18 +61,18 @@ export class Alert { | |
log(`[i] Sending email for "${this.name}" to ${this.rule.email}`); | ||
let subject = `[${this.rule.bot}] ${this.rule.task} failure`; | ||
|
||
const webKey = crypto.randomBytes(32).toString('hex'); | ||
this.rule.webKey = crypto.randomBytes(32).toString('hex'); | ||
if (this.rule.email.includes('@')) { | ||
await mailTransporter.sendMail({ | ||
from: '[email protected]', | ||
to: this.rule.email, | ||
subject: subject, | ||
html: this.getEmailBodyHtml(webKey), | ||
html: this.getEmailBodyHtml(), | ||
}); | ||
} else { | ||
await new bot.User(this.rule.email).email( | ||
subject, | ||
this.getEmailBodyPlain(webKey), | ||
this.getEmailBodyPlain(), | ||
{ccme: true} | ||
).catch(err => { | ||
if (err.code === 'notarget') { | ||
|
@@ -88,24 +88,24 @@ export class Alert { | |
}); | ||
} | ||
|
||
getEmailBodyHtml(webKey: string): string { | ||
getEmailBodyHtml(): string { | ||
const taskKey = `${this.rule.bot}: ${this.rule.task}`; | ||
return `${this.rule.bot}'s task <b>${this.rule.task}</b> failed to run per the configuration specified at <a href="https://en.wikipedia.org/wiki/Wikipedia:Bot_activity_monitor/Configurations">Wikipedia:Bot activity monitor/Configurations</a>. Detected only ${this.actions} ${this.rule.action === 'edit' ? 'edit' : `"${this.rule.action}" action`}s in the last ${this.rule.duration}, whereas at least ${this.rule.minEdits} were expected.` + | ||
`<br><br>` + | ||
`If your bot is behaving as expected, then you may want to <a href="https://en.wikipedia.org/wiki/Wikipedia:Bot_activity_monitor/Configurations?action=edit">modify the task configuration instead</a>. Or to unsubscribe from these email notifications, remove the |email= parameter from the {{/task}} template.` + | ||
`<br><br>` + | ||
`To temporarily pause these notifications, click here: https://sdzerobot.toolforge.org/bot-monitor/pause?task=${encodeURIComponent(taskKey)}&webKey=${webKey}` + | ||
`To temporarily pause these notifications, click here: https://sdzerobot.toolforge.org/bot-monitor/pause?task=${encodeURIComponent(taskKey)}&webKey=${this.rule.webKey}` + | ||
`<br><br>` + | ||
`Thanks!`; | ||
} | ||
|
||
getEmailBodyPlain(webKey: string): string { | ||
getEmailBodyPlain(): string { | ||
const taskKey = `${this.rule.bot}: ${this.rule.task}`; | ||
return `${this.rule.bot}'s task "${this.rule.task}" failed to run per the configuration specified at Wikipedia:Bot activity monitor/Configurations (<https://en.wikipedia.org/wiki/Wikipedia:Bot_activity_monitor/Configurations>). Detected only ${this.actions} ${this.rule.action === 'edit' ? 'edit' : `"${this.rule.action}" action`}s in the last ${this.rule.duration}, whereas at least ${this.rule.minEdits} were expected.` + | ||
`\n\n` + | ||
`If your bot is behaving as expected, then you may want to modify the task configuration instead. Or to unsubscribe from these email notifications, remove the |email= parameter from the {{/task}} template.` + | ||
`\n\n` + | ||
`To temporarily pause these notifications, click here: https://sdzerobot.toolforge.org/bot-monitor/pause?task=${encodeURIComponent(taskKey)}&webKey=${webKey}` + | ||
`To temporarily pause these notifications, click here: https://sdzerobot.toolforge.org/bot-monitor/pause?task=${encodeURIComponent(taskKey)}&webKey=${this.rule.webKey}` + | ||
`\n\n` + | ||
`Thanks!`; | ||
} | ||
|
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