feat: add some error messages

This commit is contained in:
max_richter 2025-05-09 19:32:00 +02:00
parent 6883780d57
commit 6f9717f530
Signed by: max
GPG Key ID: 51973802EF3F77C5
2 changed files with 27 additions and 13 deletions

View File

@ -10,7 +10,9 @@ const activeTasks: Record<
string,
{
noteName: string;
entries: Array<{ type: string; content: string | Uint8Array }>;
entries: Array<
{ type: string; content: string | Uint8Array; fileName?: string }
>;
}
> = {};
@ -50,7 +52,8 @@ bot.command("end", async (ctx) => {
const mp3Data = await convertOggToMp3(entry.content as Uint8Array);
const transcript = await transcribe(mp3Data);
finalNote += `**Voice Transcript:**\n${transcript}\n\n`;
} catch (_) {
} catch (error) {
console.log(error);
finalNote += "**[Voice message could not be transcribed]**\n\n";
}
} else if (entry.type === "photo") {
@ -68,20 +71,27 @@ bot.command("end", async (ctx) => {
}
}
for (const entry of photoTasks) {
await createDocument(entry.path, entry.content, "image/jpeg");
try {
for (const entry of photoTasks) {
await createDocument(entry.path, entry.content, "image/jpeg");
}
await createDocument(task.noteName, finalNote, "text/markdown");
delete activeTasks[ctx.chat.id.toString()];
await ctx.reply("Note complete. Here is your markdown:");
await ctx.reply(finalNote);
} catch (error) {
console.error("Error creating document:", error);
await ctx.reply("Error creating document:");
await ctx.reply(JSON.stringify(error));
}
await createDocument(task.noteName, finalNote, "text/markdown");
delete activeTasks[ctx.chat.id.toString()];
await ctx.reply("Note complete. Here is your markdown:");
await ctx.reply(finalNote);
});
bot.on("message:text", (ctx) => {
const task = activeTasks[ctx.chat.id.toString()];
if (!task) return;
task.entries.push({ type: "text", content: ctx.message.text });
const entry = { type: "text", content: ctx.message.text };
console.log("New Entry", entry);
task.entries.push(entry);
});
bot.on("message:voice", async (ctx) => {
@ -89,7 +99,9 @@ bot.on("message:voice", async (ctx) => {
if (!task) return;
const file = await ctx.getFile();
const buffer = await downloadFile(file.file_path!);
task.entries.push({ type: "voice", content: buffer });
const entry = { type: "voice", content: buffer };
console.log("New Entry", entry);
task.entries.push(entry);
});
bot.on("message:photo", async (ctx) => {
@ -97,7 +109,10 @@ bot.on("message:photo", async (ctx) => {
if (!task) return;
const file = await ctx.getFile();
const buffer = await downloadFile(file.file_path!);
task.entries.push({ type: "photo", content: buffer });
const fileName = file.file_path!.split("/").pop()!;
const entry = { type: "photo", content: buffer, fileName };
console.log("New Entry", entry);
task.entries.push(entry);
});
export async function convertOggToMp3(

View File

@ -8,6 +8,5 @@ import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
import config from "./fresh.config.ts";
import "@lib/telegram.ts";
console.log("hello");
await start(manifest, config);