Skip to content

The agent that grows with you

docs(whatsapp): group access section says what the gateway admits; env reference rows; trim bridge tests

kshitijk4poor8925c70a1c84
diff --git a/scripts/whatsapp-bridge/allowlist.test.mjs b/scripts/whatsapp-bridge/allowlist.test.mjs
index daa85cb7405..10da9e3369c 100644
--- a/scripts/whatsapp-bridge/allowlist.test.mjs
+++ b/scripts/whatsapp-bridge/allowlist.test.mjs
@@ -48,14 +48,14 @@ test('matchesAllowedUser accepts mapped lid sender when allowlist only contains
}
});
-test('matchesAllowedSender accepts Baileys senderPn when a first-contact LID has no mapping yet', () => {
+test('matchesAllowedSender accepts the Baileys alt phone JID when a first-contact LID has no mapping yet (#63415, #72529)', () => {
const sessionDir = mkdtempSync(path.join(os.tmpdir(), 'hermes-wa-allowlist-'));
try {
const allowedUsers = parseAllowedUsers('+19175395595');
// On a first message from a WhatsApp Multi-Device contact, Baileys can
// emit a LID as senderId before it has written LID mapping files, while
- // senderPn carries WhatsApp's authenticated phone JID.
+ // key.remoteJidAlt / key.participantAlt carries the phone JID.
assert.equal(
matchesAllowedSender('267383306489914@lid', '[email protected]', allowedUsers, sessionDir),
true,
@@ -122,49 +122,3 @@ test('matchesAllowedUser rejects everyone when allowlist is empty (#8389)', () =
rmSync(sessionDir, { recursive: true, force: true });
}
});
-
-test('matchesAllowedSender falls back to participantAlt when no lid mapping exists (#72529)', () => {
- // Baileys v7 group messages arrive with key.participant in LID form and
- // the phone number only in key.participantAlt. A fresh bot session has no
- // lid-mapping-*.json files, so the LID alone can never match a phone
- // allowlist — the alt identifier must be consulted as a fallback.
- const sessionDir = mkdtempSync(path.join(os.tmpdir(), 'hermes-wa-allowlist-'));
-
- try {
- const allowedUsers = parseAllowedUsers('+19175395595');
-
- // No mapping file: LID by itself is rejected today (the #72529 drop)…
- assert.equal(matchesAllowedUser('267383306489914@lid', allowedUsers, sessionDir), false);
- // …but the alt phone identifier rescues the match.
- assert.equal(
- matchesAllowedSender('267383306489914@lid', '[email protected]', allowedUsers, sessionDir),
- true
- );
-
- // A stranger's LID with a non-allowlisted alt stays rejected.
- assert.equal(
- matchesAllowedSender('188012763865257@lid', '[email protected]', allowedUsers, sessionDir),
- false
- );
-
- // Missing / empty alt keeps the existing behaviour.
- assert.equal(matchesAllowedSender('267383306489914@lid', '', allowedUsers, sessionDir), false);
- assert.equal(matchesAllowedSender('267383306489914@lid', undefined, allowedUsers, sessionDir), false);
- } finally {
- rmSync(sessionDir, { recursive: true, force: true });
- }
-});
-
-test('matchesAllowedSender still resolves via lid-mapping files without an alt', () => {
- const sessionDir = mkdtempSync(path.join(os.tmpdir(), 'hermes-wa-allowlist-'));
-
- try {
- writeFileSync(path.join(sessionDir, 'lid-mapping-19175395595.json'), JSON.stringify('267383306489914'));
- writeFileSync(path.join(sessionDir, 'lid-mapping-267383306489914_reverse.json'), JSON.stringify('19175395595'));
-
- const allowedUsers = parseAllowedUsers('+19175395595');
- assert.equal(matchesAllowedSender('267383306489914@lid', '', allowedUsers, sessionDir), true);
- } finally {
- rmSync(sessionDir, { recursive: true, force: true });
- }
-});
diff --git a/website/docs/reference/environment-variables.md b/website/docs/reference/environment-variables.md
index 7eb8b0398ac..af7b87610e0 100644
--- a/website/docs/reference/environment-variables.md
+++ b/website/docs/reference/environment-variables.md
@@ -388,6 +388,8 @@ These are set automatically by the Docker terminal backend when `proxy.enabled:
| `WHATSAPP_MODE` | `bot` (separate number) or `self-chat` (message yourself) |
| `WHATSAPP_ALLOWED_USERS` | Comma-separated phone numbers (with country code, no `+`), or `*` to allow all senders |
| `WHATSAPP_ALLOW_ALL_USERS` | Allow all WhatsApp senders without an allowlist (`true`/`false`) |
+| `WHATSAPP_GROUP_POLICY` | Group intake: `pairing` (default, forwards nothing from groups), `allowlist` (group JIDs below), `open` (every group; participants still need `WHATSAPP_ALLOWED_USERS`, pairing, or `WHATSAPP_ALLOW_ALL_USERS`), or `disabled` |
+| `WHATSAPP_GROUP_ALLOWED_USERS` | Comma-separated group JIDs (e.g. `[email protected]`) admitted under `WHATSAPP_GROUP_POLICY=allowlist` |
| `WHATSAPP_HOME_CHANNEL` | Default chat ID for cron / notification delivery. |
| `WHATSAPP_HOME_CHANNEL_NAME` | Display name for the WhatsApp home channel. |
| `WHATSAPP_DEBUG` | Log raw message events in the bridge for troubleshooting (`true`/`false`) |
diff --git a/website/docs/user-guide/messaging/whatsapp.md b/website/docs/user-guide/messaging/whatsapp.md
index e4d9699bd22..60f4020e374 100644
--- a/website/docs/user-guide/messaging/whatsapp.md
+++ b/website/docs/user-guide/messaging/whatsapp.md
@@ -130,6 +130,20 @@ whatsapp:
- `unauthorized_dm_behavior: pair` is the global default. Unknown DM senders get a pairing code.
- `whatsapp.unauthorized_dm_behavior: ignore` makes WhatsApp stay silent for unauthorized DMs, which is usually the better choice for a private number.
+### Group chats (bot mode)
+
+Groups are gated by **group policy**, not by the DM allowlist. `WHATSAPP_GROUP_POLICY` / `whatsapp.group_policy`
+defaults to `pairing`, which forwards nothing from groups. `allowlist` plus `WHATSAPP_GROUP_ALLOWED_USERS` /
+`whatsapp.group_allow_from` (comma-separated **group JIDs**, e.g. `[email protected]`) admits the listed
+groups; `open` admits every group the bot is a member of. The sender is then checked like any other gateway
+principal: with `WHATSAPP_ALLOWED_USERS` set, a participant must be on it (or paired) — a sender WhatsApp
+addresses by LID matches through the phone number Baileys supplies alongside it, so a first contact with no
+`lid-mapping` file yet is not dropped; with no sender allowlist,
+`allowlist` trusts the group-JID list alone and admits every participant of a listed group, while `open` still
+needs the participant paired or `WHATSAPP_ALLOW_ALL_USERS=true`. By default the bot answers every admitted group
+message; set `require_mention: true` / `WHATSAPP_REQUIRE_MENTION=true` to answer only @mentions, replies to the
+bot, or `/commands` (groups in `free_response_chats` are exempt).
+
Then start the gateway:
```bash