mirror of
https://github.com/grassrootseconomics/farmstar-survey-backend.git
synced 2024-11-05 18:36:47 +01:00
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package worker
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/kamikazechaser/africastalking"
|
|
"github.com/riverqueue/river"
|
|
)
|
|
|
|
type (
|
|
SMSType string
|
|
SMSArgs struct {
|
|
SMS SMSType `json:"SMS"`
|
|
Phone string `json:"phone"`
|
|
Text string `json:"text"`
|
|
}
|
|
|
|
SMSWorker struct {
|
|
river.WorkerDefaults[SMSArgs]
|
|
|
|
AtClient *africastalking.AtClient
|
|
}
|
|
)
|
|
|
|
const (
|
|
FarmerRegistration SMSType = "You have registered as a farmer for the FarmStar rewards program. Follow the link https://t.ly/Vin2T to complete your registration and receive FSP."
|
|
DistributorRegistration SMSType = "You have registered as a distributor for the FarmStar rewards program. Follow the link https://t.ly/U7SbY to complete your registration."
|
|
FarmerComplete SMSType = "Thank you for completing the farmer survey, rewards will be sent soon. Use the link https://t.ly/2CxGt to record purchases of EverGrow Organic Fertilizer."
|
|
DistributorComplete SMSType = "Thank you for completing the distributor survey. Use the link https://t.ly/2CxGt to verify purchases of EverGrow Organic Fertilizer."
|
|
PurchaseComplete SMSType = "Thank you for completing the purchase survey."
|
|
)
|
|
|
|
func (SMSArgs) Kind() string {
|
|
return "sms"
|
|
}
|
|
|
|
func (w *SMSWorker) Work(ctx context.Context, job *river.Job[SMSArgs]) error {
|
|
var text string
|
|
|
|
if job.Args.Text != "" {
|
|
text = job.Args.Text
|
|
} else {
|
|
text = string(job.Args.SMS)
|
|
}
|
|
|
|
_, err := w.AtClient.SendBulkSMS(ctx, africastalking.BulkSMSInput{
|
|
To: []string{"+254" + job.Args.Phone[1:]},
|
|
From: "Sarafu",
|
|
Message: text,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|