add method for direct notification sending
This commit is contained in:
@@ -550,6 +550,56 @@ func (s *notificationService) ReadStatus(notificationUUID string, isRead bool) e
|
||||
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
|
||||
func (s *notificationService) SendNotifications(notifications []viewmodel.Notification) ([]viewmodel.Notification, error) {
|
||||
if len(notifications) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user