Allow image-only visitor messages

This commit is contained in:
rajchales-monito
2026-07-23 23:38:33 +02:00
parent a303d10c9e
commit fdfbf5ecc4
3 changed files with 24 additions and 17 deletions
+4 -4
View File
@@ -354,7 +354,7 @@ function getVisitorConversation(res, url) {
async function createConversation(req, res) {
const body = await readJson(req, 8_000_000);
if (!body.message || !String(body.message).trim()) return json(res, 400, { error: "message_required" });
if ((!body.message || !String(body.message).trim()) && !(body.attachments || []).length) return json(res, 400, { error: "message_or_image_required" });
if (!attachmentsAreAllowed(body.attachments || [])) return json(res, 400, { error: "only_images_allowed" });
const site = db.prepare("SELECT * FROM sites WHERE site_key = ?").get(body.siteKey || "9b-plus");
if (!site) return json(res, 404, { error: "site_not_found" });
@@ -389,7 +389,7 @@ async function createConversation(req, res) {
nullish(countryFromHeaders(req))
).lastInsertRowid;
const messageId = insertMessage(conversationId, "visitor", info.name || "Visitor", String(body.message).trim());
const messageId = insertMessage(conversationId, "visitor", info.name || "Visitor", String(body.message || "").trim());
saveAttachments(conversationId, messageId, body.attachments || []);
return conversationId;
});
@@ -403,11 +403,11 @@ async function createConversation(req, res) {
async function createVisitorMessage(req, res, url) {
const body = await readJson(req, 8_000_000);
if (!body.message || !String(body.message).trim()) return json(res, 400, { error: "message_required" });
if ((!body.message || !String(body.message).trim()) && !(body.attachments || []).length) return json(res, 400, { error: "message_or_image_required" });
if (!attachmentsAreAllowed(body.attachments || [])) return json(res, 400, { error: "only_images_allowed" });
const conversation = findConversation(publicIdFrom(url));
if (!conversation) return json(res, 404, { error: "conversation_not_found" });
const messageId = insertMessage(conversation.id, "visitor", conversation.visitor_name || "Visitor", String(body.message).trim());
const messageId = insertMessage(conversation.id, "visitor", conversation.visitor_name || "Visitor", String(body.message || "").trim());
saveAttachments(conversation.id, messageId, body.attachments || []);
updateVisitorContext(conversation.id, body);
markConversationUnread(conversation.id);