lib/rules/new-lead.go

91 lines
2.0 KiB
Go
Raw Permalink Normal View History

2021-01-13 02:41:43 +00:00
package rules
import (
"time"
"code.tnxs.net/taxnexus/lib/app"
2021-01-14 06:36:35 +00:00
temporal_workflow "go.temporal.io/sdk/workflow"
2021-01-13 02:41:43 +00:00
)
2021-01-19 20:11:18 +00:00
// NewLeadWorkflowWrapper wraps a Lead with auth and saga info
type NewLeadWorkflowWrapper struct {
2021-01-20 01:17:06 +00:00
APIKey string
SagaID string
SagaType string
//
2021-01-19 20:11:18 +00:00
// Address crm_models.Address
2021-01-19 17:45:58 +00:00
Company string
Description string
Email string
FirstName string
LastName 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
2021-01-13 05:09:16 +00:00
}
2021-01-14 06:36:35 +00:00
// NewLeadWorkflow is a Temporal workflow
2021-01-19 20:11:18 +00:00
func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) error { //nolint:gocritic // don't care
2021-01-19 21:18:59 +00:00
obj := app.LeadActivityWrapper{
2021-01-19 17:45:58 +00:00
// Address: w.Address,
2021-01-19 21:18:59 +00:00
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,
2021-01-19 17:45:58 +00:00
}
2021-01-14 06:36:35 +00:00
ctx = temporal_workflow.
WithActivityOptions(
ctx,
temporal_workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
})
err := temporal_workflow.
ExecuteActivity(
ctx,
StoreLeadActivity,
2021-01-19 21:18:59 +00:00
obj,
).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
2021-01-14 06:36:35 +00:00
err = temporal_workflow.
ExecuteActivity(
ctx,
NotifyLeadActivity,
2021-01-19 21:18:59 +00:00
obj,
).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
return nil
}