diff --git a/backend/handlers/main.go b/backend/handlers/main.go index 0331071..b19aac8 100644 --- a/backend/handlers/main.go +++ b/backend/handlers/main.go @@ -342,9 +342,14 @@ func WebhookReceiveHandler(db *gorm.DB) http.HandlerFunc { content = msg["text"].(map[string]interface{})["body"].(string) } - contextID := "" + var parentID *uint if ctx, ok := msg["context"].(map[string]interface{}); ok { - contextID = fmt.Sprintf("%v", ctx["id"]) + contextID := fmt.Sprintf("%v", ctx["id"]) + var parent models.Conversation + if err := db.Where("message_id = ?", contextID).First(&parent).Error; err == nil { + parentID = &parent.ID + content += fmt.Sprintf(" (réponse à %s)", contextID) + } } conv := models.Conversation{ @@ -356,10 +361,7 @@ func WebhookReceiveHandler(db *gorm.DB) http.HandlerFunc { Content: content, Direction: "inbound", Status: "received", - } - - if contextID != "" { - conv.Content += fmt.Sprintf(" (réponse à %s)", contextID) + ParentID: parentID, } if err := db.Create(&conv).Error; err != nil { @@ -372,6 +374,7 @@ func WebhookReceiveHandler(db *gorm.DB) http.HandlerFunc { } + func CreateUser(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var user models.User @@ -504,7 +507,8 @@ func HandleTemplateTest(db *gorm.DB) http.HandlerFunc { http.Error(w, "Échec de l'appel API WhatsApp", http.StatusBadGateway) return } - defer resp.Body.Close(); + defer resp.Body.Close() + var respBody map[string]interface{} json.NewDecoder(resp.Body).Decode(&respBody) @@ -532,3 +536,4 @@ func HandleTemplateTest(db *gorm.DB) http.HandlerFunc { } } + diff --git a/frontend/templates/admin_conversations_thread.pages.tmpl b/frontend/templates/admin_conversations_thread.pages.tmpl index 869e88c..d136e23 100644 --- a/frontend/templates/admin_conversations_thread.pages.tmpl +++ b/frontend/templates/admin_conversations_thread.pages.tmpl @@ -1,14 +1,27 @@ {{ define "admin_conversations_thread.pages.tmpl" }}