-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from pendulum-chain/216-monitor-the-funding-a…
…ccount-of-vortex Ready: monitor the funding account of vortex
- Loading branch information
Showing
11 changed files
with
245 additions
and
12 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ docs/ | |
.lighthouseci/ | ||
**/coins/* | ||
*.yml | ||
*.sol | ||
|
||
package-lock.json | ||
package.json | ||
|
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,3 +1,3 @@ | ||
/api/production/* https://prototype-signer-service-polygon.pendulumchain.tech/:splat 200 | ||
/api/staging/* https://prototype-signer-service-polygon-staging.pendulumchain.tech/:splat 200 | ||
/* /index.html 200 | ||
/* /index.html 200 |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Store last message timestamps with their message signatures | ||
const messageHistory = new Map(); | ||
// 6 hours in milliseconds | ||
const cooldownPeriod = 6 * 60 * 60 * 1000; | ||
|
||
class SlackNotifier { | ||
constructor() { | ||
if (process.env.SLACK_WEB_HOOK_TOKEN) { | ||
this.webhookUrl = `https://hooks.slack.com/services/${process.env.SLACK_WEB_HOOK_TOKEN}`; | ||
} else { | ||
throw new Error('SLACK_WEB_HOOK_TOKEN is not defined'); | ||
} | ||
} | ||
|
||
generateMessageSignature(message) { | ||
// Create a unique signature for the message | ||
return JSON.stringify(message); | ||
} | ||
|
||
isMessageAllowed(signature) { | ||
const now = Date.now(); | ||
const lastSent = messageHistory.get(signature); | ||
|
||
if (!lastSent) return true; | ||
|
||
return now - lastSent >= cooldownPeriod; | ||
} | ||
|
||
async sendMessage(message) { | ||
const signature = this.generateMessageSignature(message); | ||
|
||
if (!this.isMessageAllowed(signature)) { | ||
// Message is still in cooldown period, skip sending | ||
return; | ||
} | ||
|
||
const payload = JSON.stringify(message); | ||
|
||
const response = await fetch(this.webhookUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: payload, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to send message. Status: ${response.status}`); | ||
} | ||
|
||
// Update the timestamp for this message | ||
messageHistory.set(signature, Date.now()); | ||
} | ||
} | ||
|
||
exports.SlackNotifier = SlackNotifier; |
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
Oops, something went wrong.