+ call request
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
This commit is contained in:
@@ -15,6 +15,7 @@ type SiteRequestNotification struct {
|
||||
requestType gmessaging.SiteRequestEvent_RequestType
|
||||
demoRequest *model.DemoRequest
|
||||
contactRequest *model.ContactRequest
|
||||
callRequest *model.CallRequest
|
||||
}
|
||||
|
||||
func (srn *SiteRequestNotification) Serialize() ([]byte, error) {
|
||||
@@ -51,6 +52,20 @@ func (srn *SiteRequestNotification) Serialize() ([]byte, error) {
|
||||
Message: srn.contactRequest.Message,
|
||||
},
|
||||
}
|
||||
case gmessaging.SiteRequestEvent_REQUEST_TYPE_CALL:
|
||||
if srn.callRequest == nil {
|
||||
return nil, merrors.InvalidArgument("call request payload is empty", "request")
|
||||
}
|
||||
msg.Payload = &gmessaging.SiteRequestEvent_Call{
|
||||
Call: &gmessaging.SiteCallRequest{
|
||||
Name: srn.callRequest.Name,
|
||||
Phone: srn.callRequest.Phone,
|
||||
Email: srn.callRequest.Email,
|
||||
Company: srn.callRequest.Company,
|
||||
PreferredTime: srn.callRequest.PreferredTime,
|
||||
Message: srn.callRequest.Message,
|
||||
},
|
||||
}
|
||||
default:
|
||||
return nil, merrors.InvalidArgument("unsupported site request type", "type")
|
||||
}
|
||||
@@ -74,12 +89,17 @@ func NewContactRequestEvent() model.NotificationEvent {
|
||||
return newSiteRequestEvent()
|
||||
}
|
||||
|
||||
func NewCallRequestEvent() model.NotificationEvent {
|
||||
return newSiteRequestEvent()
|
||||
}
|
||||
|
||||
func NewDemoRequestEnvelope(sender string, request *model.DemoRequest) messaging.Envelope {
|
||||
return &SiteRequestNotification{
|
||||
Envelope: messaging.CreateEnvelope(sender, newSiteRequestEvent()),
|
||||
requestType: gmessaging.SiteRequestEvent_REQUEST_TYPE_DEMO,
|
||||
demoRequest: request,
|
||||
contactRequest: nil,
|
||||
callRequest: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,5 +109,16 @@ func NewContactRequestEnvelope(sender string, request *model.ContactRequest) mes
|
||||
requestType: gmessaging.SiteRequestEvent_REQUEST_TYPE_CONTACT,
|
||||
contactRequest: request,
|
||||
demoRequest: nil,
|
||||
callRequest: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func NewCallRequestEnvelope(sender string, request *model.CallRequest) messaging.Envelope {
|
||||
return &SiteRequestNotification{
|
||||
Envelope: messaging.CreateEnvelope(sender, newSiteRequestEvent()),
|
||||
requestType: gmessaging.SiteRequestEvent_REQUEST_TYPE_CALL,
|
||||
callRequest: request,
|
||||
demoRequest: nil,
|
||||
contactRequest: nil,
|
||||
}
|
||||
}
|
||||
|
||||
11
api/pkg/messaging/notifications/site/call_request.go
Normal file
11
api/pkg/messaging/notifications/site/call_request.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
messaging "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
internalsite "github.com/tech/sendico/pkg/messaging/internal/notifications/site"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
)
|
||||
|
||||
func CallRequest(sender string, request *model.CallRequest) messaging.Envelope {
|
||||
return internalsite.NewCallRequestEnvelope(sender, request)
|
||||
}
|
||||
@@ -8,3 +8,4 @@ import (
|
||||
|
||||
type DemoRequestHandler = func(context.Context, *model.DemoRequest) error
|
||||
type ContactRequestHandler = func(context.Context, *model.ContactRequest) error
|
||||
type CallRequestHandler = func(context.Context, *model.CallRequest) error
|
||||
|
||||
@@ -18,6 +18,7 @@ type SiteRequestProcessor struct {
|
||||
logger mlogger.Logger
|
||||
demoHandler handler.DemoRequestHandler
|
||||
contactHandler handler.ContactRequestHandler
|
||||
callHandler handler.CallRequestHandler
|
||||
event model.NotificationEvent
|
||||
}
|
||||
|
||||
@@ -67,6 +68,25 @@ func (srp *SiteRequestProcessor) Process(ctx context.Context, envelope me.Envelo
|
||||
Message: contact.GetMessage(),
|
||||
}
|
||||
return srp.contactHandler(ctx, request)
|
||||
case gmessaging.SiteRequestEvent_REQUEST_TYPE_CALL:
|
||||
if srp.callHandler == nil {
|
||||
srp.logger.Warn("Call request handler is not configured")
|
||||
return nil
|
||||
}
|
||||
call := msg.GetCall()
|
||||
if call == nil {
|
||||
srp.logger.Warn("Call request payload is empty")
|
||||
return nil
|
||||
}
|
||||
request := &model.CallRequest{
|
||||
Name: call.GetName(),
|
||||
Phone: call.GetPhone(),
|
||||
Email: call.GetEmail(),
|
||||
Company: call.GetCompany(),
|
||||
PreferredTime: call.GetPreferredTime(),
|
||||
Message: call.GetMessage(),
|
||||
}
|
||||
return srp.callHandler(ctx, request)
|
||||
default:
|
||||
srp.logger.Warn("Received site request with unsupported type", zap.Any("type", msg.GetType()))
|
||||
return nil
|
||||
@@ -77,11 +97,12 @@ func (srp *SiteRequestProcessor) GetSubject() model.NotificationEvent {
|
||||
return srp.event
|
||||
}
|
||||
|
||||
func NewSiteRequestProcessor(logger mlogger.Logger, demo handler.DemoRequestHandler, contact handler.ContactRequestHandler) np.EnvelopeProcessor {
|
||||
func NewSiteRequestProcessor(logger mlogger.Logger, demo handler.DemoRequestHandler, contact handler.ContactRequestHandler, call handler.CallRequestHandler) np.EnvelopeProcessor {
|
||||
return &SiteRequestProcessor{
|
||||
logger: logger.Named("site_request_processor"),
|
||||
demoHandler: demo,
|
||||
contactHandler: contact,
|
||||
callHandler: call,
|
||||
event: internalsite.NewDemoRequestEvent(),
|
||||
}
|
||||
}
|
||||
|
||||
41
api/pkg/model/callrequest.go
Normal file
41
api/pkg/model/callrequest.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
)
|
||||
|
||||
// CallRequest represents a request to schedule a call from the marketing site.
|
||||
type CallRequest struct {
|
||||
Name string `json:"name"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Company string `json:"company"`
|
||||
PreferredTime string `json:"preferredTime"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// Normalize trims whitespace from all string fields.
|
||||
func (cr *CallRequest) Normalize() {
|
||||
if cr == nil {
|
||||
return
|
||||
}
|
||||
cr.Name = strings.TrimSpace(cr.Name)
|
||||
cr.Phone = strings.TrimSpace(cr.Phone)
|
||||
cr.Email = strings.TrimSpace(cr.Email)
|
||||
cr.Company = strings.TrimSpace(cr.Company)
|
||||
cr.PreferredTime = strings.TrimSpace(cr.PreferredTime)
|
||||
cr.Message = strings.TrimSpace(cr.Message)
|
||||
}
|
||||
|
||||
// Validate ensures required call request fields are present.
|
||||
func (cr *CallRequest) Validate() error {
|
||||
if cr == nil {
|
||||
return merrors.InvalidArgument("request payload is empty", "request")
|
||||
}
|
||||
if cr.Phone == "" {
|
||||
return merrors.InvalidArgument("phone must not be empty", "request.phone")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user