-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Slack bot notifications (#676)
- Loading branch information
Showing
9 changed files
with
129 additions
and
24 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 |
---|---|---|
|
@@ -31,14 +31,6 @@ services: | |
# - DEFAULT_ADMIN_NAME=Demo Demo | ||
# - DEFAULT_ADMIN_USERNAME=demo | ||
|
||
# Email Notifications (https://nodemailer.com/smtp/) | ||
# - SMTP_HOST= | ||
# - SMTP_PORT=587 | ||
# - SMTP_SECURE=true | ||
# - SMTP_USER= | ||
# - SMTP_PASSWORD= | ||
# - SMTP_FROM="Demo Demo" <[email protected]> | ||
|
||
# - OIDC_ISSUER= | ||
# - OIDC_CLIENT_ID= | ||
# - OIDC_CLIENT_SECRET= | ||
|
@@ -51,6 +43,17 @@ services: | |
# - OIDC_IGNORE_USERNAME=true | ||
# - OIDC_IGNORE_ROLES=true | ||
# - OIDC_ENFORCED=true | ||
|
||
# Email Notifications (https://nodemailer.com/smtp/) | ||
# - SMTP_HOST= | ||
# - SMTP_PORT=587 | ||
# - SMTP_SECURE=true | ||
# - SMTP_USER= | ||
# - SMTP_PASSWORD= | ||
# - SMTP_FROM="Demo Demo" <[email protected]> | ||
|
||
# - SLACK_BOT_TOKEN= | ||
# - SLACK_CHANNEL_ID= | ||
depends_on: | ||
postgres: | ||
condition: service_healthy | ||
|
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 |
---|---|---|
|
@@ -22,14 +22,6 @@ SECRET_KEY=notsecretkey | |
# DEFAULT_ADMIN_NAME=Demo Demo | ||
# DEFAULT_ADMIN_USERNAME=demo | ||
|
||
# Email Notifications (https://nodemailer.com/smtp/) | ||
# SMTP_HOST= | ||
# SMTP_PORT=587 | ||
# SMTP_SECURE=true | ||
# SMTP_USER= | ||
# SMTP_PASSWORD= | ||
# SMTP_FROM="Demo Demo" <[email protected]> | ||
|
||
# OIDC_ISSUER= | ||
# OIDC_CLIENT_ID= | ||
# OIDC_CLIENT_SECRET= | ||
|
@@ -43,6 +35,17 @@ SECRET_KEY=notsecretkey | |
# OIDC_IGNORE_ROLES=true | ||
# OIDC_ENFORCED=true | ||
|
||
# Email Notifications (https://nodemailer.com/smtp/) | ||
# SMTP_HOST= | ||
# SMTP_PORT=587 | ||
# SMTP_SECURE=true | ||
# SMTP_USER= | ||
# SMTP_PASSWORD= | ||
# SMTP_FROM="Demo Demo" <[email protected]> | ||
|
||
# SLACK_BOT_TOKEN= | ||
# SLACK_CHANNEL_ID= | ||
|
||
## Do not edit this | ||
|
||
TZ=UTC |
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,53 @@ | ||
const POST_MESSAGE_API_URL = 'https://slack.com/api/chat.postMessage'; | ||
|
||
module.exports = { | ||
inputs: { | ||
markdown: { | ||
type: 'string', | ||
required: true, | ||
}, | ||
}, | ||
|
||
async fn(inputs) { | ||
const headers = { | ||
Authorization: `Bearer ${sails.config.custom.slackBotToken}`, | ||
'Content-Type': 'application/json; charset=utf-8', | ||
}; | ||
|
||
const body = { | ||
blocks: [ | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: inputs.markdown, | ||
}, | ||
}, | ||
], | ||
channel: sails.config.custom.slackChannelId, | ||
}; | ||
|
||
let response; | ||
try { | ||
response = await fetch(POST_MESSAGE_API_URL, { | ||
headers, | ||
method: 'POST', | ||
body: JSON.stringify(body), | ||
}); | ||
} catch (error) { | ||
sails.log.error(error); // TODO: provide description text? | ||
return; | ||
} | ||
|
||
if (!response.ok) { | ||
sails.log.error('Error sending to Slack: %s', response.error); | ||
return; | ||
} | ||
|
||
const responseJson = await response.json(); | ||
|
||
if (!responseJson.ok) { | ||
sails.log.error('Error sending to Slack: %s', responseJson.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