-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 (admin) share newly created DIs in Slack
- Loading branch information
1 parent
7d78a3e
commit 3d4609d
Showing
6 changed files
with
178 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import e from "express" | ||
import * as db from "../../db/db.js" | ||
import { Request } from "../authentication.js" | ||
import { SLACK_BOT_OAUTH_TOKEN } from "../../settings/serverSettings" | ||
import { JsonError } from "@ourworldindata/types" | ||
|
||
export async function sendMessageToSlack( | ||
req: Request, | ||
_res: e.Response<any, Record<string, any>>, | ||
_trx: db.KnexReadWriteTransaction | ||
) { | ||
const url = "https://slack.com/api/chat.postMessage" | ||
|
||
const { channel, blocks, username } = req.body | ||
|
||
if (!channel) throw new JsonError("Channel missing") | ||
if (!blocks) throw new JsonError("Blocks missing") | ||
|
||
const data = { channel, blocks, username } | ||
|
||
const fetchData = { | ||
method: "POST", | ||
body: JSON.stringify(data), | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${SLACK_BOT_OAUTH_TOKEN}`, | ||
}, | ||
} | ||
|
||
const response = await fetch(url, fetchData) | ||
|
||
if (!response.ok) { | ||
throw new JsonError( | ||
`Slack API error: ${response.status} ${response.statusText}` | ||
) | ||
} | ||
|
||
return { success: true } | ||
} |
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