Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Slack Ephemeral Messages #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Configurable Slack Ephemeral Messages
Introduce a setting to allow users to configure which Slack commands
will response with an ephemeral message. This was motivated by wanting
to turn the "help" command response into an ephemeral message to prevent it from
creating noise in the incident room.
  • Loading branch information
cshoe committed Jul 1, 2021
commit 839da88346a4c524a99751eb15b1d9ce81e912c9
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -107,6 +107,7 @@ Follow [these instructions](./docs/slack_app_create.md) to create a new Slack Ap
| `INCIDENT_CHANNEL_ID` | When an incident is declared, a 'headline' post is sent to a central channel.<br /><br />See the [demo app settings](./demo/demo/settings/dev.py) for an example of how to get the incident channel ID from the Slack API. |
| `INCIDENT_BOT_ID` | We want to invite the Bot to all Incident Channels, so need to know its ID.<br /><br />See the [demo app settings](./demo/demo/settings/dev.py) for an example of how to get the bot ID from the Slack API. |
| `SLACK_CLIENT` | Response needs a shared global instance of a Slack Client to talk to the Slack API. Typically this does not require any additional configuration. <br /><pre>from response.slack.client import SlackClient<br />SLACK_CLIENT = SlackClient(SLACK_TOKEN)</pre> |
|`SLACK_EPHEMERAL_RESPONSES` | JSON formatted list of command names to which the Slack response should be sent as an [Ephemeral Message](https://api.slack.com/messaging/managing#ephemeral). All aliases for a single command need to be added to this list.

## 3. Running the server

3 changes: 3 additions & 0 deletions demo/demo/settings/prod.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

from .base import * # noqa: F401, F403
@@ -47,6 +48,8 @@

SLACK_TOKEN = get_env_var("SLACK_TOKEN")
SLACK_SIGNING_SECRET = get_env_var("SLACK_SIGNING_SECRET")
SLACK_EPHEMERAL_RESPONSES = json.loads(os.getenv("SLACK_EPHEMERAL_RESPONSES",
"[]"))
INCIDENT_CHANNEL_NAME = get_env_var("INCIDENT_CHANNEL_NAME")
INCIDENT_REPORT_CHANNEL_NAME = get_env_var("INCIDENT_REPORT_CHANNEL_NAME")
INCIDENT_BOT_NAME = get_env_var("INCIDENT_BOT_NAME")
9 changes: 8 additions & 1 deletion response/slack/decorators/incident_command.py
Original file line number Diff line number Diff line change
@@ -126,7 +126,14 @@ def handle_incident_command(command_name, message, thread_ts, channel_id, user_i
react_not_ok(channel_id, thread_ts)

if response:
settings.SLACK_CLIENT.send_message(comms_channel.channel_id, response)
if command_name in settings.SLACK_EPHEMERAL_RESPONSES:
settings.SLACK_CLIENT.send_ephemeral_message(
channel_id,
user_id,
response
)
else:
settings.SLACK_CLIENT.send_message(comms_channel.channel_id, response)

except CommsChannel.DoesNotExist:
logger.error("No matching incident found for this channel")