fix(slack): respect historyLimit=0 when fetching thread replies
Skip thread replies fetch when historyLimit <= 0 to honor user config that disables context injection (extra tokens or privacy concerns).
This commit is contained in:
parent
eb8e004499
commit
dd4da8ec3e
@ -496,31 +496,34 @@ export async function prepareSlackMessage(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch recent thread replies (excluding starter and current message).
|
// Fetch recent thread replies (excluding starter and current message).
|
||||||
const threadReplies = await resolveSlackThreadReplies({
|
// Respect historyLimit=0 to disable context injection.
|
||||||
channelId: message.channel,
|
if (ctx.historyLimit > 0) {
|
||||||
threadTs,
|
const threadReplies = await resolveSlackThreadReplies({
|
||||||
client: ctx.app.client,
|
channelId: message.channel,
|
||||||
excludeTs: message.ts,
|
threadTs,
|
||||||
limit: ctx.historyLimit > 0 ? ctx.historyLimit : 10,
|
client: ctx.app.client,
|
||||||
});
|
excludeTs: message.ts,
|
||||||
if (threadReplies.length > 0) {
|
limit: ctx.historyLimit,
|
||||||
const formattedReplies = await Promise.all(
|
});
|
||||||
threadReplies.map(async (reply) => {
|
if (threadReplies.length > 0) {
|
||||||
const replyUser = reply.userId ? await ctx.resolveUserName(reply.userId) : null;
|
const formattedReplies = await Promise.all(
|
||||||
const replyName = replyUser?.name ?? reply.userId ?? "Unknown";
|
threadReplies.map(async (reply) => {
|
||||||
const replyWithId = `${reply.text}\n[slack message id: ${reply.ts ?? "unknown"} channel: ${message.channel}]`;
|
const replyUser = reply.userId ? await ctx.resolveUserName(reply.userId) : null;
|
||||||
return formatInboundEnvelope({
|
const replyName = replyUser?.name ?? reply.userId ?? "Unknown";
|
||||||
channel: "Slack",
|
const replyWithId = `${reply.text}\n[slack message id: ${reply.ts ?? "unknown"} channel: ${message.channel}]`;
|
||||||
from: roomLabel,
|
return formatInboundEnvelope({
|
||||||
timestamp: reply.ts ? Math.round(Number(reply.ts) * 1000) : undefined,
|
channel: "Slack",
|
||||||
body: replyWithId,
|
from: roomLabel,
|
||||||
chatType: "channel",
|
timestamp: reply.ts ? Math.round(Number(reply.ts) * 1000) : undefined,
|
||||||
senderLabel: replyName,
|
body: replyWithId,
|
||||||
envelope: envelopeOptions,
|
chatType: "channel",
|
||||||
});
|
senderLabel: replyName,
|
||||||
}),
|
envelope: envelopeOptions,
|
||||||
);
|
});
|
||||||
threadRepliesBody = formattedReplies.join("\n\n");
|
}),
|
||||||
|
);
|
||||||
|
threadRepliesBody = formattedReplies.join("\n\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user