fixed notifications dispatch
Some checks failed
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/billing_fees 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/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
ci/woodpecker/push/bump_version Pipeline failed
Some checks failed
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/billing_fees 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/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
ci/woodpecker/push/bump_version Pipeline failed
This commit is contained in:
@@ -80,13 +80,8 @@ func CreateAPI(a api.API) (*NotificationAPI, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.Register().Consumer(snotifications.NewDemoRequestProcessor(p.logger, p.onDemoRequest)); err != nil {
|
if err := a.Register().Consumer(snotifications.NewSiteRequestProcessor(p.logger, p.onDemoRequest, p.onContactRequest)); err != nil {
|
||||||
p.logger.Error("Failed to register demo request handler", zap.Error(err))
|
p.logger.Error("Failed to register site request handler", zap.Error(err))
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := a.Register().Consumer(snotifications.NewContactRequestProcessor(p.logger, p.onContactRequest)); err != nil {
|
|
||||||
p.logger.Error("Failed to register contact request handler", zap.Error(err))
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type client struct {
|
|||||||
botToken string
|
botToken string
|
||||||
chatID string
|
chatID string
|
||||||
threadID *int64
|
threadID *int64
|
||||||
parseMode string
|
parseMode parseMode
|
||||||
}
|
}
|
||||||
|
|
||||||
type sendMessagePayload struct {
|
type sendMessagePayload struct {
|
||||||
@@ -80,9 +80,9 @@ func NewClient(logger mlogger.Logger, cfg *notconfig.TelegramConfig) (Client, er
|
|||||||
if apiURL == "" {
|
if apiURL == "" {
|
||||||
apiURL = defaultAPIURL
|
apiURL = defaultAPIURL
|
||||||
}
|
}
|
||||||
parseMode := strings.TrimSpace(cfg.ParseMode)
|
mode := normalizeParseMode(cfg.ParseMode)
|
||||||
if parseMode == "" {
|
if mode == parseModeUnset {
|
||||||
parseMode = "Markdown"
|
mode = parseModeMarkdown
|
||||||
}
|
}
|
||||||
|
|
||||||
return &client{
|
return &client{
|
||||||
@@ -94,7 +94,7 @@ func NewClient(logger mlogger.Logger, cfg *notconfig.TelegramConfig) (Client, er
|
|||||||
botToken: token,
|
botToken: token,
|
||||||
chatID: chatID,
|
chatID: chatID,
|
||||||
threadID: threadID,
|
threadID: threadID,
|
||||||
parseMode: parseMode,
|
parseMode: mode,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ func (c *client) sendForm(ctx context.Context, template messageTemplate) error {
|
|||||||
payload := sendMessagePayload{
|
payload := sendMessagePayload{
|
||||||
ChatID: c.chatID,
|
ChatID: c.chatID,
|
||||||
Text: message,
|
Text: message,
|
||||||
ParseMode: c.parseMode,
|
ParseMode: c.parseMode.String(),
|
||||||
ThreadID: c.threadID,
|
ThreadID: c.threadID,
|
||||||
DisablePreview: true,
|
DisablePreview: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import "github.com/tech/sendico/pkg/model"
|
|||||||
|
|
||||||
func newContactRequestTemplate(request *model.ContactRequest) messageTemplate {
|
func newContactRequestTemplate(request *model.ContactRequest) messageTemplate {
|
||||||
return messageTemplate{
|
return messageTemplate{
|
||||||
title: "New contact request received",
|
title: "New site request received",
|
||||||
|
emphasize: []string{"site request"},
|
||||||
fields: []messageField{
|
fields: []messageField{
|
||||||
{label: "Name", value: request.Name},
|
{label: "Name", value: request.Name},
|
||||||
{label: "Email", value: request.Email},
|
{label: "Email", value: request.Email},
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ func newDemoRequestTemplate(request *model.DemoRequest) messageTemplate {
|
|||||||
fields = append(fields, messageField{label: "Comment", value: request.Comment})
|
fields = append(fields, messageField{label: "Comment", value: request.Comment})
|
||||||
}
|
}
|
||||||
return messageTemplate{
|
return messageTemplate{
|
||||||
title: "New demo request received",
|
title: "New demo request received",
|
||||||
fields: fields,
|
fields: fields,
|
||||||
|
emphasize: []string{"demo request"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,50 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type parseMode string
|
||||||
|
|
||||||
|
const (
|
||||||
|
parseModeUnset parseMode = ""
|
||||||
|
parseModeMarkdown parseMode = "markdown"
|
||||||
|
parseModeMarkdownV2 parseMode = "markdownV2"
|
||||||
|
parseModeHTML parseMode = "HTML"
|
||||||
|
)
|
||||||
|
|
||||||
|
func normalizeParseMode(value string) parseMode {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||||
|
case "markdown":
|
||||||
|
return parseModeMarkdown
|
||||||
|
case "markdownv2":
|
||||||
|
return parseModeMarkdownV2
|
||||||
|
case "html":
|
||||||
|
return parseModeHTML
|
||||||
|
default:
|
||||||
|
return parseModeUnset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pm parseMode) String() string {
|
||||||
|
return string(pm)
|
||||||
|
}
|
||||||
|
|
||||||
type messageField struct {
|
type messageField struct {
|
||||||
label string
|
label string
|
||||||
value string
|
value string
|
||||||
}
|
}
|
||||||
|
|
||||||
type messageTemplate struct {
|
type messageTemplate struct {
|
||||||
title string
|
title string
|
||||||
fields []messageField
|
fields []messageField
|
||||||
|
emphasize []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mt messageTemplate) Format(parseMode string) string {
|
func (mt messageTemplate) Format(mode parseMode) string {
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
builder.WriteString(mt.title)
|
builder.WriteString(formatTitle(mode, mt.title, mt.emphasize))
|
||||||
builder.WriteString("\n")
|
builder.WriteString("\n")
|
||||||
builder.WriteString("-----------------------------\n")
|
builder.WriteString("-----------------------------\n")
|
||||||
|
|
||||||
formatter := selectValueFormatter(parseMode)
|
formatter := selectValueFormatter(mode)
|
||||||
for _, field := range mt.fields {
|
for _, field := range mt.fields {
|
||||||
appendMessageField(&builder, field.label, field.value, formatter)
|
appendMessageField(&builder, field.label, field.value, formatter)
|
||||||
}
|
}
|
||||||
@@ -31,6 +58,53 @@ func (mt messageTemplate) Format(parseMode string) string {
|
|||||||
|
|
||||||
type valueFormatter func(string) string
|
type valueFormatter func(string) string
|
||||||
|
|
||||||
|
func formatTitle(mode parseMode, title string, emphasize []string) string {
|
||||||
|
switch mode {
|
||||||
|
case parseModeMarkdown:
|
||||||
|
return highlightMarkdown(title, emphasize, escapeMarkdown)
|
||||||
|
case parseModeMarkdownV2:
|
||||||
|
return highlightMarkdown(title, emphasize, escapeMarkdownV2)
|
||||||
|
case parseModeHTML:
|
||||||
|
return highlightHTML(title, emphasize)
|
||||||
|
default:
|
||||||
|
return title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func highlightMarkdown(title string, emphasize []string, esc func(string) string) string {
|
||||||
|
if len(emphasize) == 0 {
|
||||||
|
return title
|
||||||
|
}
|
||||||
|
result := title
|
||||||
|
for _, word := range emphasize {
|
||||||
|
word = strings.TrimSpace(word)
|
||||||
|
if word == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
escaped := esc(word)
|
||||||
|
replacement := fmt.Sprintf("*%s*", escaped)
|
||||||
|
result = strings.ReplaceAll(result, word, replacement)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func highlightHTML(title string, emphasize []string) string {
|
||||||
|
if len(emphasize) == 0 {
|
||||||
|
return html.EscapeString(title)
|
||||||
|
}
|
||||||
|
result := html.EscapeString(title)
|
||||||
|
for _, word := range emphasize {
|
||||||
|
word = strings.TrimSpace(word)
|
||||||
|
if word == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
escaped := html.EscapeString(word)
|
||||||
|
replacement := fmt.Sprintf("<b>%s</b>", escaped)
|
||||||
|
result = strings.ReplaceAll(result, escaped, replacement)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func appendMessageField(builder *strings.Builder, label, value string, formatter valueFormatter) {
|
func appendMessageField(builder *strings.Builder, label, value string, formatter valueFormatter) {
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
@@ -41,17 +115,17 @@ func appendMessageField(builder *strings.Builder, label, value string, formatter
|
|||||||
fmt.Fprintf(builder, "• %s: %s\n", label, value)
|
fmt.Fprintf(builder, "• %s: %s\n", label, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectValueFormatter(parseMode string) valueFormatter {
|
func selectValueFormatter(mode parseMode) valueFormatter {
|
||||||
switch strings.ToLower(parseMode) {
|
switch mode {
|
||||||
case "markdown":
|
case parseModeMarkdown:
|
||||||
return func(value string) string {
|
return func(value string) string {
|
||||||
return fmt.Sprintf("*%s*", escapeMarkdown(value))
|
return fmt.Sprintf("*%s*", escapeMarkdown(value))
|
||||||
}
|
}
|
||||||
case "markdownv2":
|
case parseModeMarkdownV2:
|
||||||
return func(value string) string {
|
return func(value string) string {
|
||||||
return fmt.Sprintf("*%s*", escapeMarkdownV2(value))
|
return fmt.Sprintf("*%s*", escapeMarkdownV2(value))
|
||||||
}
|
}
|
||||||
case "html":
|
case parseModeHTML:
|
||||||
return func(value string) string {
|
return func(value string) string {
|
||||||
return fmt.Sprintf("<b>%s</b>", html.EscapeString(value))
|
return fmt.Sprintf("<b>%s</b>", html.EscapeString(value))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,72 +10,84 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DemoRequestNotification struct {
|
type SiteRequestNotification struct {
|
||||||
messaging.Envelope
|
messaging.Envelope
|
||||||
request *model.DemoRequest
|
requestType gmessaging.SiteRequestEvent_RequestType
|
||||||
|
demoRequest *model.DemoRequest
|
||||||
|
contactRequest *model.ContactRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
func (drn *DemoRequestNotification) Serialize() ([]byte, error) {
|
func (srn *SiteRequestNotification) Serialize() ([]byte, error) {
|
||||||
if drn.request == nil {
|
msg := gmessaging.SiteRequestEvent{
|
||||||
return nil, merrors.InvalidArgument("demo request payload is empty", "request")
|
Type: srn.requestType,
|
||||||
}
|
}
|
||||||
msg := gmessaging.DemoRequestEvent{
|
|
||||||
Name: drn.request.Name,
|
switch srn.requestType {
|
||||||
OrganizationName: drn.request.OrganizationName,
|
case gmessaging.SiteRequestEvent_REQUEST_TYPE_DEMO:
|
||||||
Phone: drn.request.Phone,
|
if srn.demoRequest == nil {
|
||||||
WorkEmail: drn.request.WorkEmail,
|
return nil, merrors.InvalidArgument("demo request payload is empty", "request")
|
||||||
PayoutVolume: drn.request.PayoutVolume,
|
}
|
||||||
Comment: drn.request.Comment,
|
msg.Payload = &gmessaging.SiteRequestEvent_Demo{
|
||||||
|
Demo: &gmessaging.SiteDemoRequest{
|
||||||
|
Name: srn.demoRequest.Name,
|
||||||
|
OrganizationName: srn.demoRequest.OrganizationName,
|
||||||
|
Phone: srn.demoRequest.Phone,
|
||||||
|
WorkEmail: srn.demoRequest.WorkEmail,
|
||||||
|
PayoutVolume: srn.demoRequest.PayoutVolume,
|
||||||
|
Comment: srn.demoRequest.Comment,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
case gmessaging.SiteRequestEvent_REQUEST_TYPE_CONTACT:
|
||||||
|
if srn.contactRequest == nil {
|
||||||
|
return nil, merrors.InvalidArgument("contact request payload is empty", "request")
|
||||||
|
}
|
||||||
|
msg.Payload = &gmessaging.SiteRequestEvent_Contact{
|
||||||
|
Contact: &gmessaging.SiteContactRequest{
|
||||||
|
Name: srn.contactRequest.Name,
|
||||||
|
Email: srn.contactRequest.Email,
|
||||||
|
Phone: srn.contactRequest.Phone,
|
||||||
|
Company: srn.contactRequest.Company,
|
||||||
|
Topic: srn.contactRequest.Topic,
|
||||||
|
Message: srn.contactRequest.Message,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, merrors.InvalidArgument("unsupported site request type", "type")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := proto.Marshal(&msg)
|
data, err := proto.Marshal(&msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return drn.Envelope.Wrap(data)
|
return srn.Envelope.Wrap(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSiteRequestEvent() model.NotificationEvent {
|
||||||
|
return model.NewNotification(mservice.Site, nm.NACreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDemoRequestEvent() model.NotificationEvent {
|
func NewDemoRequestEvent() model.NotificationEvent {
|
||||||
return model.NewNotification(mservice.Site, nm.NACreated)
|
return newSiteRequestEvent()
|
||||||
}
|
|
||||||
|
|
||||||
func NewDemoRequestEnvelope(sender string, request *model.DemoRequest) messaging.Envelope {
|
|
||||||
return &DemoRequestNotification{
|
|
||||||
Envelope: messaging.CreateEnvelope(sender, NewDemoRequestEvent()),
|
|
||||||
request: request,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContactRequestNotification struct {
|
|
||||||
messaging.Envelope
|
|
||||||
request *model.ContactRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
func (crn *ContactRequestNotification) Serialize() ([]byte, error) {
|
|
||||||
if crn.request == nil {
|
|
||||||
return nil, merrors.InvalidArgument("contact request payload is empty", "request")
|
|
||||||
}
|
|
||||||
msg := gmessaging.ContactRequestEvent{
|
|
||||||
Name: crn.request.Name,
|
|
||||||
Email: crn.request.Email,
|
|
||||||
Phone: crn.request.Phone,
|
|
||||||
Company: crn.request.Company,
|
|
||||||
Topic: crn.request.Topic,
|
|
||||||
Message: crn.request.Message,
|
|
||||||
}
|
|
||||||
data, err := proto.Marshal(&msg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return crn.Envelope.Wrap(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContactRequestEvent() model.NotificationEvent {
|
func NewContactRequestEvent() model.NotificationEvent {
|
||||||
return model.NewNotification(mservice.Site, nm.NACreated)
|
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,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContactRequestEnvelope(sender string, request *model.ContactRequest) messaging.Envelope {
|
func NewContactRequestEnvelope(sender string, request *model.ContactRequest) messaging.Envelope {
|
||||||
return &ContactRequestNotification{
|
return &SiteRequestNotification{
|
||||||
Envelope: messaging.CreateEnvelope(sender, NewContactRequestEvent()),
|
Envelope: messaging.CreateEnvelope(sender, newSiteRequestEvent()),
|
||||||
request: request,
|
requestType: gmessaging.SiteRequestEvent_REQUEST_TYPE_CONTACT,
|
||||||
|
contactRequest: request,
|
||||||
|
demoRequest: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,72 +14,74 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DemoRequestProcessor struct {
|
type SiteRequestProcessor struct {
|
||||||
logger mlogger.Logger
|
logger mlogger.Logger
|
||||||
handler handler.DemoRequestHandler
|
demoHandler handler.DemoRequestHandler
|
||||||
event model.NotificationEvent
|
contactHandler handler.ContactRequestHandler
|
||||||
|
event model.NotificationEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (drp *DemoRequestProcessor) Process(ctx context.Context, envelope me.Envelope) error {
|
func (srp *SiteRequestProcessor) Process(ctx context.Context, envelope me.Envelope) error {
|
||||||
var msg gmessaging.DemoRequestEvent
|
var msg gmessaging.SiteRequestEvent
|
||||||
if err := proto.Unmarshal(envelope.GetData(), &msg); err != nil {
|
if err := proto.Unmarshal(envelope.GetData(), &msg); err != nil {
|
||||||
drp.logger.Warn("Failed to decode demo request envelope", zap.Error(err), zap.String("topic", drp.event.ToString()))
|
srp.logger.Warn("Failed to decode site request envelope", zap.Error(err), zap.String("topic", srp.event.ToString()))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
request := &model.DemoRequest{
|
|
||||||
Name: msg.GetName(),
|
|
||||||
OrganizationName: msg.GetOrganizationName(),
|
|
||||||
Phone: msg.GetPhone(),
|
|
||||||
WorkEmail: msg.GetWorkEmail(),
|
|
||||||
PayoutVolume: msg.GetPayoutVolume(),
|
|
||||||
Comment: msg.GetComment(),
|
|
||||||
}
|
|
||||||
return drp.handler(ctx, request)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (drp *DemoRequestProcessor) GetSubject() model.NotificationEvent {
|
switch msg.GetType() {
|
||||||
return drp.event
|
case gmessaging.SiteRequestEvent_REQUEST_TYPE_DEMO:
|
||||||
}
|
if srp.demoHandler == nil {
|
||||||
|
srp.logger.Warn("Demo request handler is not configured")
|
||||||
func NewDemoRequestProcessor(logger mlogger.Logger, handler handler.DemoRequestHandler) np.EnvelopeProcessor {
|
return nil
|
||||||
return &DemoRequestProcessor{
|
}
|
||||||
logger: logger.Named("demo_request_processor"),
|
demo := msg.GetDemo()
|
||||||
handler: handler,
|
if demo == nil {
|
||||||
event: internalsite.NewDemoRequestEvent(),
|
srp.logger.Warn("Demo request payload is empty")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
request := &model.DemoRequest{
|
||||||
|
Name: demo.GetName(),
|
||||||
|
OrganizationName: demo.GetOrganizationName(),
|
||||||
|
Phone: demo.GetPhone(),
|
||||||
|
WorkEmail: demo.GetWorkEmail(),
|
||||||
|
PayoutVolume: demo.GetPayoutVolume(),
|
||||||
|
Comment: demo.GetComment(),
|
||||||
|
}
|
||||||
|
return srp.demoHandler(ctx, request)
|
||||||
|
case gmessaging.SiteRequestEvent_REQUEST_TYPE_CONTACT:
|
||||||
|
if srp.contactHandler == nil {
|
||||||
|
srp.logger.Warn("Contact request handler is not configured")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
contact := msg.GetContact()
|
||||||
|
if contact == nil {
|
||||||
|
srp.logger.Warn("Contact request payload is empty")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
request := &model.ContactRequest{
|
||||||
|
Name: contact.GetName(),
|
||||||
|
Email: contact.GetEmail(),
|
||||||
|
Phone: contact.GetPhone(),
|
||||||
|
Company: contact.GetCompany(),
|
||||||
|
Topic: contact.GetTopic(),
|
||||||
|
Message: contact.GetMessage(),
|
||||||
|
}
|
||||||
|
return srp.contactHandler(ctx, request)
|
||||||
|
default:
|
||||||
|
srp.logger.Warn("Received site request with unsupported type", zap.Any("type", msg.GetType()))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContactRequestProcessor struct {
|
func (srp *SiteRequestProcessor) GetSubject() model.NotificationEvent {
|
||||||
logger mlogger.Logger
|
return srp.event
|
||||||
handler handler.ContactRequestHandler
|
|
||||||
event model.NotificationEvent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (crp *ContactRequestProcessor) Process(ctx context.Context, envelope me.Envelope) error {
|
func NewSiteRequestProcessor(logger mlogger.Logger, demo handler.DemoRequestHandler, contact handler.ContactRequestHandler) np.EnvelopeProcessor {
|
||||||
var msg gmessaging.ContactRequestEvent
|
return &SiteRequestProcessor{
|
||||||
if err := proto.Unmarshal(envelope.GetData(), &msg); err != nil {
|
logger: logger.Named("site_request_processor"),
|
||||||
crp.logger.Warn("Failed to decode contact request envelope", zap.Error(err), zap.String("topic", crp.event.ToString()))
|
demoHandler: demo,
|
||||||
return err
|
contactHandler: contact,
|
||||||
}
|
event: internalsite.NewDemoRequestEvent(),
|
||||||
request := &model.ContactRequest{
|
|
||||||
Name: msg.GetName(),
|
|
||||||
Email: msg.GetEmail(),
|
|
||||||
Phone: msg.GetPhone(),
|
|
||||||
Company: msg.GetCompany(),
|
|
||||||
Topic: msg.GetTopic(),
|
|
||||||
Message: msg.GetMessage(),
|
|
||||||
}
|
|
||||||
return crp.handler(ctx, request)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (crp *ContactRequestProcessor) GetSubject() model.NotificationEvent {
|
|
||||||
return crp.event
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewContactRequestProcessor(logger mlogger.Logger, handler handler.ContactRequestHandler) np.EnvelopeProcessor {
|
|
||||||
return &ContactRequestProcessor{
|
|
||||||
logger: logger.Named("contact_request_processor"),
|
|
||||||
handler: handler,
|
|
||||||
event: internalsite.NewContactRequestEvent(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,12 @@ func FromString(s string) (*NotificationEventImp, error) {
|
|||||||
|
|
||||||
func StringToNotificationAction(s string) (nm.NotificationAction, error) {
|
func StringToNotificationAction(s string) (nm.NotificationAction, error) {
|
||||||
switch nm.NotificationAction(s) {
|
switch nm.NotificationAction(s) {
|
||||||
case nm.NACreated, nm.NAPending, nm.NAUpdated, nm.NADeleted, nm.NAAssigned, nm.NAPasswordReset:
|
case nm.NACreated,
|
||||||
|
nm.NAPending,
|
||||||
|
nm.NAUpdated,
|
||||||
|
nm.NADeleted,
|
||||||
|
nm.NAAssigned,
|
||||||
|
nm.NAPasswordReset:
|
||||||
return nm.NotificationAction(s), nil
|
return nm.NotificationAction(s), nil
|
||||||
default:
|
default:
|
||||||
return "", merrors.DataConflict("invalid Notification action: " + s)
|
return "", merrors.DataConflict("invalid Notification action: " + s)
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option go_package = "github.com/tech/sendico/pkg/generated/gmessaging";
|
|
||||||
|
|
||||||
message ContactRequestEvent {
|
|
||||||
string Name = 1;
|
|
||||||
string Email = 2;
|
|
||||||
string Phone = 3;
|
|
||||||
string Company = 4;
|
|
||||||
string Topic = 5;
|
|
||||||
string Message = 6;
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option go_package = "github.com/tech/sendico/pkg/generated/gmessaging";
|
|
||||||
|
|
||||||
message DemoRequestEvent {
|
|
||||||
string Name = 1;
|
|
||||||
string OrganizationName = 2;
|
|
||||||
string Phone = 3;
|
|
||||||
string WorkEmail = 4;
|
|
||||||
string PayoutVolume = 5;
|
|
||||||
string Comment = 6;
|
|
||||||
}
|
|
||||||
36
api/proto/site_request.proto
Normal file
36
api/proto/site_request.proto
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option go_package = "github.com/tech/sendico/pkg/generated/gmessaging";
|
||||||
|
|
||||||
|
message SiteRequestEvent {
|
||||||
|
enum RequestType {
|
||||||
|
REQUEST_TYPE_UNSPECIFIED = 0;
|
||||||
|
REQUEST_TYPE_DEMO = 1;
|
||||||
|
REQUEST_TYPE_CONTACT = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestType type = 1;
|
||||||
|
|
||||||
|
oneof payload {
|
||||||
|
SiteDemoRequest demo = 2;
|
||||||
|
SiteContactRequest contact = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message SiteDemoRequest {
|
||||||
|
string name = 1;
|
||||||
|
string organization_name = 2;
|
||||||
|
string phone = 3;
|
||||||
|
string work_email = 4;
|
||||||
|
string payout_volume = 5;
|
||||||
|
string comment = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SiteContactRequest {
|
||||||
|
string name = 1;
|
||||||
|
string email = 2;
|
||||||
|
string phone = 3;
|
||||||
|
string company = 4;
|
||||||
|
string topic = 5;
|
||||||
|
string message = 6;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user