Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. WalkthroughThe workflow Possibly related PRs
Comment |
|
Sizurp |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/pr-comment-slack-notify.yml:
- Around line 162-170: The current conversations.replies call that sets REPLIES
and extracts SLACK_MSG_TS can miss the edited message in long threads due to the
200-item cap; update the logic that runs when THREAD_TS is set (the edited
branch) to perform cursor-based pagination: repeatedly call
conversations.replies with the response_metadata.next_cursor until either the
message matching COMMENT_ID is found or no cursor remains, merging/fetching each
page into REPLIES or scanning per-page for the matching
.metadata.event_payload.comment_id to set SLACK_MSG_TS; ensure the cursor query
parameter is URL-encoded when appended to the API URL and stop the loop once
SLACK_MSG_TS is determined or next_cursor is empty to avoid infinite loops.
| if [ "$EVENT_ACTION" = "edited" ] && [ -n "$THREAD_TS" ]; then | ||
| # Edit — find the existing Slack message for this GitHub comment and update it | ||
| REPLIES=$(curl -s "https://slack.com/api/conversations.replies?channel=$SLACK_CHANNEL_ID&ts=$THREAD_TS&include_all_metadata=true&limit=200" \ | ||
| -H "Authorization: Bearer $SLACK_BOT_TOKEN") | ||
|
|
||
| SLACK_MSG_TS=$(echo "$REPLIES" | jq -r --arg cid "$COMMENT_ID" ' | ||
| .messages[] | ||
| | select(.metadata.event_payload.comment_id == $cid) | ||
| | .ts' | head -1) |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Slack conversations.replies API pagination next_cursor limit
💡 Result:
conversations.replies uses cursor-based pagination:
- First request: pass
channel,ts, and optionallylimit(page size). Example:limit=200(Slack recommends ≤200). The method’s general maximum is documented as1000, but see the non‑Marketplace note below. [1][2] - Next pages: read
response_metadata.next_cursorfrom the response, then call again withcursor=<next_cursor>(and the samelimit). Repeat untilnext_cursoris missing/null/empty string (""). [1][3] - Don’t stop just because you got fewer than
limititems—Slack may return fewer (even 0) while still providing anext_cursor. Always key offnext_cursor. [2][3] - Encoding: cursor strings often end with
=; when sending as a URL query parameter, encode it (e.g.,=→%3D). [3]
Important (rate-limit-driven limit change): For apps commercially distributed outside the Slack Marketplace, Slack reduced the default and maximum limit for conversations.replies to 15 and rate-limited the method to 1 request/min for certain apps/installations (see Slack’s changelog and method docs for applicability dates). [1][4]
Minimal pagination loop (pseudo):
cursor = null- call
conversations.replies(channel, ts, limit, cursor?) cursor = response.response_metadata.next_cursor- if
cursoris empty → done; else repeat. [1][3]
Sources:
[1] Slack method docs: conversations.replies https://api.slack.com/methods/conversations.replies
[2] Slack Conversations API pagination notes https://api.slack.com/conversations-api
[3] Slack pagination guide https://docs.slack.dev/apis/web-api/pagination/
[4] Slack changelog (rate limit + limit=15 for non‑Marketplace) https://api.slack.com/changelog/2025-05-terms-rate-limit-update-and-faq
Paginate replies to avoid missing edited messages in long threads.
conversations.replies is capped at 200 (or 15 for non-Marketplace apps); if a thread exceeds that, the target message won't be found and edits will post a duplicate reply instead of updating in place. Implement cursor-based pagination using response_metadata.next_cursor.
One detail: URL-encode the cursor when passing it as a query parameter (e.g., = → %3D), since cursor strings often contain special characters.
🧭 Suggested pagination pattern
- REPLIES=$(curl -s "https://slack.com/api/conversations.replies?channel=$SLACK_CHANNEL_ID&ts=$THREAD_TS&include_all_metadata=true&limit=200" \
- -H "Authorization: Bearer $SLACK_BOT_TOKEN")
-
- SLACK_MSG_TS=$(echo "$REPLIES" | jq -r --arg cid "$COMMENT_ID" '
- .messages[]
- | select(.metadata.event_payload.comment_id == $cid)
- | .ts' | head -1)
+ SLACK_MSG_TS=""
+ CURSOR=""
+ while :; do
+ REPLIES=$(curl -s "https://slack.com/api/conversations.replies?channel=$SLACK_CHANNEL_ID&ts=$THREAD_TS&include_all_metadata=true&limit=200&cursor=$CURSOR" \
+ -H "Authorization: Bearer $SLACK_BOT_TOKEN")
+
+ SLACK_MSG_TS=$(echo "$REPLIES" | jq -r --arg cid "$COMMENT_ID" '
+ .messages[]
+ | select(.metadata.event_payload.comment_id == $cid)
+ | .ts' | head -1)
+
+ if [ -n "$SLACK_MSG_TS" ] && [ "$SLACK_MSG_TS" != "null" ]; then
+ break
+ fi
+
+ CURSOR=$(echo "$REPLIES" | jq -r '.response_metadata.next_cursor // empty')
+ [ -z "$CURSOR" ] && break
+ doneNote: Consider URL-encoding the cursor parameter if special characters cause issues.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/pr-comment-slack-notify.yml around lines 162 - 170, The
current conversations.replies call that sets REPLIES and extracts SLACK_MSG_TS
can miss the edited message in long threads due to the 200-item cap; update the
logic that runs when THREAD_TS is set (the edited branch) to perform
cursor-based pagination: repeatedly call conversations.replies with the
response_metadata.next_cursor until either the message matching COMMENT_ID is
found or no cursor remains, merging/fetching each page into REPLIES or scanning
per-page for the matching .metadata.event_payload.comment_id to set
SLACK_MSG_TS; ensure the cursor query parameter is URL-encoded when appended to
the API URL and stop the loop once SLACK_MSG_TS is determined or next_cursor is
empty to avoid infinite loops.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
editedcomment events (in addition tocreated)conversations.replies+ metadata lookup, then updates it viachat.updateTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements