new settlement flow
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
messaging "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
nm "github.com/tech/sendico/pkg/model/notification"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
)
|
||||
|
||||
type TelegramReactionNotification struct {
|
||||
messaging.Envelope
|
||||
payload model.TelegramReactionRequest
|
||||
}
|
||||
|
||||
func (trn *TelegramReactionNotification) Serialize() ([]byte, error) {
|
||||
data, err := json.Marshal(trn.payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return trn.Envelope.Wrap(data)
|
||||
}
|
||||
|
||||
func telegramReactionEvent() model.NotificationEvent {
|
||||
return model.NewNotification(mservice.Notifications, nm.NATelegramReaction)
|
||||
}
|
||||
|
||||
func NewTelegramReactionEnvelope(sender string, request *model.TelegramReactionRequest) messaging.Envelope {
|
||||
var payload model.TelegramReactionRequest
|
||||
if request != nil {
|
||||
payload = *request
|
||||
}
|
||||
return &TelegramReactionNotification{
|
||||
Envelope: messaging.CreateEnvelope(sender, telegramReactionEvent()),
|
||||
payload: payload,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
me "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
np "github.com/tech/sendico/pkg/messaging/notifications/processor"
|
||||
ch "github.com/tech/sendico/pkg/messaging/notifications/telegram/handler"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type TelegramReactionProcessor struct {
|
||||
logger mlogger.Logger
|
||||
handler ch.TelegramReactionHandler
|
||||
event model.NotificationEvent
|
||||
}
|
||||
|
||||
func (trp *TelegramReactionProcessor) Process(ctx context.Context, envelope me.Envelope) error {
|
||||
var msg model.TelegramReactionRequest
|
||||
if err := json.Unmarshal(envelope.GetData(), &msg); err != nil {
|
||||
trp.logger.Warn("Failed to decode telegram reaction envelope", zap.Error(err), zap.String("topic", trp.event.ToString()))
|
||||
return err
|
||||
}
|
||||
if trp.handler == nil {
|
||||
trp.logger.Warn("Telegram reaction handler is not configured", zap.String("topic", trp.event.ToString()))
|
||||
return nil
|
||||
}
|
||||
return trp.handler(ctx, &msg)
|
||||
}
|
||||
|
||||
func (trp *TelegramReactionProcessor) GetSubject() model.NotificationEvent {
|
||||
return trp.event
|
||||
}
|
||||
|
||||
func NewTelegramReactionProcessor(logger mlogger.Logger, handler ch.TelegramReactionHandler) np.EnvelopeProcessor {
|
||||
if logger != nil {
|
||||
logger = logger.Named("telegram_reaction_processor")
|
||||
}
|
||||
return &TelegramReactionProcessor{
|
||||
logger: logger,
|
||||
handler: handler,
|
||||
event: telegramReactionEvent(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
)
|
||||
|
||||
type TelegramReactionHandler = func(context.Context, *model.TelegramReactionRequest) error
|
||||
18
api/pkg/messaging/notifications/telegram/telegram.go
Normal file
18
api/pkg/messaging/notifications/telegram/telegram.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
messaging "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
tinternal "github.com/tech/sendico/pkg/messaging/internal/notifications/telegram"
|
||||
np "github.com/tech/sendico/pkg/messaging/notifications/processor"
|
||||
ch "github.com/tech/sendico/pkg/messaging/notifications/telegram/handler"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
)
|
||||
|
||||
func TelegramReaction(sender string, request *model.TelegramReactionRequest) messaging.Envelope {
|
||||
return tinternal.NewTelegramReactionEnvelope(sender, request)
|
||||
}
|
||||
|
||||
func NewTelegramReactionProcessor(logger mlogger.Logger, handler ch.TelegramReactionHandler) np.EnvelopeProcessor {
|
||||
return tinternal.NewTelegramReactionProcessor(logger, handler)
|
||||
}
|
||||
Reference in New Issue
Block a user