new file: .env

new file:   bot.db
	new file:   db/db.go
	new file:   go.mod
	new file:   go.sum
	new file:   handlers/dashboard.go
	new file:   handlers/webhook.go
	new file:   main.go
	new file:   services/openrouter.go
	new file:   services/whatsapp.go
	new file:   templates/dashboard.html
	new file:   types/types.go
This commit is contained in:
2026-03-01 05:07:40 -03:00
parent 3412ff41ec
commit 7a5f5d86f4
12 changed files with 443 additions and 0 deletions

61
handlers/dashboard.go Normal file
View File

@@ -0,0 +1,61 @@
package handlers
import (
"net/http"
"whatsapp-bot/db"
"whatsapp-bot/services"
"github.com/gin-gonic/gin"
)
func ShowDashboard(c *gin.Context) {
rows, err := db.Conn.Query("SELECT customer_phone, appointment_date, status FROM appointments")
if err != nil {
c.String(http.StatusInternalServerError, "DB Error")
return
}
defer rows.Close()
type Appt struct{ CustomerPhone, Date, Status string }
var appts []Appt
for rows.Next() {
var a Appt
rows.Scan(&a.CustomerPhone, &a.Date, &a.Status)
appts = append(appts, a)
}
c.HTML(http.StatusOK, "dashboard.html", gin.H{
"Appointments": appts,
})
}
// Test OpenRouter via the Dashboard
func TestAIHandler(c *gin.Context) {
var body struct {
Prompt string `json:"prompt"`
}
if err := c.BindJSON(&body); err != nil {
c.JSON(400, gin.H{"response": "Invalid request, dummy."})
return
}
// Calling the service we wrote earlier
response, err := services.GetAIResponse(body.Prompt)
if err != nil {
c.JSON(500, gin.H{"response": "AI Error: " + err.Error()})
return
}
c.JSON(200, gin.H{"response": response})
}
// Manage/Delete Appointment
func DeleteAppointmentHandler(c *gin.Context) {
id := c.Param("id")
_, err := db.Conn.Exec("DELETE FROM appointments WHERE id = ?", id)
if err != nil {
c.Status(http.StatusInternalServerError)
return
}
c.Status(http.StatusOK)
}

25
handlers/webhook.go Normal file
View File

@@ -0,0 +1,25 @@
package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
)
// Meta verification
func VerifyWebhook(c *gin.Context) {
challenge := c.Query("hub.challenge")
token := c.Query("hub.verify_token")
if token == "YOUR_SECRET_TOKEN" {
c.String(http.StatusOK, challenge)
} else {
c.Status(http.StatusForbidden)
}
}
func HandleMessage(c *gin.Context) {
// You should bind your WhatsApp types here
// go services.Process(...)
c.Status(http.StatusOK)
}