45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package notifications
|
|
|
|
import (
|
|
messaging "github.com/tech/sendico/pkg/messaging/envelope"
|
|
gmessaging "github.com/tech/sendico/pkg/generated/gmessaging"
|
|
"github.com/tech/sendico/pkg/model"
|
|
nm "github.com/tech/sendico/pkg/model/notification"
|
|
"github.com/tech/sendico/pkg/mservice"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type NResultNotification struct {
|
|
messaging.Envelope
|
|
result *model.NotificationResult
|
|
}
|
|
|
|
func (nrn *NResultNotification) Serialize() ([]byte, error) {
|
|
msg := gmessaging.NotificationSentEvent{
|
|
UserID: nrn.result.UserID,
|
|
Channel: nrn.result.Channel,
|
|
Locale: nrn.result.Locale,
|
|
TemplateID: nrn.result.TemplateID,
|
|
Status: &gmessaging.OperationResult{
|
|
IsSuccessful: nrn.result.Result.IsSuccessful,
|
|
ErrorDescription: nrn.result.Result.Error,
|
|
},
|
|
}
|
|
data, err := proto.Marshal(&msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return nrn.Envelope.Wrap(data)
|
|
}
|
|
|
|
func NewNRNotification() model.NotificationEvent {
|
|
return model.NewNotification(mservice.Notifications, nm.NASent)
|
|
}
|
|
|
|
func NewNResultNotification(sender string, result *model.NotificationResult) messaging.Envelope {
|
|
return &NResultNotification{
|
|
Envelope: messaging.CreateEnvelope(sender, NewNRNotification()),
|
|
result: result,
|
|
}
|
|
}
|