Skip to content

Commit 305f964

Browse files
Ortesclaude
andcommitted
chore(send-poll): polish review nits
- Align bridge validation wording with the Python layer ("At least two poll options are required"). - Note in whatsapp.py that the validation rules are intentionally duplicated in main.go and must stay in sync. - Soften test_too_few_options assertion to tolerate wording changes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9b8e7f0 commit 305f964

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

whatsapp-bridge/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ func startRESTServer(client *whatsmeow.Client, messageStore *MessageStore, port
15051505
return
15061506
}
15071507
if len(req.Options) < 2 {
1508-
http.Error(w, "At least two options are required", http.StatusBadRequest)
1508+
http.Error(w, "At least two poll options are required", http.StatusBadRequest)
15091509
return
15101510
}
15111511
if len(req.Options) > 12 {

whatsapp-mcp-server/tests/test_send_poll.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_missing_name(self):
1919
def test_too_few_options(self):
2020
ok, msg = send_poll("123@s.whatsapp.net", "Q?", ["only"])
2121
assert not ok
22-
assert "two poll options" in msg
22+
assert "two" in msg.lower()
2323

2424
def test_too_many_options(self):
2525
ok, msg = send_poll("123@s.whatsapp.net", "Q?", [str(i) for i in range(13)])

whatsapp-mcp-server/whatsapp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,9 @@ def send_poll(
963963
options: list[str],
964964
selectable_option_count: int = 1,
965965
) -> tuple[bool, str]:
966+
# Validation is intentionally duplicated in whatsapp-bridge/main.go's
967+
# /api/send/poll handler so each layer is safe at its boundary. Keep the
968+
# two in sync if you change the rules here.
966969
try:
967970
if not recipient:
968971
return False, "Recipient must be provided"
@@ -979,8 +982,11 @@ def send_poll(
979982
if any(not opt or not opt.strip() for opt in options):
980983
return False, "Poll options must not be empty"
981984

982-
if selectable_option_count < 1 or selectable_option_count > len(options):
983-
return False, "selectable_option_count must be between 1 and len(options)"
985+
# whatsmeow semantics: 0 = multi-select with no limit, 1 = single-select,
986+
# N (1 < N <= len(options)) = multi-select up to N. Out-of-range values
987+
# are silently coerced to 0 by the library, so reject them upfront.
988+
if selectable_option_count < 0 or selectable_option_count > len(options):
989+
return False, "selectable_option_count must be 0 (unlimited) or between 1 and len(options)"
984990

985991
url = f"{WHATSAPP_API_BASE_URL}/send/poll"
986992
payload = {

0 commit comments

Comments
 (0)