modified: .env

modified:   bot.db
	modified:   db/db.go
	modified:   handlers/webhook.go
	modified:   services/whatsapp.go
This commit is contained in:
2026-03-01 08:40:30 -03:00
parent e47b12b0d9
commit 9ff021879f
5 changed files with 146 additions and 9 deletions

View File

@@ -53,3 +53,21 @@ func SaveAppointment(phone string, date string) error {
)
return err
}
// GetOrCreateChatByPhone finds a chat for this phone number or creates one
func GetOrCreateChatByPhone(phone string) int {
// 1. Check if we already have a chat for this phone
// (Note: You might want to add a 'phone' column to 'chats' table if you haven't yet.
// For now, I'll cheat and put the phone in the title if it's new)
var id int
err := Conn.QueryRow("SELECT id FROM chats WHERE title = ?", phone).Scan(&id)
if err == nil {
return id
}
// 2. If not found, create one
res, _ := Conn.Exec("INSERT INTO chats (title) VALUES (?)", phone)
newId, _ := res.LastInsertId()
return int(newId)
}