fix: monica API limits, robust contact name matching, gemini model fallbacks
All checks were successful
Build & Push Friends Image to Gitea Registry / build-and-push (push) Successful in 10s
All checks were successful
Build & Push Friends Image to Gitea Registry / build-and-push (push) Successful in 10s
This commit is contained in:
53
server.js
53
server.js
@@ -38,7 +38,7 @@ app.get("/api/contacts", async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const limit = 150;
|
||||
const limit = 100;
|
||||
const suffix = query ? `?query=${encodeURIComponent(query)}&limit=${limit}` : `?limit=${limit}`;
|
||||
const payload = await monicaFetch(`/api/contacts${suffix}`);
|
||||
const contacts = Array.isArray(payload.data) ? payload.data : [];
|
||||
@@ -265,7 +265,7 @@ export async function writeToMonica(entry) {
|
||||
results.push(await monicaWrite("note", "/api/notes", {
|
||||
contact_id: contactId,
|
||||
body: entry.note.body,
|
||||
is_favorited: Boolean(entry.note.isFavorited),
|
||||
is_favorited: entry.note.isFavorited ? 1 : 0,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -347,17 +347,37 @@ function inferContacts(text, contactsList = []) {
|
||||
if (Array.isArray(contactsList) && contactsList.length > 0) {
|
||||
for (const contact of contactsList) {
|
||||
if (!contact.name) continue;
|
||||
const nameParts = contact.name.trim().split(/\s+/);
|
||||
const firstName = nameParts[0];
|
||||
const fullName = contact.name.trim();
|
||||
|
||||
const escFullName = fullName.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
// Clean up parentheses from the name (e.g. "Aaron Lukas Lingel (Fludo Schlingel)" -> "Aaron Lukas Lingel")
|
||||
const cleanContactName = contact.name.replace(/\(.*?\)/g, "").replace(/\s+/g, " ").trim();
|
||||
if (!cleanContactName) continue;
|
||||
|
||||
const nameParts = cleanContactName.split(/\s+/).filter(p => p.length > 1);
|
||||
if (nameParts.length === 0) continue;
|
||||
|
||||
const firstName = nameParts[0];
|
||||
const lastName = nameParts[nameParts.length - 1];
|
||||
|
||||
const escFullName = cleanContactName.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
const escFirstName = firstName.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
|
||||
const regexFull = new RegExp(`\\b${escFullName}\\b`, 'i');
|
||||
const regexFirst = new RegExp(`\\b${escFirstName}\\b`, 'i');
|
||||
|
||||
if (regexFull.test(text) || (firstName.length > 2 && regexFirst.test(text))) {
|
||||
let matches = false;
|
||||
if (regexFull.test(text)) {
|
||||
matches = true;
|
||||
} else if (nameParts.length >= 2) {
|
||||
const escLastName = lastName.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
const regexLast = new RegExp(`\\b${escLastName}\\b`, 'i');
|
||||
if (regexFirst.test(text) && regexLast.test(text)) {
|
||||
matches = true;
|
||||
}
|
||||
} else if (firstName.length > 2 && regexFirst.test(text)) {
|
||||
matches = true;
|
||||
}
|
||||
|
||||
if (matches) {
|
||||
if (!candidates.some((item) => item.id === contact.id)) {
|
||||
candidates.push({
|
||||
id: contact.id,
|
||||
@@ -539,11 +559,14 @@ export function cryptoRandomId() {
|
||||
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
||||
}
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Friends listening on http://localhost:${port}`);
|
||||
if (process.env.TELEGRAM_BOT_TOKEN) {
|
||||
startTelegramBot();
|
||||
} else {
|
||||
console.log("Telegram Bot not started: TELEGRAM_BOT_TOKEN is not configured in .env");
|
||||
}
|
||||
});
|
||||
const isMain = process.argv[1] && (path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url)));
|
||||
if (isMain) {
|
||||
app.listen(port, () => {
|
||||
console.log(`Friends listening on http://localhost:${port}`);
|
||||
if (process.env.TELEGRAM_BOT_TOKEN) {
|
||||
startTelegramBot();
|
||||
} else {
|
||||
console.log("Telegram Bot not started: TELEGRAM_BOT_TOKEN is not configured in .env");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user