Set up Slack notifications using the discourse-chat-integration plugin

(David Taylor) #1

This #howto describes how to setup the Slack provider included in discourse-chat-integration.

It allows posting notifications to Slack, managing rules using Slash Commands, and posting transcripts back to Discourse (/discourse post 20 will create a draft topic containing the last 20 slack messages).


If you haven’t already, install the discourse-chat-integration plugin

Setup Slack

  1. Head over to Slack API: Applications | Slack and create a new app. If you’re not already logged in, you’ll be prompted to do so. (you may need to click on this link again, as it doesn’t seem to redirect after login :frowning: )

  2. Click Create New App

  3. Choose a name (can be anything), and select the Slack Team you want it to be a part of

  4. In the left-hand menu, under “Features”, click “OAuth & Permissions”.

  5. Scroll down to “permission scopes”, add each of these, then Save Changes

    • chat:write:bot
    • users:read
    • channels:history
    • groups:history
    • im:history
  6. On the left-hand menu, under “Features”, go to the Slash Commands page. Click Create New Command

    • Command - /discourse
    • Request URL - <your-discourse-url>/chat-integration/slack/command
    • Short Description - Manage this channel's integration with Discourse
    • Usage Hint - [watch|follow|mute|remove|status|post|help]
  • Note: if you choose to use a slash command other than /discourse (e.g. choosing a command to match your site name), you can adjust the help text to reflect the command on your Slack admin panel. Customize -> Text Content -> search for “” and change /discourse to match your command.
  1. Save

  2. Go to the Interactive Components page, and enter this url under “Request URL”

  3. Save Changes

  4. Go to the top of the OAuth & Permissions page, click Install App to Workspace, and authorise the app with your team

  5. Copy the OAuth Access Token, and paste it into your Discourse site settings under chat_integration_slack_access_token

  6. Go to the Basic Information page, copy the Verification Token, and paste it into your Discourse site settings under chat_integration_slack_incoming_webhook_token

  7. At the bottom of the Basic Information page, you can set your bot’s icon, name and description.

  8. Setup some “Rules” for your channels, according to the discourse-chat-integration instructions, or alternatively use the slash commands within a channel to get started.

Migration from discourse-slack-official

Your configuration and rules will be migrated from the old slack plugin automatically. discourse-chat-integration will be enabled and discourse-slack-official will be disabled. The migration will only happen if, at the point of installing discourse-chat-integration:

  • Plugin row fields for discourse-slack-official is still present
  • You have not set any of the slack configuration options for discourse-chat-integration
  • You do not have any channels set up for slack in discourse-chat-integration

If you want to run the migration at a later date, and bypass these safety checks, you can do so by running these commands on the rails console:

job =

Once you’ve enabled the new plugin, notifications should work immediately. For slash commands, you will need to update the configuration on Slack’s end with the new webhook URL. For transcript posting, you will need to use the access_token method of authentication. See the instructions above for more information.

Chatroom Integration Plugin (discourse-chat-integration)
Slack: Post chat snapshot to Discourse
Help configuring Slack Discourse plugin
How to enable your community to use Discourse as a (micro) blogging platform
Chatroom Integration Plugin (discourse-chat-integration)
Chatroom Integration Plugin (discourse-chat-integration)
Selecting new message in Slack "post transcript", slackbot returns an error
(Ivar) #2

I’m very excited to try this plugin. I gave installing it a shot by following these instructions carefully, but when I go to test a slash command on slack I get:

slackbot Darn - that slash command didn't work (error message: `403_client_error`). Manage the command at Discourse Integration.

(David Taylor) #3

This would suggest that it’s an issue with the authentication of slack to your Discourse instance. Can you double check that the incoming webhook token has been copied across correctly? (step 12 above) Make sure there’s nothing weird being copied before/after (e.g. spaces)

(Ivar) #4

Also, it seems Slack’s App config tools are subject to refinement as a details in this howto have changed.

  1. in step 4:
  • was “Under features and Functionality” select “Permissions”
  • now is “Under Features” select “OAuth & Permissions”
  1. in step 6: would be good to clarify “Under Features, select ‘Slash Commands’”, same with step 8 “Under Features, select ‘Interactive Messages’”

Thanks for building and sharing this plugin!

(Ivar) #5

