feat(backend,frontend,mcp): saved messages take text, files, voices and archived messages, the one write to telegram
This commit is contained in:
1 parent
2dd4e589c3
commit
58b4346166
22 files changed
+1091
-35
No files matched your search
@@ -95,6 +95,18 @@ export async function request<T>(
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export async function requestForm<T>(path: string, form: FormData): Promise<T> {
|
||||
const response = await fetch(`${BASE}${path}`, {
|
||||
body: form,
|
||||
headers: authHeaders(),
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
return handleError(response);
|
||||
}
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
function streamUrl(path: string): string {
|
||||
const query = auth.token ? `?token=${encodeURIComponent(auth.token)}` : "";
|
||||
return `${BASE}${path}${query}`;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { request } from "#lib/api/client.js";
|
||||
import { request, requestForm } from "#lib/api/client.js";
|
||||
import type {
|
||||
Account,
|
||||
Annotation,
|
||||
@@ -597,6 +597,47 @@ export function transcribeMedia(
|
||||
});
|
||||
}
|
||||
|
||||
export interface SavedResult {
|
||||
chat_id: number | null;
|
||||
error: string | null;
|
||||
message_id: number | null;
|
||||
mode: "copied" | "forwarded" | "sent" | null;
|
||||
status: "done" | "failed" | "pending";
|
||||
}
|
||||
|
||||
export interface SavedDraft {
|
||||
file?: File;
|
||||
text?: string;
|
||||
voice?: boolean;
|
||||
}
|
||||
|
||||
export function sendToSaved(draft: SavedDraft): Promise<SavedResult> {
|
||||
const form = new FormData();
|
||||
form.set("account_id", String(accounts.selectedId));
|
||||
if (draft.text) {
|
||||
form.set("text", draft.text);
|
||||
}
|
||||
if (draft.file) {
|
||||
form.set("file", draft.file);
|
||||
form.set("voice", String(Boolean(draft.voice)));
|
||||
}
|
||||
return requestForm<SavedResult>("/saved", form);
|
||||
}
|
||||
|
||||
export function forwardToSaved(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
): Promise<SavedResult> {
|
||||
return request<SavedResult>("/saved/forward", {
|
||||
body: {
|
||||
account_id: accounts.selectedId,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
export function listAnnotations(
|
||||
options: { chatId?: number; messageId?: number } = {}
|
||||
): Promise<Annotation[]> {
|
||||
|
||||
Reference in new issue
Block a user