diff --git a/adapter/sms_provider/kavenegar/adapter.go b/adapter/sms_provider/kavenegar/adapter.go index 0554996..e6c44cf 100644 --- a/adapter/sms_provider/kavenegar/adapter.go +++ b/adapter/sms_provider/kavenegar/adapter.go @@ -4,9 +4,11 @@ import "github.com/kavenegar/kavenegar-go" type Config struct { APIKey string `koanf:"api_key"` + Sender string `koanf:"sender"` OtpTemplateNewUser string `koanf:"otp_template_new_user"` OtpTemplateRegisteredUser string `koanf:"otp_template_registered_user"` } + type Adapter struct { config Config api *kavenegar.Kavenegar diff --git a/adapter/sms_provider/kavenegar/notification/adapter.go b/adapter/sms_provider/kavenegar/notification/adapter.go new file mode 100644 index 0000000..1d98f2b --- /dev/null +++ b/adapter/sms_provider/kavenegar/notification/adapter.go @@ -0,0 +1,11 @@ +package kavenegarnotification + +import "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar" + +type Adapter struct { + adapter *kavenegar.Adapter +} + +func New(adapter *kavenegar.Adapter) Adapter { + return Adapter{adapter: adapter} +} diff --git a/adapter/sms_provider/kavenegar/notification/send.go b/adapter/sms_provider/kavenegar/notification/send.go new file mode 100644 index 0000000..e36c091 --- /dev/null +++ b/adapter/sms_provider/kavenegar/notification/send.go @@ -0,0 +1,26 @@ +package kavenegarnotification + +import ( + "fmt" + + "github.com/kavenegar/kavenegar-go" +) + +func (a *Adapter) Send(phoneNumber, message string) { + const op = "kavenegarnotification.SendNotification" + var params *kavenegar.MessageSendParam + if _, err := a.adapter.Client().Message.Send(a.adapter.Config().Sender, []string{phoneNumber}, message, params); err != nil { + //nolint + switch err := err.(type) { + case *kavenegar.APIError: + // log error + fmt.Println(fmt.Errorf("error(%s):%w", op, err)) + case *kavenegar.HTTPError: + // log error + fmt.Println(fmt.Errorf("error(%s):%w", op, err)) + default: + // log error + fmt.Println(fmt.Errorf("error(%s):%w", op, err)) + } + } +} diff --git a/config.yml b/config.yml index e5ce107..1efe382 100644 --- a/config.yml +++ b/config.yml @@ -29,6 +29,7 @@ benefactor_service: kavenegar_sms_provider: api_key: insert_your_api_key + sender: "" otp_template_new_user: ebhomeverify otp_template_registered_user: ebhomeverify diff --git a/service/notification/service.go b/service/notification/service.go new file mode 100644 index 0000000..ca70d94 --- /dev/null +++ b/service/notification/service.go @@ -0,0 +1,15 @@ +package notification + +type SmsAdapter interface { + Send(phoneNumber string, message string) +} + +type Service struct { + smsAdapter SmsAdapter +} + +func New(smsAdapter SmsAdapter) Service { + return Service{ + smsAdapter: smsAdapter, + } +}