From a097ca85366ef02efdbf09fff3c885c66eee97bf Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Tue, 11 Aug 2026 11:36:11 +0530 Subject: [PATCH] fix create conversation API ignoring external_user_id for existing contacts --- cmd/conversation.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/conversation.go b/cmd/conversation.go index a9226cd0..762631b7 100644 --- a/cmd/conversation.go +++ b/cmd/conversation.go @@ -817,7 +817,13 @@ func handleCreateConversation(r *fastglue.Request) error { CustomAttributes: json.RawMessage(`{}`), } // Reuse an existing contact as-is; this endpoint is gated only on conversations:write and must never rename a contact. - existing, err := app.user.GetContactByEmail(email) + // Match by external_user_id when provided - one email can map to multiple external IDs. + var existing umodels.User + if req.ExternalUserID != "" { + existing, err = app.user.GetByExternalID(req.ExternalUserID) + } else { + existing, err = app.user.GetContactByEmail(email) + } if err != nil { if envErr, ok := err.(envelope.Error); !ok || envErr.ErrorType != envelope.NotFoundError { return sendErrorEnvelope(r, err)