feature/IO-3000-messaging-sockets-migration2 - Take last conversation if more than one exists.
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -45,7 +45,12 @@ exports.receive = async (req, res) => {
|
||||
}
|
||||
|
||||
const bodyshop = response.bodyshops[0];
|
||||
const existingConversation = bodyshop.conversations[0]; // Expect only one conversation per phone number per bodyshop
|
||||
|
||||
// Sort conversations by `updated_at` (or `created_at`) and pick the last one
|
||||
const sortedConversations = bodyshop.conversations.sort((a, b) => new Date(a.created_at) - new Date(b.created_at));
|
||||
const existingConversation = sortedConversations.length
|
||||
? sortedConversations[sortedConversations.length - 1]
|
||||
: null;
|
||||
|
||||
let conversationid;
|
||||
let newMessage = {
|
||||
|
||||
Reference in New Issue
Block a user