feat(telegram): ingest and render inbound voice messages

This commit is contained in:
Ruslan Bakiev
2026-02-23 12:21:53 +07:00
parent c94c229a1a
commit acd974766a
4 changed files with 225 additions and 5 deletions

View File

@@ -67,6 +67,7 @@ function extractOmniNormalizedText(rawJson: unknown, fallbackText = "") {
type ClientTimelineContentType = "CALENDAR_EVENT" | "DOCUMENT" | "RECOMMENDATION";
const CONTACT_DOCUMENT_SCOPE_PREFIX = "contact:";
const TELEGRAM_AUDIO_FILE_MARKER = "tg-file:";
function mapTimelineContentType(value: ClientTimelineContentType) {
if (value === "CALENDAR_EVENT") return "calendar_event";
@@ -141,6 +142,19 @@ function visibleMessageWhere(hiddenInboxIds: string[]) {
};
}
function resolveContactMessageAudioUrl(message: {
id: string;
channel: string;
audioUrl: string | null;
}) {
const raw = String(message.audioUrl ?? "").trim();
if (!raw) return "";
if (message.channel === "TELEGRAM" && raw.startsWith(TELEGRAM_AUDIO_FILE_MARKER)) {
return `/api/omni/telegram/media?messageId=${encodeURIComponent(message.id)}`;
}
return raw;
}
async function upsertContactInbox(input: {
teamId: string;
contactId: string;
@@ -662,7 +676,7 @@ async function getDashboard(auth: AuthContext | null) {
kind: m.kind === "CALL" ? "call" : "message",
direction: m.direction === "IN" ? "in" : "out",
text: m.content,
audioUrl: "",
audioUrl: resolveContactMessageAudioUrl(m),
duration: m.durationSec ? new Date(m.durationSec * 1000).toISOString().slice(14, 19) : "",
transcript: Array.isArray(m.transcriptJson) ? ((m.transcriptJson as any) as string[]) : [],
deliveryStatus: resolveDeliveryStatus(m),
@@ -918,7 +932,7 @@ async function getClientTimeline(auth: AuthContext | null, contactIdInput: strin
kind: m.kind === "CALL" ? "call" : "message",
direction: m.direction === "IN" ? "in" : "out",
text: m.content,
audioUrl: "",
audioUrl: resolveContactMessageAudioUrl(m),
duration: m.durationSec ? new Date(m.durationSec * 1000).toISOString().slice(14, 19) : "",
transcript: Array.isArray(m.transcriptJson) ? ((m.transcriptJson as any) as string[]) : [],
deliveryStatus: resolveDeliveryStatus(m),