Compare commits
2 Commits
merge-28-5
...
send-email
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab055d8a61 | ||
|
|
fc3029c6c3 |
@@ -550,6 +550,56 @@ func (s *notificationService) ReadStatus(notificationUUID string, isRead bool) e
|
|||||||
return s.svc.Notification.ReadStatus(notificationUUID, isRead)
|
return s.svc.Notification.ReadStatus(notificationUUID, isRead)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SendNotificationWithoutWritingToDatabase will send notification directly
|
||||||
|
func (s *notificationService) SendNotificationWithoutWritingToDatabase(n viewmodel.Notification) (viewmodel.Notification, error) {
|
||||||
|
switch n.Type {
|
||||||
|
case NOtificationTypeSMS:
|
||||||
|
if n.From == "" {
|
||||||
|
if err := s.notification.Twilio.SendSMS(s.cfg.Twilio.Sender, n.To, n.Message); err != nil {
|
||||||
|
fmt.Println("Error to send SMS: ", err.Error())
|
||||||
|
return viewmodel.Notification{}, err
|
||||||
|
}
|
||||||
|
if err := s.notification.Twilio.SendSMS(s.cfg.Twilio.Sender, "+17083038497", n.Message); err != nil {
|
||||||
|
fmt.Println("Error to send SMS: ", err.Error())
|
||||||
|
return viewmodel.Notification{}, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := s.notification.Twilio.SendSMS(n.From, n.To, n.Message); err != nil {
|
||||||
|
fmt.Println("Error to send SMS: ", err.Error())
|
||||||
|
return viewmodel.Notification{}, err
|
||||||
|
}
|
||||||
|
if err := s.notification.Twilio.SendSMS(n.From, "+17083038497", n.Message); err != nil {
|
||||||
|
fmt.Println("Error to send SMS: ", err.Error())
|
||||||
|
return viewmodel.Notification{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case NotificationTypeEmail:
|
||||||
|
m := gomail.NewMessage()
|
||||||
|
m.SetHeader("From", s.cfg.Email.Sender)
|
||||||
|
m.SetHeader("To", n.To)
|
||||||
|
m.SetHeader("Subject", n.Subject)
|
||||||
|
m.SetBody("text/plain", n.Message)
|
||||||
|
d := gomail.NewDialer(s.cfg.Email.Server, s.cfg.Email.Port, s.cfg.Email.User, s.cfg.Email.Pass)
|
||||||
|
|
||||||
|
if err := d.DialAndSend(m); err != nil {
|
||||||
|
fmt.Println("Error to send Email: ", err.Error())
|
||||||
|
return viewmodel.Notification{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m = gomail.NewMessage()
|
||||||
|
m.SetHeader("From", s.cfg.Email.Sender)
|
||||||
|
m.SetHeader("To", "nemt@brighterdevelopment.com")
|
||||||
|
m.SetHeader("Subject", n.Subject)
|
||||||
|
m.SetBody("text/plain", n.Message)
|
||||||
|
|
||||||
|
if err := d.DialAndSend(m); err != nil {
|
||||||
|
fmt.Println("Error to send Email: ", err.Error())
|
||||||
|
return viewmodel.Notification{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
// SendNotifications will send all the notifications to email or SMS
|
// SendNotifications will send all the notifications to email or SMS
|
||||||
func (s *notificationService) SendNotifications(notifications []viewmodel.Notification) ([]viewmodel.Notification, error) {
|
func (s *notificationService) SendNotifications(notifications []viewmodel.Notification) ([]viewmodel.Notification, error) {
|
||||||
if len(notifications) > 0 {
|
if len(notifications) > 0 {
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ import (
|
|||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
notificationEmailSubject = "Registration sucessful"
|
||||||
|
notificationEmailBody = "You have registered as a Visit Reporter for CHM NEMT.\nLogin: https://portal.bcbsinstitute.com\nReset PW: https://portal.bcbsinstitute.com/forgot"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
instance *controller
|
instance *controller
|
||||||
once sync.Once
|
once sync.Once
|
||||||
@@ -115,5 +120,19 @@ func (c *controller) handle(ctx echo.Context) error {
|
|||||||
return routeutils.HandleAPIError(ctx, err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Send email notification to Authorized user
|
||||||
|
notification := viewmodel.Notification{
|
||||||
|
Type: "email",
|
||||||
|
From: c.cfg.Email.Sender,
|
||||||
|
To: *user.Email,
|
||||||
|
Subject: notificationEmailSubject,
|
||||||
|
Message: notificationEmailBody,
|
||||||
|
}
|
||||||
|
|
||||||
|
notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification)
|
||||||
|
if err != nil {
|
||||||
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
return routeutils.ResponseAPIOK(ctx, user)
|
return routeutils.ResponseAPIOK(ctx, user)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user