# Slack widget The **Slack** widget shows how many unread mentions and direct messages you have in Slack, and lists the newest ones: who wrote, in which conversation and when. With **Show message text** on, it also shows one line of the text. It is read-only: it cannot reply or mark anything as read. The PhoneBox agent on your computer asks Slack, with a token from a Slack app that you create yourself. The token stays on the computer. The phone never contacts Slack and never gets the token. ## Why your own Slack app PhoneBox has no shared Slack app and no server of its own. You create a small app in your own workspace once (about five minutes, free), and paste its user token into PhoneBox: - Nobody but you and Slack sees the token or your messages. - An app that you build for your own workspace is an internal app. Slack's stricter rate limits for apps distributed to other workspaces do not apply to it. - The manifest below asks only for read scopes. The token is as sensitive as your Slack account. The `search:read` scope lets it read every message that you can see in Slack, in every channel and conversation. Keep it only in PhoneBox, and revoke it in Slack when you stop using the widget. Some workspaces let only an admin approve new apps. Then Slack asks an admin to approve it before you can install it. ## 1. Create the Slack app 1. Open [api.slack.com/apps](https://api.slack.com/apps) and sign in to the workspace you want to see. 2. Click **Create New App**, then **From a manifest**, and pick the workspace. 3. Choose **YAML**, replace the example with this manifest and click **Next**, then **Create**: ```yaml display_information: name: PhoneBox Slack widget description: Unread mentions and direct messages on my PhoneBox panel (read-only). oauth_config: scopes: user: - search:read - users:read - channels:read - groups:read - im:read - mpim:read - channels:history - groups:history - im:history - mpim:history settings: org_deploy_enabled: false socket_mode_enabled: false token_rotation_enabled: false ``` 4. Open **Install App** (or **OAuth & Permissions**) and click **Install to Workspace**, then **Allow**. 5. Copy the **User OAuth Token**. It starts with `xoxp-`. A token that starts with `xoxb-` is a bot token, and the widget does not use it. When the token has scopes that are not in this manifest, the **Slack** card in the settings shows a warning with their names. The widget does not need them. Create a new app from the manifest, paste its token, and remove the old app. ## 2. Enter it in PhoneBox 1. Open the PhoneBox settings page, choose **General** and find the **Slack** card. 2. Turn on **Connect Slack**. 3. Paste the token in **User OAuth Token**, then click **Save**. The token is write-only. After the save, the settings page shows only that a token is saved, never the token itself. To change it, paste a new one and save. To remove it, click **Remove the saved token** and save. The previous token stays in `config.json.bak` next to the settings until the next save, so to retire a token, revoke it in Slack (remove the app or its token). ## 3. Add the widget Add a **Slack** widget to a page in the editor. The agent asks Slack only while Slack is on and an enabled page has a Slack widget. The first list appears within a minute after you save. With many conversations it shows the newest messages first, and the rest fill in over the next few minutes. | What you see | Meaning | |---|---| | **4 unread** | Four unread mentions and direct messages | | **4+ unread** | One of Slack's searches returned its maximum of 50 matches, so there can be more than 4. The "+" shows only when the oldest of those 50 is itself unread | | **Connect Slack in Settings › General** | Slack is off in the settings | | **Connecting…** | The agent has not finished its first request | | **No unread mentions or direct messages** | Everything you were sent is read | | **Slack refresh failed; last update 5m ago** | The last request failed. The list from that time stays, with the reason below it | A message is unread when it is newer than your read position in its conversation, or in its thread for a thread reply. A new message shows only after the agent has asked Slack for that read position: each minute it asks for at most 20 of them, so after the first start the list can take a few minutes to fill. A thread that you do not follow in Slack has no read position, so its replies use the read position of their conversation. Slack keeps no read position for a channel that you have not joined, so mentions there are not shown. Join the channel in Slack to see them. A message that the agent finds for the first time waits until the agent has asked Slack again for its read position. So a new message that you already read on the computer does not show because of an old read position. Usually it shows by the next poll. Messages that you sent yourself are left out. ### Message text The phone sits on your desk, so the widget does not show the text of your messages by default. Each row shows the kind (`@` for a mention, `✉` for a direct message), who wrote, the conversation and the time. Turn on **Show message text** in the widget's options to also see one line of each message, at most 140 characters. The agent sends the text to the phone only while a Slack widget on an enabled page has this option on. - A link shows only as its host, for example `github.com`, and other kinds of link as `[link]`. A link with a label shows its label. - When the agent cannot get a new list from Slack for more than an hour, the phone gets the old list without the text until a poll succeeds again. ### Toasts Turn on **Toast for new mentions and messages** in the widget's options (off by default) to get a toast on the phone for each new unread mention or direct message. The toast says only who wrote and where, for example `Ada · #releases`, never the text of the message, also when **Show message text** is on. - The agent sends the toasts, so they come on whichever page the phone shows, and they go to every connected phone. - The first list after the agent starts, after the token changes or after you turn the option on is the starting point: messages already there cause no toast, and neither does an older message found later. - A message causes a toast only when its read position says that it is unread. A message that waits for its read position causes no toast until then, so a message that you already read on the computer causes none. - Each message causes one toast at most. A message that arrives while the agent is not running causes none. - When two or more new messages arrive between two checks, one toast stands for all of them: its title gives their number, for example `Slack (5)`, and it names up to two senders and the number of the other senders, for example `Ann, Bob +1`. - The phone keeps its last 30 toasts in its notification list, so the names stay there until newer toasts push them out. ## What is requested Every minute, while Slack is on and an enabled page has a Slack widget, the agent calls Slack's Web API at `https://slack.com/api/` with the token in the `Authorization` header. It follows no redirects, so the token goes to `slack.com` and nowhere else. | Call | When | Why | |---|---|---| | `auth.test` | Once for each token | Your user id, for the mention search | | `search.messages` | Twice a minute, and twice more for each accepted tap on ↻ (at most once every 30 seconds) | The newest 50 messages that mention you (`<@your id>`), and the newest 50 direct and group messages (`to:me`) | | `users.info` | At most 10 new people per poll | The names of the senders and of the people mentioned in the messages | | `conversations.info`, `conversations.replies` | At most 20 per poll | Your read position in a conversation or a thread | After a failure the agent waits 1 minute, then 2, 4, 8 and at most 15 minutes, until a poll succeeds. When Slack is busy (HTTP 429), it waits as long as Slack asks if that is longer, up to an hour. A name that Slack says is not there for you (a person that you cannot see) is skipped. A read position that Slack says is not there for you (a channel that you left) counts as no read position, so its messages are not shown. Any other error ends the poll: the list from before stays, with the error, and the agent tries again 1 minute later, then after longer waits as above. So a message is never shown as unread because Slack did not answer. When Slack refuses the token, the agent clears the list and asks Slack nothing more until you paste a new token, or turn Slack or the widget off and on again. The ↻ button next to the widget's title asks the agent to poll now. The agent accepts a tap only 30 seconds or more after the end of its last poll, also after a failure, and never during a rate-limit wait or while Slack refuses the token. A refused tap does nothing, and the button dims for the time left, up to a minute. What reaches the phone, through the agent's `/api/slack`: the number of unread items, and for each of the newest 50 the kind (mention or direct message), the sender's name, the conversation's name and the time. With **Show message text** on, also at most 140 characters of plain text, in which a link shows only as its host (or `[link]`) unless its label is plain words. No ids, permalinks, pictures or files. The phone keeps the last answer in memory while the widget shows it, and writes nothing: the widget asks the agent again every 15 seconds, and the answer is never cached. Only a toast, when that option is on, is kept on the phone, with the names and without the text. The agent keeps the list in memory only, never in a file or the log. It forgets the list when Slack is turned off, the widget is removed, the token changes or Slack refuses the token. See the Slack rows in [PRIVACY.md](../PRIVACY.md). ## Troubleshooting | Problem | What to try | |---|---| | **The Slack token must be a user token that starts with xoxp-** | You pasted a bot token or something else. Copy the **User OAuth Token** from **OAuth & Permissions** | | **Slack refused the token (invalid_auth)** or **(token_revoked)** | The app was removed or reinstalled, or the token was revoked. The agent stops asking Slack. Install the app again and paste its new token | | **(account_inactive)** | The account behind the token is deactivated | | **This token has scopes the widget does not need** (in the settings) | The app was not created from the manifest above. Create a new app from the manifest, paste its token, and remove the old app | | **The Slack app is missing a permission (missing_scope)** | The app was not created from the manifest above. Add the missing user scopes under **OAuth & Permissions**, click **Reinstall to Workspace** and paste the new token | | **Slack is rate limiting requests** | The agent waits and tries again by itself. The list from before stays on the phone | | **Install to Workspace** is not possible | Your workspace needs an admin to approve new apps. Click **Request to Install** and wait for the approval | | A message stays in the list after you read it | The list follows Slack's read position, which can take a minute to update. A reply in a thread you do not follow uses the read position of its conversation | | A name shows as a handle or as `…` | The agent looks up at most 10 new people a minute; the name appears after a few minutes. A person Slack does not show you stays `…`, and an id never reaches the phone |