forked from ebhomengo/niki
feat(niki): implement send notification base service
This commit is contained in:
parent
86a962b0c9
commit
7cfd9b31e0
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
}
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue