Allow image-only visitor messages
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user