forked from ebhomengo/niki
1
0
Fork 0

feat(niki): implement send notification base service

This commit is contained in:
Ruhollah 2024-07-27 18:28:37 +03:30
parent 86a962b0c9
commit 7cfd9b31e0
5 changed files with 55 additions and 0 deletions

View File

@ -4,9 +4,11 @@ import "github.com/kavenegar/kavenegar-go"
type Config struct { type Config struct {
APIKey string `koanf:"api_key"` APIKey string `koanf:"api_key"`
Sender string `koanf:"sender"`
OtpTemplateNewUser string `koanf:"otp_template_new_user"` OtpTemplateNewUser string `koanf:"otp_template_new_user"`
OtpTemplateRegisteredUser string `koanf:"otp_template_registered_user"` OtpTemplateRegisteredUser string `koanf:"otp_template_registered_user"`
} }
type Adapter struct { type Adapter struct {
config Config config Config
api *kavenegar.Kavenegar api *kavenegar.Kavenegar

View File

@ -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}
}

View File

@ -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))
}
}
}

View File

@ -29,6 +29,7 @@ benefactor_service:
kavenegar_sms_provider: kavenegar_sms_provider:
api_key: insert_your_api_key api_key: insert_your_api_key
sender: ""
otp_template_new_user: ebhomeverify otp_template_new_user: ebhomeverify
otp_template_registered_user: ebhomeverify otp_template_registered_user: ebhomeverify

View File

@ -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,
}
}