Repository navigation
feat(telegram): implement telegram poll action,persistent answer routing, fixed some vulnerabilities - #17357
feat(telegram): implement telegram poll action,persistent answer routing, fixed some vulnerabilities #17357akyourowngames wants to merge 11 commits into
Conversation
| const durationSeconds = | ||
| normalizedPoll.durationSeconds ?? | ||
| (normalizedPoll.durationHours ? normalizedPoll.durationHours * 3600 : undefined); | ||
|
|
||
| if (durationSeconds !== undefined && (durationSeconds < 5 || durationSeconds > 600)) { | ||
| throw new Error("Telegram poll durationSeconds must be between 5 and 600"); |
There was a problem hiding this comment.
durationHours conversion always exceeds Telegram's limit
The conversion durationHours * 3600 will always produce a value ≥ 3600 (since normalizePollInput floors durationHours to a minimum of 1), which always fails the 5–600 range check on line 1054. This means any caller passing durationHours gets a confusing error about durationSeconds rather than a clear message that Telegram's open_period max is 600 seconds (~10 minutes) and hours-based durations are not applicable.
The previous behavior threw a clear error: "durationHours is not supported. Use durationSeconds (5-600) instead." The new code silently converts but always fails validation. Consider restoring a clear rejection, for example:
| const durationSeconds = | |
| normalizedPoll.durationSeconds ?? | |
| (normalizedPoll.durationHours ? normalizedPoll.durationHours * 3600 : undefined); | |
| if (durationSeconds !== undefined && (durationSeconds < 5 || durationSeconds > 600)) { | |
| throw new Error("Telegram poll durationSeconds must be between 5 and 600"); | |
| if (normalizedPoll.durationHours !== undefined) { | |
| throw new Error( | |
| "Telegram polls do not support durationHours (max open_period is 600s / 10min). Use durationSeconds (5-600) instead.", | |
| ); | |
| } | |
| const durationSeconds = normalizedPoll.durationSeconds; | |
| if (durationSeconds !== undefined && (durationSeconds < 5 || durationSeconds > 600)) { | |
| throw new Error("Telegram poll durationSeconds must be between 5 and 600"); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/send.ts
Line: 1050:1055
Comment:
**`durationHours` conversion always exceeds Telegram's limit**
The conversion `durationHours * 3600` will always produce a value ≥ 3600 (since `normalizePollInput` floors `durationHours` to a minimum of 1), which always fails the 5–600 range check on line 1054. This means any caller passing `durationHours` gets a confusing error about `durationSeconds` rather than a clear message that Telegram's `open_period` max is 600 seconds (~10 minutes) and hours-based durations are not applicable.
The previous behavior threw a clear error: `"durationHours is not supported. Use durationSeconds (5-600) instead."` The new code silently converts but always fails validation. Consider restoring a clear rejection, for example:
```suggestion
if (normalizedPoll.durationHours !== undefined) {
throw new Error(
"Telegram polls do not support durationHours (max open_period is 600s / 10min). Use durationSeconds (5-600) instead.",
);
}
const durationSeconds = normalizedPoll.durationSeconds;
if (durationSeconds !== undefined && (durationSeconds < 5 || durationSeconds > 600)) {
throw new Error("Telegram poll durationSeconds must be between 5 and 600");
}
```
How can I resolve this? If you propose a fix, please make it concise.| "tar": "7.5.7", | ||
| "tough-cookie": "4.1.3" | ||
| "tough-cookie": "4.1.3", | ||
| "request": "npm:got@^11.8.3" |
There was a problem hiding this comment.
request → got override breaks API compatibility
The request package uses a callback-based API (request(url, opts, callback)), while got uses a completely different promise-based API (got(url, opts) → Promise). The transitive consumer request-promise (used by @vector-im/matrix-bot-sdk) wraps request's callback interface internally — it won't function correctly when request is replaced by got.
This override will resolve the SSRF audit finding, but it will likely cause runtime errors in the matrix extension when the bot SDK attempts HTTP calls. Consider one of:
- Pinning to a patched fork of
requestthat fixes the SSRF without changing the API (e.g.,postman-request) - Adding
requesttopnpm.overrideswith a version/fork that retains API compatibility - Removing
requestandrequest-promisefrom the matrix bot SDK's resolution entirely if those code paths are truly unused
Prompt To Fix With AI
This is a comment left during a code review.
Path: package.json
Line: 210:210
Comment:
**`request` → `got` override breaks API compatibility**
The `request` package uses a callback-based API (`request(url, opts, callback)`), while `got` uses a completely different promise-based API (`got(url, opts) → Promise`). The transitive consumer `request-promise` (used by `@vector-im/matrix-bot-sdk`) wraps `request`'s callback interface internally — it won't function correctly when `request` is replaced by `got`.
This override will resolve the SSRF audit finding, but it will likely cause runtime errors in the matrix extension when the bot SDK attempts HTTP calls. Consider one of:
- Pinning to a patched fork of `request` that fixes the SSRF without changing the API (e.g., `postman-request`)
- Adding `request` to `pnpm.overrides` with a version/fork that retains API compatibility
- Removing `request` and `request-promise` from the matrix bot SDK's resolution entirely if those code paths are truly unused
How can I resolve this? If you propose a fix, please make it concise.|
All linting and formatting issues have been resolved locally and pushed. The formal_conformance failure appears to be a known 403 permission issue for external forksa and discord channel issue is another bug by another fork,
No discord, execApprovals, or session-store approval logic appears in either file. |
bfc1ccb to
f92900f
Compare
| const durationSeconds = | ||
| normalizedPoll.durationSeconds ?? | ||
| (normalizedPoll.durationHours ? normalizedPoll.durationHours * 3600 : undefined); |
There was a problem hiding this comment.
The conversion normalizedPoll.durationHours * 3600 always produces ≥3600 (since normalizePollInput floors to min 1), failing the 5-600 check on line 1054. The test on line 65-77 of send.poll.test.ts confirms this: durationHours: 1 throws "durationSeconds must be between 5 and 600".
Previous code threw a clear error about hours not being supported. Current code silently converts but always fails validation.
| const durationSeconds = | |
| normalizedPoll.durationSeconds ?? | |
| (normalizedPoll.durationHours ? normalizedPoll.durationHours * 3600 : undefined); | |
| if (normalizedPoll.durationHours !== undefined) { | |
| throw new Error( | |
| "Telegram poll durationHours is not supported. Use durationSeconds (5-600) instead.", | |
| ); | |
| } | |
| const durationSeconds = normalizedPoll.durationSeconds; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/send.ts
Line: 1050:1052
Comment:
The conversion `normalizedPoll.durationHours * 3600` always produces ≥3600 (since `normalizePollInput` floors to min 1), failing the 5-600 check on line 1054. The test on line 65-77 of `send.poll.test.ts` confirms this: `durationHours: 1` throws `"durationSeconds must be between 5 and 600"`.
Previous code threw a clear error about hours not being supported. Current code silently converts but always fails validation.
```suggestion
if (normalizedPoll.durationHours !== undefined) {
throw new Error(
"Telegram poll durationHours is not supported. Use durationSeconds (5-600) instead.",
);
}
const durationSeconds = normalizedPoll.durationSeconds;
```
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: src/telegram/bot.ts
Line: 1:1
Comment:
Add test coverage for the `poll_answer` handler to verify it correctly extracts user info, calls `enqueuePollAnswerEvent`, and sends acknowledgement messages when `summary.chatId` is present.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
|
Hey! We've been testing this PR in our fork and found a bug in the poll answer routing for non-forum groups. In const resolvedThreadId = resolveTelegramForumThreadId({
isForum: isGroup, // ← bug: treats ALL groups as forums
messageThreadId: messageThreadId ?? undefined,
});
Result: Fix: - isForum: isGroup,
+ isForum: messageThreadId != null,Everything else in the PR works great — tested poll creation, non-anonymous voting, vote retraction, and multi-option selection. Nice work! 🎉 |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Openclaw Contribution
This file summarizes the changes made to the Openclaw project.
Vulnerability Fix
A medium-severity vulnerability was identified in the
requestpackage. This package was a transitive dependency of thematrixextension. Therequestpackage is deprecated and has a known Server-Side Request Forgery (SSRF) vulnerability (GHSA-p8p7-x288-28g6).To mitigate this vulnerability, the
requestpackage was replaced with thegotpackage using apnpmoverride in the rootpackage.jsonfile.Verification
The following steps were taken to verify the fix:
pnpm auditwas run after the change to confirm that the vulnerability was no longer present. The audit reported no vulnerabilities.Telegram Poll Plugin Verification
Use these steps to verify the Telegram poll plugin flow end-to-end.
1. Configure Telegram and start gateway
cd openclaw openclaw config set channels.telegram.botToken "<YOUR_BOT_TOKEN>" openclaw config set channels.telegram.enabled true pnpm dev2. Check channel health
In a second terminal:
cd openclaw openclaw channels status --probeExpected: Telegram account is configured/enabled/connected.
3. Send a basic poll from CLI
Expected: poll appears in Telegram chat.
4. Verify Telegram poll options
Silent delivery:
Duration in seconds (valid range 5-600):
Anonymous poll:
Public poll (if exposed in your CLI surface):
5. Vote in Telegram and confirm inbound handling
6. Check logs for handler errors
Look at gateway logs and ensure there are no poll handler errors such as:
telegram poll answer handler failed7. Negative validation checks
One option only (should fail):
Expected: validation error requiring at least two options.
Out-of-range duration (should fail):
Expected: validation error for duration range.
8. Optional local test suite verification
successfully created one and one poll cast feature, for agent, where agent have access to what user casted!!
Greptile Summary
Adds Telegram poll functionality with persistent answer routing to agent sessions, including CLI support and agent tools. Changes default poll behavior to non-anonymous (public votes) and converts
durationHoursto seconds, which always exceeds Telegram's 600s limit. Therequest→gotoverride addresses an SSRF vulnerability but breaks API compatibility with the matrix extension's callback-based interface.sendPollTelegram, receiving answers viapoll_answerhandler, caching context inpoll-answer-cache.ts, and routing events to agent sessionspollaction to telegram plugin with validation for options (min 2), mutual exclusivity ofpollAnonymous/pollPublic, and duration handlingpoll-confirmationskill enables agents to use polls for user decision-makingConfidence Score: 2/5
durationHoursfunctionality and a potentially breaking API compatibility issuedurationHoursconversion logic has a bug that always causes validation failures (confirmed by test on line 65-77 of send.poll.test.ts). Additionally, therequest→gotoverride resolves an audit finding but breaks API compatibility withrequest-promiseused by the matrix bot SDK, which may cause runtime errors. The poll implementation itself is well-structured with good test coverage, but these two issues need resolution before merge.Last reviewed commit: aa0c915