@usepipa/pipa 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,7 +55,7 @@ Incoming messages can include up to Slack's 10-file limit, with a maximum size o
55
55
 
56
56
  ### Access control
57
57
 
58
- By default Pipa answers anyone who mentions it in a channel it can see. In a shared workspace, restrict who can use it by listing the allowed Slack channel and user IDs. `pipa init` asks for these, and they are stored in the config:
58
+ By default Pipa answers any human user who mentions it in a channel it can see, excluding DMs and external channels. In a shared workspace, restrict who can use it by listing the allowed Slack channel and user IDs. `pipa init` asks for these, and they are stored in the config:
59
59
 
60
60
  ```json
61
61
  {
@@ -64,11 +64,44 @@ By default Pipa answers anyone who mentions it in a channel it can see. In a sha
64
64
  "slackAppToken": "xapp-...",
65
65
  "slackBotToken": "xoxb-...",
66
66
  "allowedSlackChannelIds": ["C0BSE2JTYPR"],
67
- "allowedSlackUserIds": ["UFWBSCZ54"]
67
+ "allowedSlackUserIds": ["UFWBSCZ54"],
68
+ "allowedSlackBotIds": ["B0C6Q27E82X"]
68
69
  }
69
70
  ```
70
71
 
71
- A mention is only handled when the channel ID is in `allowedSlackChannelIds` **and** the author's user ID is in `allowedSlackUserIds`. Leave a list empty to allow any channel or any user. You can also set them non-interactively during setup with `PIPA_ALLOWED_CHANNEL_IDS` and `PIPA_ALLOWED_USER_IDS` (comma-separated).
72
+ A human user's mention is only handled when the channel and user pass their respective allowlists. An absent or empty `allowedSlackChannelIds` allows any otherwise eligible channel; an absent or empty `allowedSlackUserIds` allows any human user. You can also set them non-interactively during setup with `PIPA_ALLOWED_CHANNEL_IDS` and `PIPA_ALLOWED_USER_IDS` (comma-separated).
73
+
74
+ By default Pipa ignores messages sent by other Slack apps. Unlike the human user and channel lists, an absent or empty `allowedSlackBotIds` disables all other bots. List their bot IDs to let those messages through; an allowed bot only needs its bot ID (e.g. `B0C6Q27E82X`), not an entry in `allowedSlackUserIds`. Bots still must pass the channel allowlist. Bots not on the list stay ignored even when `allowedSlackUserIds` is empty. Set it non-interactively during setup with `PIPA_ALLOWED_BOT_IDS` (comma-separated).
75
+
76
+ #### Find the sender's bot ID
77
+
78
+ Use the message event's `bot_id` (`B…`), not the app ID (`A…`) or bot user ID (`U…`). To look up the sender app's OAuth bot ID:
79
+
80
+ 1. Open the **sender app** at [Slack Apps](https://api.slack.com/apps), not Pipa's app.
81
+ 2. Under **OAuth & Permissions**, copy its **Bot User OAuth Token** (`xoxb-…`). If needed, install the app in the workspace via **Install App** first.
82
+ 3. Set that token locally in `SLACK_SENDER_BOT_TOKEN`, then call [Slack `auth.test`](https://docs.slack.dev/reference/methods/auth.test/):
83
+
84
+ ```sh
85
+ curl --silent --show-error --request POST \
86
+ --header "Authorization: Bearer ${SLACK_SENDER_BOT_TOKEN}" \
87
+ https://slack.com/api/auth.test
88
+ ```
89
+
90
+ No Slack CLI is needed. Keep the token out of config examples, shared output, and commits. A successful response includes fields like:
91
+
92
+ ```json
93
+ {
94
+ "ok": true,
95
+ "user_id": "U0123456789",
96
+ "bot_id": "B0123456789"
97
+ }
98
+ ```
99
+
100
+ Use `bot_id` (`B0123456789`) in `allowedSlackBotIds`; `user_id` identifies the bot's user account and is not the bot allowlist ID.
101
+
102
+ **Incoming webhooks:** the posted message's `bot_id` can differ from the sender app's OAuth `bot_id` returned by `auth.test`. Allow the actual incoming message/event's `bot_id`. If you do not have the event payload, find the posted message with [Slack `conversations.history`](https://docs.slack.dev/reference/methods/conversations.history/) (or [`conversations.replies`](https://docs.slack.dev/reference/methods/conversations.replies/) for a thread reply), using a token with access to that conversation and the required history scope, and read its `bot_id`.
103
+
104
+ After saving the config, restart Pipa to load the updated allowlist. The allowed bot can start a conversation by posting `<@PIPA_BOT_USER_ID> triage this alert` in an allowed channel, or continue one by replying in a thread Pipa has subscribed to. For an incoming webhook, send that mention in the payload's `text` field. Allowlisting a bot does not make Pipa handle every message it posts in the channel; the normal mention/thread routing still applies. Only allow bots whose messages you trust as requests to your agent.
72
105
 
73
106
  To use an existing OpenCode server instead, set its URL before starting Pipa. Pipa checks that the server can serve the configured workspace but does not start or stop it. If the server uses authentication, also set `OPENCODE_SERVER_USERNAME` and `OPENCODE_SERVER_PASSWORD`:
74
107
 
package/bin/pipa.mjs CHANGED
@@ -348,8 +348,10 @@ async function init(io) {
348
348
  ?? (await prompt.question("Allowed Slack channel IDs (comma-separated, e.g. C0BSE2JTYPR; leave empty to allow any channel): ")).trim();
349
349
  const allowedSlackUserIds = process.env.PIPA_ALLOWED_USER_IDS
350
350
  ?? (await prompt.question("Allowed Slack user IDs (comma-separated, e.g. UFWBSCZ54; leave empty to allow any user): ")).trim();
351
+ const allowedSlackBotIds = process.env.PIPA_ALLOWED_BOT_IDS
352
+ ?? (await prompt.question("Allowed Slack bot IDs (comma-separated, e.g. B0C6Q27E82X; leave empty to ignore bot messages): ")).trim();
351
353
  io.output.write("\nChecking OpenCode and Slack credentials...\n");
352
- const result = await initializePipa({ botName, workingDirectory, slackAppToken, slackBotToken, allowedSlackChannelIds, allowedSlackUserIds });
354
+ const result = await initializePipa({ botName, workingDirectory, slackAppToken, slackBotToken, allowedSlackChannelIds, allowedSlackUserIds, allowedSlackBotIds });
353
355
  io.output.write(`✓ Credentials validated.\n\nSaved config to ${result.paths.config}. Run \`pipa start\`.\n`);
354
356
  } finally {
355
357
  prompt.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usepipa/pipa",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Run Pipa through Slack Socket Mode with OpenCode",
5
5
  "keywords": [
6
6
  "slack",
package/src/app.mjs CHANGED
@@ -19,6 +19,7 @@ export async function initializePipa(input, options = {}) {
19
19
  workingDirectory: await canonicalWorkingDirectory(input.workingDirectory),
20
20
  allowedSlackChannelIds: normalizeIdList(input.allowedSlackChannelIds),
21
21
  allowedSlackUserIds: normalizeIdList(input.allowedSlackUserIds),
22
+ allowedSlackBotIds: normalizeIdList(input.allowedSlackBotIds),
22
23
  };
23
24
  const openCodeVersion = await (options.checkOpenCode ?? runOpenCodeVersion)();
24
25
  if (!/^v?1(?:\.|$)/u.test(openCodeVersion)) throw new Error(`Pipa requires OpenCode v1; found ${openCodeVersion || "an unknown version"}.`);
@@ -170,7 +171,7 @@ export async function startPipa(options = {}) {
170
171
  };
171
172
 
172
173
  const handle = async (thread, message, subscribe) => {
173
- if (!accepting || !isAuthorized(thread, message, config) || shouldIgnore(thread, message)) return;
174
+ if (!accepting || !isAuthorized(thread, message, config) || shouldIgnore(thread, message, config)) return;
174
175
  const messageText = subscribe || message.isMention ? stripMention(message.text) : message.text.trim();
175
176
  const missingLinks = (message.links ?? []).map((link) => link.url)
176
177
  .filter((url) => typeof url === "string" && !messageText.split(/\s+/u).includes(url));
@@ -714,12 +715,13 @@ export async function checkSlackAppToken(token, fetchImpl = fetch) {
714
715
  return result;
715
716
  }
716
717
 
717
- function shouldIgnore(thread, message) {
718
+ function shouldIgnore(thread, message, config) {
719
+ const allowedSubtypes = config.allowedSlackBotIds?.length ? ["file_share", "bot_message"] : ["file_share"];
718
720
  return message.author?.isMe
719
- || message.author?.isBot
721
+ || (message.author?.isBot && !config.allowedSlackBotIds?.length)
722
+ || Boolean(message.raw?.subtype && !allowedSubtypes.includes(message.raw.subtype))
720
723
  || thread.channel?.isDM
721
724
  || thread.channel?.channelVisibility === "external"
722
- || Boolean(message.raw?.subtype && message.raw.subtype !== "file_share")
723
725
  || !message.text?.trim();
724
726
  }
725
727
 
@@ -727,6 +729,7 @@ function isAuthorized(thread, message, config) {
727
729
  const channelId = thread.id.split(":")[1];
728
730
  const userId = message.author?.userId ?? message.author?.id;
729
731
  if (config.allowedSlackChannelIds?.length && !config.allowedSlackChannelIds.includes(channelId)) return false;
732
+ if (message.author?.isBot) return config.allowedSlackBotIds?.includes(message.raw?.bot_id) ?? false;
730
733
  if (config.allowedSlackUserIds?.length && !config.allowedSlackUserIds.includes(userId)) return false;
731
734
  return true;
732
735
  }
package/src/state.mjs CHANGED
@@ -163,7 +163,7 @@ export async function loadConfig(file = pipaPaths().config) {
163
163
  if (slackMode === "managed" && (!Number.isInteger(config.openCodePort) || config.openCodePort < 1 || config.openCodePort > 65535)) {
164
164
  throw new Error("Invalid Pipa config: openCodePort must be an integer from 1 to 65535.");
165
165
  }
166
- for (const key of ["allowedSlackChannelIds", "allowedSlackUserIds"]) {
166
+ for (const key of ["allowedSlackChannelIds", "allowedSlackUserIds", "allowedSlackBotIds"]) {
167
167
  const value = config[key];
168
168
  if (value !== undefined && (!Array.isArray(value) || !value.every((item) => typeof item === "string" && item.trim()))) {
169
169
  throw new Error(`Invalid Pipa config: ${key} must be a list of non-empty Slack IDs.`);