Private
Public Access
1
0

Update sendMessage to return inserted guid for new protocol

This commit is contained in:
2023-12-10 17:45:40 -08:00
parent f222078a9d
commit 416949095c
3 changed files with 94 additions and 1 deletions

View File

@@ -224,7 +224,22 @@ func (m *MockHTTPServer) handleSendMessage(w http.ResponseWriter, r *http.Reques
// Send message
m.Server.SendMessage(conversation, message)
w.WriteHeader(http.StatusOK)
// Formulate response
sendMessageResp := SendMessageResponse{
Guid: message.Guid,
}
// Encode response as JSON
jsonData, err := json.Marshal(sendMessageResp)
if err != nil {
log.Error().Err(err).Msg("Error marshalling response")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Write JSON to response
w.Header().Set("Content-Type", "application/json")
w.Write(jsonData)
}
func (m *MockHTTPServer) handlePollUpdates(w http.ResponseWriter, r *http.Request) {
@@ -315,6 +330,11 @@ func NewMockHTTPServer(config MockHTTPServerConfiguration) *MockHTTPServer {
authEnabled: config.AuthEnabled,
}
// Redirect /api/* to /*
this.mux.Handle("/api/", http.StripPrefix("/api", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, r.URL.Path, http.StatusMovedPermanently)
})))
this.mux.Handle("/version", http.HandlerFunc(this.handleVersion))
this.mux.Handle("/conversations", http.HandlerFunc(this.handleConversations))
this.mux.Handle("/status", http.HandlerFunc(this.handleStatus))