-
-
Notifications
You must be signed in to change notification settings - Fork 52.9k
Description
Version
2026.2.26
Bug
When an agent returns `null` or `undefined` as reply text (instead of an empty string `""`), the Telegram typing indicator gets stuck until the 2-minute TTL expires.
Root cause
In `pi-embedded-*.js`, the guard that skips sending empty payloads only handles empty strings, not `null`/`undefined`:
```js
// Current (buggy) — only catches empty string ""
if (!(hasMedia || typeof payload.text !== "string" || payload.text.length > 0)) {
```
When `payload.text` is `null` or `undefined`, `typeof payload.text !== "string"` evaluates to `true`, the OR short-circuits, the condition is `false`, and `sendPayload(null)` is called → Telegram API returns `400: text must be non-empty` → typing indicator is never cleaned up.
Suggested fix
```js
// Catches null, undefined, and empty string
if (!(hasMedia || (payload.text && typeof payload.text === "string" && payload.text.length > 0))) {
```
Log evidence
```
[telegram] sendMessage failed: Call to 'sendMessage' failed! (400: Bad Request: text must be non-empty)
[telegram] final reply failed: GrammyError: Call to 'sendMessage' failed!
typing TTL reached (2m); stopping typing indicator
```
Reproduction
- Configure a Telegram channel
- Trigger an agent run that produces no text output (e.g. a tool-only run or a run that returns early with no assistant message)
- Observe the typing indicator in Telegram — it stays active for 2 minutes instead of clearing immediately