package hooks import ( "fmt" "github.com/grassrootseconomics/farmstar-survey-backend/internal/worker" "github.com/pocketbase/pocketbase/core" ) func (r *HooksContainer) bootstrapRegistrationHook() { r.pb.OnModelAfterCreate("users").Add(func(e *core.ModelEvent) error { userRecord, err := r.pb.Dao().FindRecordById("users", e.Model.GetId()) if err != nil { return err } participantType := userRecord.GetString("participant_type") participantPhone := userRecord.GetString("phone") tgMsg := fmt.Sprintf( "New %s signup:\n\nname: %s\nphone: %s", participantType, userRecord.GetString("name"), participantPhone, ) if err := r.worker.QueueTgTask(tgMsg); err != nil { return err } if participantType == "farmer" { if err := r.worker.QueueSMSTask(participantPhone, worker.FarmerRegistration, ""); err != nil { return err } } else { if err := r.worker.QueueSMSTask(participantPhone, worker.DistributorRegistration, ""); err != nil { return err } } return nil }) }