lib/rules/new-lead.go

101 lines
2.4 KiB
Go
Raw Normal View History

2021-01-13 02:41:43 +00:00
package rules
import (
"time"
2021-01-13 05:09:16 +00:00
"code.tnxs.net/taxnexus/lib/api/crm/crm_models"
2021-01-13 02:41:43 +00:00
"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 {
// Address crm_models.Address
2021-01-19 17:45:58 +00:00
Company string
Description string
Email string
FirstName string
ID 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
APIKey string
SagaID string
SagaType 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 17:45:58 +00:00
obj := crm_models.Lead{
// Address: w.Address,
Company: w.Company,
Description: w.Description,
Email: w.Email,
FirstName: w.FirstName,
LastName: w.LastName,
MobilePhone: w.MobilePhone,
Name: w.Name,
OwnerID: w.OwnerID,
PartnerAccountID: w.PartnerAccountID,
Phone: w.Phone,
ProductID: w.ProductID,
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-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 20:11:18 +00:00
app.LeadChannelWrapper{
2021-01-19 17:45:58 +00:00
Obj: obj,
SagaID: w.SagaID,
SagaType: w.SagaType,
APIKey: w.APIKey,
2021-01-14 06:36:35 +00:00
}).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 20:11:18 +00:00
app.LeadChannelWrapper{
2021-01-19 17:45:58 +00:00
Obj: obj,
APIKey: w.APIKey,
2021-01-14 06:36:35 +00:00
}).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
return nil
}