Configurar notificações do Slack usando o plugin discourse-chat-integration

Este howto descreve como configurar o provedor do Slack incluído em discourse-chat-integration.

Ele permite postar notificações no Slack, gerenciar regras usando Comandos de Barra (Slash Commands) e postar transcrições de volta para o Discourse. As instruções para comandos de barra podem ser encontradas digitando /discourse help. Transcrições podem ser criadas usando os menus de contexto em posts do Slack.

Instalação

Se você ainda não o fez, instale o plugin discourse-chat-integration e certifique-se de que ele está habilitado através da configuração de site chat integration enabled.

Configurar o Slack

  1. Acesse Slack API: Applications | Slack e crie um novo aplicativo. Se você ainda não estiver logado, será solicitado a fazê-lo. (Você pode precisar clicar neste link novamente, pois ele não parece redirecionar após o login :()

  2. Clique em Create New App

  3. Escolha um nome (pode ser qualquer coisa) e selecione a Equipe do Slack da qual deseja que ele faça parte

  4. No menu esquerdo, em “Features” (Recursos), clique em “OAuth & Permissions” (OAuth e Permissões).

  5. Role para baixo até “Scopes / Bot Token Scopes” (Escopos / Escopos do Token do Bot) e adicione cada um destes para permitir que o plugin poste mensagens no seu espaço de trabalho do Slack:

    • chat:write
    • chat:write.customize
  1. Vá para a página de Configurações (Settings) > Install App (Instalar Aplicativo), clique em Install to Workspace (Instalar no Espaço de Trabalho) e autorize o aplicativo com sua equipe

  2. Copie o Bot User OAuth Token e cole-o nas configurações do seu site no Discourse sob chat_integration_slack_access_token

  3. Vá para a página Basic Information (Informações Básicas), copie o Verification Token e cole-o nas configurações do seu site no Discourse sob chat_integration_slack_incoming_webhook_token

  4. No final da página Basic Information (Informações Básicas), você pode definir o ícone, nome e descrição do seu bot.

  5. Configure algumas “Rules” (Regras) para seus canais, de acordo com as instruções do discourse-chat-integration, ou alternativamente use os comandos de barra dentro de um canal para começar.

  6. Adicione o usuário bot do Discourse aos canais nos quais você deseja que ele possa postar:

    • No menu esquerdo da página do seu cliente Slack, clique com o botão direito no nome do canal ao qual deseja adicionar o aplicativo e clique em View Channel Details (Ver Detalhes do Canal):
    • Na janela pop-up, selecione a guia Integrations (Integrações)
    • Na página de Integrações, você pode clicar em Add an App (Adicionar um Aplicativo) e escolher o Bot do Discourse:
    • O aplicativo agora deve ser capaz de postar no canal

Solução de problemas (Troubleshooting)

O comando de barra /discourse retorna o erro dispatch_failed

Sintoma

Após configurar a integração do Slack, você tenta o comando de barra /discourse e vê o seguinte erro no Slack:

/discourse failed with the error "dispatch_failed"

Causa

É provável que isso se deva a um erro de configuração. Verifique se o valor que você configurou para Request URL (URL de Requisição) está correto. Deve estar neste formato:

\u003cyour-discourse-url\u003e/chat-integration/slack/command

Correção

Atualize sua Request URL (URL de Requisição) e preste atenção especial ao seguinte:

  1. Certifique-se de que começa com o protocolo correto (por exemplo, https://)
  2. Certifique-se de que está usando o domínio do seu site Discourse (não da sua instância do Slack)
  3. Certifique-se de que possui o caminho correto /chat-integration/slack/command
33 curtidas

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.

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)

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!

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!

1 curtida

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:

3 curtidas

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 ?

2 curtidas

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:

1 curtida

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

2 curtidas

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?

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.

4 curtidas

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?

1 curtida

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:
51
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.

7 curtidas

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.

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.

10 curtidas

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?

4 curtidas

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.

8 curtidas

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.

2 curtidas

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

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

3 curtidas