chore: format + fix telegram thread ids
This commit is contained in:
@@ -18,4 +18,3 @@ describe("formatRawAssistantErrorForUi", () => {
|
||||
expect(formatRawAssistantErrorForUi("")).toContain("unknown error");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -155,11 +155,7 @@ export function resolveCommandAuthorization(params: {
|
||||
const senderId = matchedSender ?? senderCandidates[0];
|
||||
|
||||
const enforceOwner = Boolean(dock?.commands?.enforceOwnerForCommands);
|
||||
const isOwner =
|
||||
!enforceOwner ||
|
||||
allowAll ||
|
||||
ownerList.length === 0 ||
|
||||
Boolean(matchedSender);
|
||||
const isOwner = !enforceOwner || allowAll || ownerList.length === 0 || Boolean(matchedSender);
|
||||
const isAuthorizedSender = commandAuthorized && isOwner;
|
||||
|
||||
return {
|
||||
|
||||
@@ -8,6 +8,17 @@ function parseReplyToMessageId(replyToId?: string | null) {
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
function parseThreadId(threadId?: string | number | null) {
|
||||
if (threadId == null) return undefined;
|
||||
if (typeof threadId === "number") {
|
||||
return Number.isFinite(threadId) ? Math.trunc(threadId) : undefined;
|
||||
}
|
||||
const trimmed = threadId.trim();
|
||||
if (!trimmed) return undefined;
|
||||
const parsed = Number.parseInt(trimmed, 10);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
export const telegramOutbound: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
chunker: markdownToTelegramHtmlChunks,
|
||||
@@ -25,10 +36,11 @@ export const telegramOutbound: ChannelOutboundAdapter = {
|
||||
sendText: async ({ to, text, accountId, deps, replyToId, threadId }) => {
|
||||
const send = deps?.sendTelegram ?? sendMessageTelegram;
|
||||
const replyToMessageId = parseReplyToMessageId(replyToId);
|
||||
const messageThreadId = parseThreadId(threadId);
|
||||
const result = await send(to, text, {
|
||||
verbose: false,
|
||||
textMode: "html",
|
||||
messageThreadId: threadId ?? undefined,
|
||||
messageThreadId,
|
||||
replyToMessageId,
|
||||
accountId: accountId ?? undefined,
|
||||
});
|
||||
@@ -37,11 +49,12 @@ export const telegramOutbound: ChannelOutboundAdapter = {
|
||||
sendMedia: async ({ to, text, mediaUrl, accountId, deps, replyToId, threadId }) => {
|
||||
const send = deps?.sendTelegram ?? sendMessageTelegram;
|
||||
const replyToMessageId = parseReplyToMessageId(replyToId);
|
||||
const messageThreadId = parseThreadId(threadId);
|
||||
const result = await send(to, text, {
|
||||
verbose: false,
|
||||
mediaUrl,
|
||||
textMode: "html",
|
||||
messageThreadId: threadId ?? undefined,
|
||||
messageThreadId,
|
||||
replyToMessageId,
|
||||
accountId: accountId ?? undefined,
|
||||
});
|
||||
|
||||
@@ -36,6 +36,23 @@ import type { ChannelPlugin } from "./types.js";
|
||||
|
||||
const meta = getChatChannelMeta("telegram");
|
||||
|
||||
function parseReplyToMessageId(replyToId?: string | null) {
|
||||
if (!replyToId) return undefined;
|
||||
const parsed = Number.parseInt(replyToId, 10);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
function parseThreadId(threadId?: string | number | null) {
|
||||
if (threadId == null) return undefined;
|
||||
if (typeof threadId === "number") {
|
||||
return Number.isFinite(threadId) ? Math.trunc(threadId) : undefined;
|
||||
}
|
||||
const trimmed = threadId.trim();
|
||||
if (!trimmed) return undefined;
|
||||
const parsed = Number.parseInt(trimmed, 10);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount> = {
|
||||
id: "telegram",
|
||||
meta: {
|
||||
@@ -231,29 +248,25 @@ export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount> = {
|
||||
},
|
||||
sendText: async ({ to, text, accountId, deps, replyToId, threadId }) => {
|
||||
const send = deps?.sendTelegram ?? sendMessageTelegram;
|
||||
const replyToMessageId = replyToId ? Number.parseInt(replyToId, 10) : undefined;
|
||||
const resolvedReplyToMessageId = Number.isFinite(replyToMessageId)
|
||||
? replyToMessageId
|
||||
: undefined;
|
||||
const replyToMessageId = parseReplyToMessageId(replyToId);
|
||||
const messageThreadId = parseThreadId(threadId);
|
||||
const result = await send(to, text, {
|
||||
verbose: false,
|
||||
messageThreadId: threadId ?? undefined,
|
||||
replyToMessageId: resolvedReplyToMessageId,
|
||||
messageThreadId,
|
||||
replyToMessageId,
|
||||
accountId: accountId ?? undefined,
|
||||
});
|
||||
return { channel: "telegram", ...result };
|
||||
},
|
||||
sendMedia: async ({ to, text, mediaUrl, accountId, deps, replyToId, threadId }) => {
|
||||
const send = deps?.sendTelegram ?? sendMessageTelegram;
|
||||
const replyToMessageId = replyToId ? Number.parseInt(replyToId, 10) : undefined;
|
||||
const resolvedReplyToMessageId = Number.isFinite(replyToMessageId)
|
||||
? replyToMessageId
|
||||
: undefined;
|
||||
const replyToMessageId = parseReplyToMessageId(replyToId);
|
||||
const messageThreadId = parseThreadId(threadId);
|
||||
const result = await send(to, text, {
|
||||
verbose: false,
|
||||
mediaUrl,
|
||||
messageThreadId: threadId ?? undefined,
|
||||
replyToMessageId: resolvedReplyToMessageId,
|
||||
messageThreadId,
|
||||
replyToMessageId,
|
||||
accountId: accountId ?? undefined,
|
||||
});
|
||||
return { channel: "telegram", ...result };
|
||||
|
||||
@@ -29,7 +29,12 @@ export function normalizeSlackChannelType(
|
||||
channelId?: string | null,
|
||||
): SlackMessageEvent["channel_type"] {
|
||||
const normalized = channelType?.trim().toLowerCase();
|
||||
if (normalized === "im" || normalized === "mpim" || normalized === "channel" || normalized === "group") {
|
||||
if (
|
||||
normalized === "im" ||
|
||||
normalized === "mpim" ||
|
||||
normalized === "channel" ||
|
||||
normalized === "group"
|
||||
) {
|
||||
return normalized;
|
||||
}
|
||||
return inferSlackChannelType(channelId) ?? "channel";
|
||||
|
||||
@@ -28,4 +28,3 @@ describe("extractTextFromMessage", () => {
|
||||
expect(text).toContain("unknown error");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user