-
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.
Slack: Notification After Success Run (#17)
Adding a slack client (requiring a SLACK_TOKEN and SLACK_CHANNEL) that is initialized at runtime setup: It posts to SLACK_CHANNEL as follows: After Billing - MEV Billing ran successfully: ${TX_LINK}. After Drafting - (if there were any drafted account) MEV Drafting ran successfully: ${TX_LINK}.
- Loading branch information
Showing
11 changed files
with
237 additions
and
15 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
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
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,35 @@ | ||
import { WebClient } from "@slack/web-api"; | ||
|
||
export class Slack { | ||
client: WebClient; | ||
channel: string; | ||
|
||
constructor(token: string, channel: string) { | ||
this.client = new WebClient(token); | ||
this.channel = channel; | ||
} | ||
|
||
static async fromEnv(): Promise<Slack> { | ||
const { SLACK_TOKEN, SLACK_CHANNEL } = process.env; | ||
const slack = new Slack(SLACK_TOKEN!, SLACK_CHANNEL!); | ||
// Test early! | ||
const result = await slack.client.auth.test(); | ||
if (result.ok) { | ||
return slack; | ||
} else { | ||
throw new Error(`couldn't connect to slack: ${result.error}`); | ||
} | ||
} | ||
|
||
async post(message: string): Promise<void> { | ||
let result = await this.client.chat.postMessage({ | ||
text: message, | ||
channel: this.channel, | ||
}); | ||
if (result.ok) { | ||
return; | ||
} else { | ||
throw new Error(`failed to post: ${result.error}`); | ||
} | ||
} | ||
} |
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.