Lighter Objects

v0.1.26 v0.1.26
Vernon Keenan 2021-01-20 19:04:43 -08:00
parent 89f6c0a13a
commit a12863e619
4 changed files with 26 additions and 96 deletions

View File

@ -4,34 +4,6 @@ import (
"database/sql" "database/sql"
) )
// LeadActivityWrapper wraps the object with workflow params
type LeadActivityWrapper struct {
APIKey string
SagaID string
SagaType string
//
Address Address
Company string
Description string
Email string
FirstName string
LastName string
MobilePhone string
Name string
Phone string
RefererURL string
Status string
TenantID string
Title string
Type string
UTMCampaign string
UTMContent string
UTMMedium string
UTMSource string
UTMTerm string
Website string
}
// Lead is a first-class object type // Lead is a first-class object type
type Lead struct { type Lead struct {
ID string ID string

View File

@ -67,7 +67,7 @@ func StoreContactActivity(ctx workflow.Context, w app.ContactActivityWrapper) er
} }
// NotifyContactActivity sends an email to a new lead // NotifyContactActivity sends an email to a new lead
func NotifyContactActivity(ctx context.Context, w app.ContactActivityWrapper) error { //nolint:dupl,gocritic,lll // todo #2 need email templates func NotifyContactActivity(ctx context.Context, w app.ContactActivityWrapper) error { //nolint:gocritic,lll // todo #2 need email templates
sugar.Info("workflow.notifyContact: 📥") sugar.Info("workflow.notifyContact: 📥")
var buf bytes.Buffer var buf bytes.Buffer
const textBody = ` const textBody = `

View File

@ -9,39 +9,36 @@ import (
"code.tnxs.net/taxnexus/lib/api/crm/crm_models" "code.tnxs.net/taxnexus/lib/api/crm/crm_models"
"code.tnxs.net/taxnexus/lib/api/workflow/workflow_client/outgoing_email_message" "code.tnxs.net/taxnexus/lib/api/workflow/workflow_client/outgoing_email_message"
"code.tnxs.net/taxnexus/lib/api/workflow/workflow_models" "code.tnxs.net/taxnexus/lib/api/workflow/workflow_models"
"code.tnxs.net/taxnexus/lib/app"
httptransport "github.com/go-openapi/runtime/client" httptransport "github.com/go-openapi/runtime/client"
"go.temporal.io/sdk/workflow" "go.temporal.io/sdk/workflow"
) )
// NewLeadActivityWrapper wraps the object with workflow params
type NewLeadActivityWrapper struct {
APIKey string
SagaID string
SagaType string
//
Company string
Description string
Email string
FirstName string
LastName string
UTMSource string
}
// StoreLeadActivity posts a new lead object to datastore // StoreLeadActivity posts a new lead object to datastore
func StoreLeadActivity(ctx workflow.Context, w app.LeadActivityWrapper) error { //nolint:gocritic // don't care func StoreLeadActivity(ctx workflow.Context, w NewLeadActivityWrapper) error { //nolint:gocritic // don't care
obj := &crm_models.Lead{ obj := &crm_models.Lead{
Address: w.Address.MarshalToCrm(),
Company: w.Company, Company: w.Company,
Description: w.Description, Description: w.Description,
Email: w.Email, Email: w.Email,
FirstName: w.FirstName, FirstName: w.FirstName,
LastName: w.LastName, LastName: w.LastName,
MobilePhone: w.MobilePhone, Name: w.FirstName + " " + w.LastName,
Phone: w.Phone,
RefererURL: w.RefererURL,
Status: w.Status,
TenantID: w.TenantID,
Title: w.Title,
Type: w.Type,
UTMCampaign: w.UTMCampaign,
UTMContent: w.UTMContent,
UTMMedium: w.UTMMedium,
UTMSource: w.UTMSource, UTMSource: w.UTMSource,
UTMTerm: w.UTMTerm,
Website: w.Website,
Name: w.Name,
} }
postLeadParams := leads.NewPostLeadsParamsWithTimeout(postTimeout) postLeadParams := leads.NewPostLeadsParamsWithTimeout(postTimeout)
if obj.Name == "" {
obj.Name = obj.FirstName + " " + obj.LastName
}
postLeadParams.LeadRequest = &crm_models.LeadRequest{ postLeadParams.LeadRequest = &crm_models.LeadRequest{
Data: []*crm_models.Lead{obj}, Data: []*crm_models.Lead{obj},
} }
@ -59,7 +56,7 @@ func StoreLeadActivity(ctx workflow.Context, w app.LeadActivityWrapper) error {
} }
// NotifyLeadActivity sends an email to a new lead // NotifyLeadActivity sends an email to a new lead
func NotifyLeadActivity(ctx context.Context, w app.LeadActivityWrapper) error { //nolint:dupl,gocritic,lll // todo #2 need email templates func NotifyLeadActivity(ctx context.Context, w NewLeadActivityWrapper) error { //nolint:gocritic,lll // todo #2 need email templates
sugar.Info("workflow.notifyLead: 📥") sugar.Info("workflow.notifyLead: 📥")
var buf bytes.Buffer var buf bytes.Buffer
const textBody = ` const textBody = `
@ -83,7 +80,7 @@ Alert! New Lead Inquiry from Taxnexus.io website.
emailParams.OutgoingEmailMessageRequest = &workflow_models.OutgoingEmailMessageRequest{ emailParams.OutgoingEmailMessageRequest = &workflow_models.OutgoingEmailMessageRequest{
Data: []*workflow_models.OutgoingEmailMessage{ Data: []*workflow_models.OutgoingEmailMessage{
{ {
Subject: "New lead from " + w.Name, Subject: "New lead from " + w.FirstName + " " + w.LastName,
ValidatedFromAddress: "support@taxnexus.net", ValidatedFromAddress: "support@taxnexus.net",
ToAddress: "info@taxnexus.net", ToAddress: "info@taxnexus.net",
FromName: "Taxnexus Onboarding", FromName: "Taxnexus Onboarding",

View File

@ -3,7 +3,6 @@ package rules
import ( import (
"time" "time"
"code.tnxs.net/taxnexus/lib/app"
"go.temporal.io/sdk/temporal" "go.temporal.io/sdk/temporal"
temporal_workflow "go.temporal.io/sdk/workflow" temporal_workflow "go.temporal.io/sdk/workflow"
) )
@ -14,57 +13,19 @@ type NewLeadWorkflowWrapper struct {
SagaID string SagaID string
SagaType string SagaType string
// //
// Address crm_models.Address Company string
Company string Description string
Description string Email string
Email string FirstName string
FirstName string LastName string
LastName string UTMSource string
MobilePhone string
Name string
OwnerID string
PartnerAccountID string
Phone string
ProductID string
RefererURL string
Status string
TenantID string
Title string
Type string
UTMCampaign string
UTMContent string
UTMMedium string
UTMSource string
UTMTerm string
Website string
} }
// NewLeadWorkflow is a Temporal workflow // NewLeadWorkflow is a Temporal workflow
func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) error { //nolint:gocritic // don't care func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) error { //nolint:gocritic // don't care
sugar.Info("rules.NewLeadWorkflow: 📥") sugar.Info("rules.NewLeadWorkflow: 📥")
sugar.Debugf("rules.NewLeadWorkflow: wrapper: %v", w) sugar.Debugf("rules.NewLeadWorkflow: wrapper: %v", w)
transferDetails := app.LeadActivityWrapper{ transferDetails := NewLeadActivityWrapper(w)
// Address: w.Address,
Company: w.Company,
Description: w.Description,
Email: w.Email,
FirstName: w.FirstName,
LastName: w.LastName,
MobilePhone: w.MobilePhone,
Name: w.Name,
Phone: w.Phone,
RefererURL: w.RefererURL,
Status: w.Status,
TenantID: w.TenantID,
Title: w.Title,
Type: w.Type,
UTMCampaign: w.UTMCampaign,
UTMContent: w.UTMContent,
UTMMedium: w.UTMMedium,
UTMSource: w.UTMSource,
UTMTerm: w.UTMTerm,
Website: w.Website,
}
retryPolicy := &temporal.RetryPolicy{ retryPolicy := &temporal.RetryPolicy{
InitialInterval: time.Second, InitialInterval: time.Second,
MaximumInterval: time.Minute, MaximumInterval: time.Minute,