Skip to content

Commit

Permalink
Merge pull request stakwork#2181 from MahtabBukhari/Update_hivechatch…
Browse files Browse the repository at this point in the history
…atsend_to_include_product_brief

Update /hivechat/chat/send to include product brief
  • Loading branch information
humansinstitute authored Dec 13, 2024
2 parents 13f580b + 8f644b7 commit 6bee08d
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 6bee08d

Please sign in to comment.