icealtria / obsidian-telegram-inbox

Receive messages from Telegram bots and add them to Obsidian's daily note.
GNU General Public License v3.0
24 stars 1 forks source link

Insert text at the top. #7

Open tonypuglieso opened 4 days ago

tonypuglieso commented 4 days ago

Hello, I wrote this tread to find out if there is a possibility to have the text inserted at the top of the note.

That would be how chats work, the last message is the one you see first.

icealtria commented 1 day ago

In fact, there is already a function in code that can do something similar but it has not been used.

I will add this feature in the next version.

tonypuglieso commented 1 day ago

Great, for now I'm change this for use local. But its better have a setting in options. Thanks for answer!.

// src/io.ts var mutex = new Mutex(); async function insertMessage(vault, message, tFile) { const release2 = await mutex.acquire(); try { const fileContent = await vault.read(tFile); if (fileContent.trim() === "") { vault.modify(tFile, message); } else { const updatedContent = ${message}\n${fileContent}; vault.modify(tFile, updatedContent); } } catch (error) { throw new Error(Error inserting message. ${error}); } finally { release2(); } }