Skip to content

feat(telegram): implement telegram poll action,persistent answer routing, fixed some vulnerabilities - #17357

Closed
akyourowngames wants to merge 11 commits into
openclaw:mainfrom
akyourowngames:main
Closed

akyourowngames wants to merge 11 commits into
openclaw:mainfrom
akyourowngames:main

Conversation

@akyourowngames

@akyourowngames akyourowngames commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor

Openclaw Contribution

This file summarizes the changes made to the Openclaw project.

Vulnerability Fix

A medium-severity vulnerability was identified in the request package. This package was a transitive dependency of the matrix extension. The request package is deprecated and has a known Server-Side Request Forgery (SSRF) vulnerability (GHSA-p8p7-x288-28g6).

To mitigate this vulnerability, the request package was replaced with the got package using a pnpm override in the root package.json file.

Verification

The following steps were taken to verify the fix:

  1. Tests: The extension test suite was run to ensure that the change did not break any existing functionality. All tests passed.
  2. Audit: pnpm audit was 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 dev

2. Check channel health

In a second terminal:

cd openclaw
openclaw channels status --probe

Expected: Telegram account is configured/enabled/connected.

3. Send a basic poll from CLI

cd openclaw
openclaw message poll --channel telegram --target "<chat_id_or_telegram:chat_id>" --poll-question "Lunch?" --poll-option "Pizza" --poll-option "Sushi"

Expected: poll appears in Telegram chat.

4. Verify Telegram poll options

Silent delivery:

cd openclaw
openclaw message poll --channel telegram --target "<chat>" --poll-question "Silent test?" --poll-option "A" --poll-option "B" --silent

Duration in seconds (valid range 5-600):

cd openclaw
openclaw message poll --channel telegram --target "<chat>" --poll-question "Duration?" --poll-option "A" --poll-option "B" --poll-duration-seconds 60

Anonymous poll:

cd openclaw
openclaw message poll --channel telegram --target "<chat>" --poll-question "Anon?" --poll-option "Yes" --poll-option "No" --poll-anonymous

Public poll (if exposed in your CLI surface):

cd openclaw
openclaw message poll --channel telegram --target "<chat>" --poll-question "Public?" --poll-option "Yes" --poll-option "No" --poll-public

5. Vote in Telegram and confirm inbound handling

  1. Vote on the poll in Telegram.
  2. Confirm bot sends an acknowledgement message ("Got it. You selected: ...").
  3. Confirm poll-answer event is routed into OpenClaw session/system events.

6. Check logs for handler errors

Look at gateway logs and ensure there are no poll handler errors such as:

telegram poll answer handler failed

7. Negative validation checks

One option only (should fail):

cd openclaw
openclaw message poll --channel telegram --target "<chat>" --poll-question "Bad" --poll-option "OnlyOne"

Expected: validation error requiring at least two options.

Out-of-range duration (should fail):

cd openclaw
openclaw message poll --channel telegram --target "<chat>" --poll-question "Bad duration" --poll-option "A" --poll-option "B" --poll-duration-seconds 601

Expected: validation error for duration range.

8. Optional local test suite verification

cd openclaw
pnpm -s vitest run src/telegram/send.poll.test.ts src/telegram/allowed-updates.test.ts src/telegram/poll-answer-cache.test.ts src/channels/plugins/actions/telegram.test.ts src/channels/plugins/outbound/telegram.test.ts
pnpm -s tsc -p tsconfig.json --noEmit

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 durationHours to seconds, which always exceeds Telegram's 600s limit. The request → got override addresses an SSRF vulnerability but breaks API compatibility with the matrix extension's callback-based interface.

  • Implements complete poll lifecycle: sending via sendPollTelegram, receiving answers via poll_answer handler, caching context in poll-answer-cache.ts, and routing events to agent sessions
  • Adds poll action to telegram plugin with validation for options (min 2), mutual exclusivity of pollAnonymous/pollPublic, and duration handling
  • New poll-confirmation skill enables agents to use polls for user decision-making
  • Test coverage added for poll sending, answer caching, and outbound adapter
  • The vulnerability fix may cause runtime failures in matrix extension due to incompatible API replacement

Confidence Score: 2/5

  • This PR has a critical logical error that breaks durationHours functionality and a potentially breaking API compatibility issue
  • The durationHours conversion logic has a bug that always causes validation failures (confirmed by test on line 65-77 of send.poll.test.ts). Additionally, the request → got override resolves an audit finding but breaks API compatibility with request-promise used 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.
  • src/telegram/send.ts (critical durationHours logic bug), package.json (API compatibility concern with matrix extension)

Last reviewed commit: aa0c915

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/telegram/send.ts
Comment on lines +1050 to 1055
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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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.

Comment thread package.json
"tar": "7.5.7",
"tough-cookie": "4.1.3"
"tough-cookie": "4.1.3",
"request": "npm:got@^11.8.3"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram scripts Repository scripts agents Agent runtime and tooling size: L labels Feb 15, 2026
@akyourowngames

Copy link
Copy Markdown
Contributor Author

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,
I checked both files and the commits that touched them; there are no changes related to Discord account session stores or exec approvals.

  • src/telegram/bot.ts: Telegram poll-answer handler/import + stream mode behavior only
  • src/telegram/send.ts: Telegram poll send behavior/routing only

No discord, execApprovals, or session-store approval logic appears in either file.
This PR is ready for final review!

@steipete steipete closed this Feb 16, 2026
@steipete steipete reopened this Feb 17, 2026

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/telegram/send.ts
Comment on lines +1050 to +1052
const durationSeconds =
normalizedPoll.durationSeconds ??
(normalizedPoll.durationHours ? normalizedPoll.durationHours * 3600 : undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

@greptile-apps

greptile-apps Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

src/telegram/bot.ts
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.

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 AI
This 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.

@whatrwewaitingf0r

Copy link
Copy Markdown

Hey! We've been testing this PR in our fork and found a bug in the poll answer routing for non-forum groups.

In send.ts, the poll context recording uses:

const resolvedThreadId = resolveTelegramForumThreadId({
  isForum: isGroup,  // ← bug: treats ALL groups as forums
  messageThreadId: messageThreadId ?? undefined,
});

isGroup is true for both regular groups and forum supergroups. For a regular group (where chat.is_forum is false), this incorrectly resolves to topic:1 (the General topic fallback). But the inbound handler in bot.ts correctly checks msg.chat.is_forum === true, so it produces a sessionKey without the topic suffix.

Result: enqueueSystemEvent writes to agent:...:topic:1, but drainSystemEvents reads from agent:... (no topic) — the poll answer event is never delivered to the agent.

Fix: isForum: messageThreadId != null — if a messageThreadId is provided, it's a forum; otherwise don't assume forum. For real forum groups, messageThreadId is always present (General topic = 1).

- 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! 🎉

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Mar 15, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #pr-thunderdome-dangerzone on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: telegram Channel integration: telegram scripts Repository scripts size: L stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants