modified: .env
modified: bot.db modified: db/db.go modified: handlers/webhook.go modified: services/whatsapp.go
This commit is contained in:
18
db/db.go
18
db/db.go
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user