Skip to content

Commit

Permalink
Update hivechat chat send to include product brief
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtabBukhari committed Dec 13, 2024
1 parent 13f580b commit 8f644b7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion handlers/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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")),
},
Expand Down

0 comments on commit 8f644b7

Please sign in to comment.