ellelel
This commit is contained in:
parent
6a6ccf96cb
commit
5534e4f819
@ -372,8 +372,6 @@ func WebhookReceiveHandler(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func CreateUser(db *gorm.DB) http.HandlerFunc {
|
func CreateUser(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var user models.User
|
var user models.User
|
||||||
@ -455,7 +453,6 @@ func DeleteUser(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleTemplateTest(db *gorm.DB) http.HandlerFunc {
|
func HandleTemplateTest(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
val := r.Context().Value("ssoid")
|
val := r.Context().Value("ssoid")
|
||||||
|
|||||||
@ -25,6 +25,19 @@ func TestMessagesPages(w http.ResponseWriter, r *http.Request){
|
|||||||
func TestMessagesPages2(w http.ResponseWriter, r *http.Request){
|
func TestMessagesPages2(w http.ResponseWriter, r *http.Request){
|
||||||
renderTemplate(w,"test",nil)
|
renderTemplate(w,"test",nil)
|
||||||
}
|
}
|
||||||
|
func ApiDocPage(db *gorm.DB) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data := map[string]interface{}{}
|
||||||
|
if val := r.Context().Value("ssoid"); val != nil {
|
||||||
|
var user models.User
|
||||||
|
if err := db.Where("sso_id = ?", val.(string)).First(&user).Error; err == nil {
|
||||||
|
data["User"] = user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
renderTemplate(w, "apidoc", data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func AdminUserList(db *gorm.DB) http.HandlerFunc {
|
func AdminUserList(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var users []models.User
|
var users []models.User
|
||||||
|
|||||||
@ -63,7 +63,8 @@ func RoutesPublic(r *mux.Router, db *gorm.DB) {
|
|||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.HandleFunc("/apidoc", renders.ApiDocPage(db))
|
||||||
|
|
||||||
|
|
||||||
// // Ici on place les vues et API qui doivent être protégées
|
// // Ici on place les vues et API qui doivent être protégées
|
||||||
// r.HandleFunc("/stream", StreamHandler)
|
// r.HandleFunc("/stream", StreamHandler)
|
||||||
|
|||||||
89
frontend/templates/apidoc.pages.tmpl
Normal file
89
frontend/templates/apidoc.pages.tmpl
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
{{ define "apidoc.pages.tmpl" }}
|
||||||
|
{{ template "head" . }}
|
||||||
|
|
||||||
|
<div class="section">
|
||||||
|
<h1 class="title">📘 API WhatsApp SaaS – Documentation JSON</h1>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<p>Tu peux utiliser ces endpoints via Postman, PHP (cURL) ou JS. Toutes les requêtes POST attendent du JSON dans le corps et certaines nécessitent un JWT dans un <code>token</code> ou un <code>cookie</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h2 class="subtitle">🔐 Authentification</h2>
|
||||||
|
<p><strong>POST /api/login</strong></p>
|
||||||
|
<pre><code>{
|
||||||
|
"email": "admin@example.com",
|
||||||
|
"password": "motdepasse"
|
||||||
|
}</code></pre>
|
||||||
|
|
||||||
|
<p><strong>Retour</strong> : Cookie "token" et JSON <code>{"message":"Login success"}</code></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h2 class="subtitle">📤 Envoi message simple</h2>
|
||||||
|
<p><strong>POST /api/message/send</strong> <em>(nécessite token)</em></p>
|
||||||
|
<pre><code>{
|
||||||
|
"to": "33612345678",
|
||||||
|
"type": "text",
|
||||||
|
"text": {
|
||||||
|
"body": "Bonjour depuis l'API"
|
||||||
|
},
|
||||||
|
"token": "votre_jwt_token_si_poster_via_JSON"
|
||||||
|
}</code></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h2 class="subtitle">📤 Envoi message template</h2>
|
||||||
|
<p><strong>POST /api/message/send2</strong></p>
|
||||||
|
<pre><code>{
|
||||||
|
"to": "33612345678",
|
||||||
|
"template_name": "hello_world",
|
||||||
|
"language": "fr",
|
||||||
|
"param1": "Jean",
|
||||||
|
"param2": "commande #1234",
|
||||||
|
"token": "votre_jwt_token"
|
||||||
|
}</code></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h2 class="subtitle">📥 Webhook WhatsApp</h2>
|
||||||
|
<p><strong>GET /api/whatsapp/webhook</strong> <em>(vérification)</em><br>
|
||||||
|
Envoyer <code>?hub.mode=subscribe&hub.verify_token=secrettoken&hub.challenge=123</code></p>
|
||||||
|
|
||||||
|
<p><strong>POST /api/whatsapp/webhook</strong> <em>(callback messages/statuts)</em></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h2 class="subtitle">👤 Utilisateurs (admin uniquement)</h2>
|
||||||
|
|
||||||
|
<p><strong>POST /api/user/create</strong></p>
|
||||||
|
<pre><code>{
|
||||||
|
"email": "client@demo.com",
|
||||||
|
"password": "secret",
|
||||||
|
"sso_id": "CLIENT123",
|
||||||
|
"role": "CLIENT",
|
||||||
|
"is_active": true,
|
||||||
|
"whatsapp_token": "EAAxxxxx",
|
||||||
|
"whatsapp_phone_number_id": "123456789",
|
||||||
|
"monthly_credits": 100
|
||||||
|
}</code></pre>
|
||||||
|
|
||||||
|
<p><strong>PUT /api/user/update/{id}</strong></p>
|
||||||
|
<pre><code>{
|
||||||
|
"email": "nouveau@demo.com",
|
||||||
|
"is_active": true,
|
||||||
|
"monthly_credits": 200
|
||||||
|
}</code></pre>
|
||||||
|
|
||||||
|
<p><strong>DELETE /api/user/delete/{id}</strong></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h2 class="subtitle">💬 Conversations</h2>
|
||||||
|
<p><strong>GET /api/user/{id}/conversations</strong></p>
|
||||||
|
<p>Filtrable avec <code>?type=text</code> ou <code>?filter=today</code></p>
|
||||||
|
|
||||||
|
<p><strong>GET /admin/user/{id}/conversation-thread</strong><br>(Vue HTML pour un utilisateur)</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
{{ define "sidebar" }}
|
{{ define "sidebar" }}
|
||||||
<aside class="menu column is-2">
|
<aside class="menu column is-2" style="position: relative; min-height: 100vh;">
|
||||||
<p class="menu-label">Navigation</p>
|
<p class="menu-label">Navigation</p>
|
||||||
<ul class="menu-list">
|
<ul class="menu-list">
|
||||||
<li><a href="/dashboard">🏠 Dashboard</a></li>
|
<li><a href="/dashboard">🏠 Dashboard</a></li>
|
||||||
@ -8,10 +8,15 @@
|
|||||||
<li><a href="/admin/user">👤 Utilisateurs</a></li>
|
<li><a href="/admin/user">👤 Utilisateurs</a></li>
|
||||||
<li><a href="/test/send">📤 Test envoi</a></li>
|
<li><a href="/test/send">📤 Test envoi</a></li>
|
||||||
<li><a href="/test/send2">📤 Test envoi template</a></li>
|
<li><a href="/test/send2">📤 Test envoi template</a></li>
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<li><a href="/admin/user/{{ .User.ID }}/conversations">💬 Mes conversations</a></li>
|
<li><a href="/admin/user/{{ .User.ID }}/conversations">💬 Mes conversations</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<!-- 🔒 Déconnexion fixée en bas -->
|
||||||
|
<div style="position: absolute; bottom: 1rem; width: 90%;">
|
||||||
|
<a class="button is-danger is-fullwidth" href="/logout">🚪 Déconnexion</a>
|
||||||
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user