Debian Codegraph @

docs/user_guide/configuration/slackv3.rst

raw
1 Slack v3 Backend
2 ================
3
4 This backend lets you connect to the `Slack <https://slack.com/>`_ messaging service using the
5 Real-time Messaging Protocol, Events Request-URL or Events Socket mode.
6
7 .. note::
8 The use of the Real-time messaging protocol is not recommended by Slack and they urge people to
9 move to the Event based protocol. https://api.slack.com/changelog/2021-10-rtm-start-to-stop
10
11 To select this backend, set `BACKEND = 'SlackV3'`.
12
13 Dependencies
14 ------------
15
16 You need to install Slackv3 dependencies before using Errbot with Slack. In the below example,
17 it is assumed slackv3 has been download to the /opt/errbot/backends directory and errbot has been
18 installed in a python virtual environment (adjust the command to your errbot's installation)::
19
20 git clone https://github.com/errbotio/err-backend-slackv3.git
21 source /opt/errbot/bin/activate
22 /opt/errbot/bin/pip install -r /opt/errbot/backends/err-backend-slackv3/requirements.txt
23
24 Connection Methods
25 ------------------
26
27 Over the years, Slack has changed to their OAuth and API architecture that can be a source of confusion. No
28 matter which OAuth bot token you're using or the API architecture in your environment, slackv3 can handle it.
29
30 The backend will automatically detect which token and architecture you have and start listening for Slack events in the right way:
31
32 Legacy tokens (OAuthv1) with Real Time Messaging (RTM) API
33 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34
35 When the following oauth scopes are detected, the RTM protocol will be used. These scopes are automatically present when using a legacy token.
36
37 .. code::
38
39 "apps"
40 "bot"
41 "bot:basic"
42 "client"
43 "files:write:user"
44 "identify"
45 "post"
46 "read"
47
48 - Current token (OAuthv2) with Event API using the Event Subscriptions and Request URL.
49 - Current token (OAuthv2) with Event API using the Socket-mode client.
50
51 Backend Installation
52 --------------------
53
54 These instructions are for errbot running inside a Python virtual environment. You will need to adapt these steps to your own errbot instance setup.
55 The virtual environment is created in `/opt/errbot/virtualenv` and errbot initialised in `/opt/errbot`. The extra backend directory is in `/opt/errbot/backend`.
56
57 1. Create the errbot virtual environment
58
59 .. code::
60
61 mkdir -p /opt/errbot/backend
62 virtualenv --python=python3 /opt/errbot/virtualenv
63
64 2. Install and initialise errbot. `See here for details <https://errbot.readthedocs.io/en/latest/user_guide/setup.html>`_
65
66 .. code::
67
68 source /opt/errbot/virtualenv/bin/activate
69 pip install errbot
70 cd /opt/errbot
71 errbot --init
72
73 3. Configure the slackv3 backend and extra backend directory. Located in `/opt/errbot/config.py`
74
75 .. code::
76
77 BACKEND="SlackV3"
78 BOT_EXTRA_BACKEND_DIR=/opt/errbot/backend
79
80 4. Clone `err-backend-slackv3` into the backend directory and install module dependencies.
81
82 .. code::
83
84 cd /opt/errbot/backend
85 git clone https://github.com/errbotio/err-backend-slackv3
86 pip install -r /opt/errbot/backend/err-backend-slackv3/requirements.txt
87
88 5. Configure the slack bot token, signing secret (Events API with Request URLs) and/or app token (Events API with Socket-mode). Located in `/opt/errbot/config.py`
89
90 .. code::
91
92 BOT_IDENTITY = {
93 'token': 'xoxb-...',
94 'signing_secret': "<hexadecimal value>",
95 'app_token': "xapp-..."
96 }
97
98
99 Setting up Slack application
100 ----------------------------
101
102 Legacy token with RTM
103 ^^^^^^^^^^^^^^^^^^^^^
104
105 This was the original method for connecting a bot to Slack. Create a bot token, configure errbot with it and start using Slack.
106 Pay attention when reading `real time messaging <https://github.com/slackapi/python-slack-sdk/blob/main/docs-src/real_time_messaging.rst>`_ explaining how to create a "classic slack application". Slack does not allow Legacy bot tokens to use the Events API.
107
108 Current token with Events Request URLs
109 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110
111 This is by far the most complex method of having errbot communicate with Slack. The architecture involves server to client communication over HTTP. This means the Slack server must be able to reach errbot's `/slack/events` endpoint via the internet using a valid SSL connection.
112 How to set up such an architecture is outside the scope of this readme and is left as an exercise for the reader. Read `slack events api document <https://github.com/slackapi/python-slack-events-api>`_ for details on how to configure the Slack app and request URL.
113
114 Current token with Events Socket-mode client
115 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116
117 Create a current bot token, enable socket mode. Configure errbot to use the bot and app tokens and start using Slack.
118 Read `socket-mode <https://github.com/slackapi/python-slack-sdk/blob/main/docs-src/socket-mode/index.rst>`_ for instructions on setting up Socket-mode.
119
120 Ensure the bot is also subscribed to the following events:
121
122 - `file_created`
123 - `file_public`
124 - `message.channels`
125 - `message.groups`
126 - `message.im`