MCPcopy Index your code
hub / github.com/Flagsmith/flagsmith / toChannel

Function toChannel

frontend/api/slack-client.js:7–25  ·  view source on GitHub ↗
(message, channel)

Source from the content-addressed store, hash-verified

5const SLACK_TOKEN = process.env.SLACK_TOKEN
6
7async function toChannel(message, channel) {
8 // eslint-disable-next-line
9 console.log(`sending to channel: ${channel} message: ${message}`)
10 try {
11 const res = await fetch('https://slack.com/api/chat.postMessage', {
12 method: 'POST',
13 headers: {
14 'Content-Type': 'application/json; charset=utf-8',
15 Authorization: `Bearer ${SLACK_TOKEN}`,
16 },
17 body: JSON.stringify({ channel: `#${channel}`, text: message }),
18 })
19 const data = await res.json()
20 if (!data.ok) throw new Error(data.error)
21 } catch (error) {
22 // eslint-disable-next-line
23 console.log(`Error posting to Slack:${error}`)
24 }
25}
26
27module.exports = toChannel

Callers

nothing calls this directly

Calls 2

fetchFunction · 0.85
jsonMethod · 0.45

Tested by

no test coverage detected