From f47da5f2ce44c15a3fb705aa4122b5404dc4f7a0 Mon Sep 17 00:00:00 2001 From: cangui Date: Fri, 9 May 2025 16:03:44 +0200 Subject: [PATCH] lflflfl --- backend/handlers/main.go | 19 ++++++---- .../admin_conversations_thread.pages.tmpl | 36 ++++++++++++++----- 2 files changed, 39 insertions(+), 16 deletions(-) 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" }}
+ {{ $parentMap := dict }} {{ range .Conversations }} -
-
- {{ .From }} — {{ .CreatedAt.Format "2006-01-02 15:04:05" }} + {{ if not .ParentID }} +
+
+ {{ .From }} — {{ .CreatedAt.Format "2006-01-02 15:04:05" }} +
+
{{ .Content }}
-
- {{ .Content }} -
-
+ + {{/* Afficher les enfants */}} + {{ range $i, $c := $.Conversations }} + {{ if and $c.ParentID (eq (printf "%d" $c.ParentID) (printf "%d" .ID)) }} +
+
+ {{ $c.From }} — {{ $c.CreatedAt.Format "2006-01-02 15:04:05" }} +
+
{{ $c.Content }}
+
+ {{ end }} + {{ end }} + {{ end }} {{ end }}
@@ -18,7 +31,7 @@ background: #f5f5f5; border: 1px solid #ccc; border-radius: 0.5rem; - max-height: 400px; + max-height: 600px; overflow-y: auto; } .bubble { @@ -37,10 +50,15 @@ background-color: #d1e7dd; float: right; } +.bubble.reply { + margin-left: 2rem; + margin-right: 2rem; + opacity: 0.9; +} .meta { font-size: 0.75rem; color: #666; margin-bottom: 0.25rem; } -{{ end }} \ No newline at end of file +{{ end }}