feat(telegram): wire replyToMode config, add forum topic support, fix messaging tool duplicates
Changes: - Default replyToMode from "off" to "first" for better threading UX - Add messageThreadId and replyToMessageId params for forum topic support - Add messaging tool duplicate detection to suppress redundant block replies - Add sendMessage action to telegram tool schema - Add @grammyjs/types devDependency for proper TypeScript typing - Remove @ts-nocheck and fix all type errors in send.ts - Add comprehensive docs/telegram.md documentation - Add PR-326-REVIEW.md with John Carmack-level code review Test coverage: - normalizeTextForComparison: 5 cases - isMessagingToolDuplicate: 7 cases - sendMessageTelegram thread params: 5 cases - handleTelegramAction sendMessage: 4 cases - Forum topic isolation: 4 cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
6cd32ec7f6
commit
33e2d53be3
@@ -319,7 +319,8 @@ export async function runReplyAgent(params: {
|
||||
text: cleaned,
|
||||
mediaUrls: payload.mediaUrls,
|
||||
mediaUrl: payload.mediaUrls?.[0],
|
||||
replyToId: tagResult.replyToId,
|
||||
// Default to incoming message ID for threading support (replyToMode: "first"|"all")
|
||||
replyToId: tagResult.replyToId ?? sessionCtx.MessageSid,
|
||||
};
|
||||
const payloadKey = buildPayloadKey(blockPayload);
|
||||
if (
|
||||
@@ -501,7 +502,8 @@ export async function runReplyAgent(params: {
|
||||
return {
|
||||
...payload,
|
||||
text: cleaned ? cleaned : undefined,
|
||||
replyToId: replyToId ?? payload.replyToId,
|
||||
// Default to incoming message ID for threading support (replyToMode: "first"|"all")
|
||||
replyToId: replyToId ?? payload.replyToId ?? sessionCtx.MessageSid,
|
||||
};
|
||||
})
|
||||
.filter(
|
||||
@@ -511,8 +513,14 @@ export async function runReplyAgent(params: {
|
||||
(payload.mediaUrls && payload.mediaUrls.length > 0),
|
||||
);
|
||||
|
||||
// Drop final payloads if:
|
||||
// 1. Block streaming is enabled and we already streamed block replies, OR
|
||||
// 2. A messaging tool (telegram, whatsapp, etc.) successfully sent the response.
|
||||
// The agent often generates confirmation text (e.g., "Respondi no Telegram!")
|
||||
// AFTER using the messaging tool - we must suppress this confirmation text.
|
||||
const shouldDropFinalPayloads =
|
||||
blockStreamingEnabled && didStreamBlockReply;
|
||||
(blockStreamingEnabled && didStreamBlockReply) ||
|
||||
runResult.didSendViaMessagingTool === true;
|
||||
const filteredPayloads = shouldDropFinalPayloads
|
||||
? []
|
||||
: blockStreamingEnabled
|
||||
|
||||
Reference in New Issue
Block a user