Skip to content

Commit 000aea1

Browse files
steipeteampagent
andauthored
1 parent 663a9d2 commit 000aea1

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

‎extensions/telegram/src/send-message.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ async function sendMessageTelegramWithContext(
7373
const {
7474
chatId,
7575
threadSpec,
76+
threadParams: preparedThreadParams,
7677
request: requestWithChatNotFound,
7778
} = await prepareTelegramOutbound({
7879
to,
7980
context: apiContext,
8081
opts,
81-
thread: { messageThreadId: opts.messageThreadId },
82+
thread: {
83+
messageThreadId: opts.messageThreadId,
84+
replyToMessageId: opts.replyToMessageId,
85+
replyQuoteText: opts.quoteText,
86+
useReplyIdAsQuoteSource: true,
87+
},
8288
request: { kind: "nonIdempotent" },
8389
});
8490
const reportDelivery = async (
@@ -136,17 +142,14 @@ async function sendMessageTelegramWithContext(
136142
opts.replyToIdSource === "implicit" &&
137143
opts.replyToMode !== undefined &&
138144
isSingleUseReplyToMode(opts.replyToMode);
139-
const buildThreadParams = (includeReplyTo: boolean) =>
140-
buildTelegramThreadReplyParams({
141-
thread: threadSpec,
142-
...(includeReplyTo
143-
? {
144-
replyToMessageId: opts.replyToMessageId,
145-
replyQuoteText: opts.quoteText,
146-
useReplyIdAsQuoteSource: true,
147-
}
148-
: {}),
149-
});
145+
let threadParamsWithoutReply: ReturnType<typeof buildTelegramThreadReplyParams> | undefined;
146+
const buildThreadParams = (includeReplyTo: boolean) => {
147+
if (includeReplyTo) {
148+
return preparedThreadParams;
149+
}
150+
threadParamsWithoutReply ??= buildTelegramThreadReplyParams({ thread: threadSpec });
151+
return threadParamsWithoutReply;
152+
};
150153
const textMode = opts.textMode ?? "markdown";
151154
// Caller-authored HTML keeps legacy parse_mode HTML semantics (literal
152155
// newlines, 4096 chunking) even on rich accounts; blocks are markdown-only.
@@ -255,7 +258,7 @@ async function sendMessageTelegramWithContext(
255258
const needsSeparateText = Boolean(followUpText);
256259
// When splitting, put reply_markup only on the follow-up text (the "main" content),
257260
// not on the media message.
258-
const mediaThreadParams = buildThreadParams(true);
261+
const mediaThreadParams = preparedThreadParams;
259262
const mediaUsedReplyTo = resolveAcceptedReplyToMessageId(mediaThreadParams) !== undefined;
260263
const baseMediaParams = {
261264
...mediaThreadParams,

0 commit comments

Comments
 (0)