lot of new functionalities
This commit is contained in:
41
core/application/sms.go
Normal file
41
core/application/sms.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *ApplicationHandler) SendSMS(ctx context.Context, beneficiaryID, message string) error {
|
||||
return h.GenerateSMS(beneficiaryID, message)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) GenerateSMS(recipientid string, message string) error {
|
||||
recipient, err := h.services.GetAccount(recipientid)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("user not found")
|
||||
return err
|
||||
}
|
||||
|
||||
pn, ok := recipient.Data["phone_number"]
|
||||
if !ok {
|
||||
log.Error().Msg("Beneficiary doesn't have a phone number")
|
||||
return errors.New("missing phone number")
|
||||
}
|
||||
phoneNumber, ok := pn.(string)
|
||||
if !ok {
|
||||
log.Error().Msg("phone number type error")
|
||||
return errors.New("phone number type error")
|
||||
}
|
||||
|
||||
sender := h.config.GetString("service_name")
|
||||
|
||||
err = h.services.SMS.Send(phoneNumber, message, sender)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("cannot send SMS")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user