Skip to content

Commit 988bd78

Browse files
mvanhornPenchan
andauthored
fix: restore Telegram topic announce delivery (openclaw#51688) (thanks @mvanhorn)
When `replyLike.text` or `replyLike.caption` is an unexpected non-string value (edge case from some Telegram API responses), the reply body was coerced to "[object Object]" via string concatenation. Add a `typeof === "string"` guard to gracefully fall back to empty string, matching the existing pattern used for `quoteText` in the same function. Co-authored-by: Penchan <[email protected]>
1 parent 7ba28d6 commit 988bd78

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

extensions/telegram/src/bot/helpers.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,25 @@ describe("describeReplyTarget", () => {
248248
expect(result?.kind).toBe("reply");
249249
});
250250

251+
it("handles non-string reply text gracefully (issue #27201)", () => {
252+
const result = describeReplyTarget({
253+
message_id: 2,
254+
date: 1000,
255+
chat: { id: 1, type: "private" },
256+
reply_to_message: {
257+
message_id: 1,
258+
date: 900,
259+
chat: { id: 1, type: "private" },
260+
// Simulate edge case where text is an unexpected non-string value
261+
text: { some: "object" },
262+
from: { id: 42, first_name: "Alice", is_bot: false },
263+
},
264+
// oxlint-disable-next-line typescript/no-explicit-any
265+
} as any);
266+
// Should not produce "[object Object]" — should return null (no valid body)
267+
expect(result).toBeNull();
268+
});
269+
251270
it("extracts forwarded context from reply_to_message (issue #9619)", () => {
252271
// When user forwards a message with a comment, the comment message has
253272
// reply_to_message pointing to the forwarded message. We should extract

extensions/telegram/src/bot/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ export function describeReplyTarget(msg: Message): TelegramReplyTarget | null {
406406

407407
const replyLike = reply ?? externalReply;
408408
if (!body && replyLike) {
409-
const replyBody = (replyLike.text ?? replyLike.caption ?? "").trim();
409+
const rawText = replyLike.text ?? replyLike.caption ?? "";
410+
const replyBody = (typeof rawText === "string" ? rawText : "").trim();
410411
body = replyBody;
411412
if (!body) {
412413
body = resolveTelegramMediaPlaceholder(replyLike) ?? "";

0 commit comments

Comments
 (0)