Ugh, I went through the instructions twice, and realized I copied the verification token incorrectly. My issue was completely PEBKAC :(- thanks for the (immediate) help!

(David Taylor) #6

Thanks - I’ve updated the two things you mentioned, and converted the first post to a wiki. Please feel free to update if you notice anything else.

No problem - glad it’s working :smiley:

(Ivar) #7

re: rule generation. The help doc states:

New rule: /discourse [watch|follow|mute] [category] [tag:name]
(you must specify a rule type and at least one category or tag)

  • watch – notify this channel for new topics and new replies
  • follow – notify this channel for new topics
  • mute – block notifications to this channel

The integration doesn’t seem to be able to find tags.
edit: Ugh… I just saw the docs that the syntax for tags is [tag:name] :facepalm: … sorry I missed that…

I noticed that the help files are hard coded to the slash command “/discourse”… I pulled down the source and got as far as finding the strings in the locale files and where they’re invoked in the helper. I would like to issue a PR to allow the slash command in help files to be configurable (my integration uses my sitename as the command…) but I’m not sure how persistence works with Discourse plugins. If I submitted a partially complete PR would you be able to provide some pointers or would that be a waste of time ?

Also, where would be the best place to add feature requests ?

Add setting to replace "discourse" with name that matches slash command
(David Taylor) #8

The easiest way to change this to a different command is to go to your discourse admin panel, Customize Text Content, then type chat_integration.provider.slack into the search bar. You’ll find the “help” string in this list. Changes to this should persist across discourse/plugin updates

I think slack-specific ones in this topic, and general ones for the plugin in the main topic :slight_smile:

(Ivar) #9

Wow. That’s pretty sweet - no code changes necessary. (I’m pretty new to Discourse but it seems pretty badass!)

(Jay Pfaffman) #10

What am I missing? When I try that, I get

“Sorry, this integration isn’t setup to support posting transcripts.”

Did I miss something? Is the feature available only to some Slack communities and not the free ones?

(David Taylor) #11

You need to use the “OAUTH Token” method of authentication to slack, not the “Webhook” method. The instructions above should walk you through setting up the oauth method.

(Jay Pfaffman) #12

That did it. I think I broke it by foolishly trying to migrate the settings from the other slack plugin.

One thing I don’t understand is who can use the slack App I created. It is just me? If so, that’s a little sucky. If not, wait, anyone can control what categories get watched? I see “collaborators” in the slack API page. If I add a collaborator can they too control the rules?

Also, it seems that rules established in the Discourse web interface don’t show up in slack if you do a /discourse status. Is that right?

(David Taylor) #13

When you create slack apps, they are private to you. Only you can edit the settings of the app, and only you can install it onto an organisation. Notice the “Not Distributed” status:
You can then install your app onto your Slack organisation. If you have slash commands set up, anyone in that organisation can control the ‘rules’ for any channel they have access to, and so you should make sure to set the chat integration discourse username appropriately.

‘Collaborators’ of the Slack app means that they can edit the app’s settings (things like callback URLs, auth secrets etc.). It has absolutely nothing to do with who can configure ‘rules’ using slash commands.

/discourse status should list all of the rules for the current channel. So if you have set up rules for #general using the discourse admin interface, they should show up when you run /discourse status in #general. If that’s not working, it’s a bug.

(Jay Pfaffman) #14

Thanks, @david, that’s a huge help. It still seems a bit wild that any slack user can change what Discourse stuff gets posted to a channel, but I suspect that’s because I don’t understand slack.

(David Taylor) #15

I think it depends what kind of community you have in Slack. In my mind there are three main scenarios:

  • If any member of the public can join your Slack organisation, Slash commands probably aren’t a good idea. In this case it’s probably easiest to just manage the rules from the discourse admin panel.

  • If you have a fairly open forum, but a closed slack organisation (like I believe the discourse team do), then having slash commands is a nice convenience without any real issue (everyone in slack is trusted).

  • If you have a roughly 1:1 mapping between forum members and slack members (e.g. a corporate environment), it can be useful to allow individuals to manage the rules in their own slack channel. For example, the dev team might want to watch #dev, and the support team #support. Rather than forcing all this to be done by a discourse admin, they can do it themselves with slash commands. I think this is how @mcwumbly uses slack integration.

(Dave McClure) #16

We’re starting to see some healthy adoption of Slack threads in some channels. I was a big skeptic at first, but as people find good patterns for using them, I can see their value. Does the transcript feature work with threads at all?

Slack threads and chat integration plugin transcripts
(David Taylor) #17

That’s great to hear - I was a little skeptical how useful it would be as well, so glad to hear people like it :slight_smile:

Sadly not. I don’t know if the slack API allows loading messages from a specific thread, so we might need to do the filtering on the Discourse end.

Slack threads and chat integration plugin transcripts
(Erlend Sogge Heggen) #18

Should transcript export work with Direct Messages? I just tried with two different ones and it’ll say Loading the transcript... but nothing happens after that.

(Ben Edwards) #20

I’m getting the same thing, and have checked my access and webhook tokes very carefully. Other things to try?

(Ben Edwards) #21

Also - is it possible to connect Discourse to multiple Slack orgs?