From 8f644b7ab30e5ea50fc55567bf2beb5610089548 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Fri, 13 Dec 2024 08:34:18 +0500 Subject: [PATCH] Update hivechat chat send to include product brief --- handlers/chat.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/handlers/chat.go b/handlers/chat.go index 97a555a78..d99ef84b9 100644 --- a/handlers/chat.go +++ b/handlers/chat.go @@ -105,6 +105,7 @@ func (ch *ChatHandler) SendMessage(w http.ResponseWriter, r *http.Request) { ID string `json:"id"` } `json:"contextTags"` SourceWebsocketID string `json:"sourceWebsocketId"` + WorkspaceUUID string `json:"workspaceUUID"` } if err := json.NewDecoder(r.Body).Decode(&request); err != nil { @@ -116,6 +117,25 @@ func (ch *ChatHandler) SendMessage(w http.ResponseWriter, r *http.Request) { return } + if request.WorkspaceUUID == "" { + w.WriteHeader(http.StatusBadRequest) + json.NewEncoder(w).Encode(ChatResponse{ + Success: false, + Message: "workspaceUUID is required", + }) + return + } + + context, err := ch.db.GetProductBrief(request.WorkspaceUUID) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + json.NewEncoder(w).Encode(ChatResponse{ + Success: false, + Message: "Error retrieving product brief", + }) + return + } + history, err := ch.db.GetChatMessagesForChatID(request.ChatID) if err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -170,7 +190,7 @@ func (ch *ChatHandler) SendMessage(w http.ResponseWriter, r *http.Request) { "messageId": createdMessage.ID, "message": request.Message, "history": messageHistory, - "contextTags": "This is a project with Typescript frontend and Go Backend", + "contextTags": context, "sourceWebsocketId": request.SourceWebsocketID, "webhook_url": fmt.Sprintf("%s/hivechat/process", os.Getenv("HOST")), },