lib/rules/new-lead.go

101 lines
2.4 KiB
Go

package rules
import (
"time"
"code.tnxs.net/taxnexus/lib/api/crm/crm_models"
"code.tnxs.net/taxnexus/lib/app"
temporal_workflow "go.temporal.io/sdk/workflow"
)
// NewLeadWrapper wraps a Lead and a user identifier (app.User)
type NewLeadWrapper struct {
// Address *crm_models.Address
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
}
// NewLeadWorkflow is a Temporal workflow
func NewLeadWorkflow(ctx temporal_workflow.Context, w *NewLeadWrapper) error {
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,
}
ctx = temporal_workflow.
WithActivityOptions(
ctx,
temporal_workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
})
err := temporal_workflow.
ExecuteActivity(
ctx,
StoreLeadActivity,
&app.LeadChannelWrapper{
Obj: obj,
SagaID: w.SagaID,
SagaType: w.SagaType,
APIKey: w.APIKey,
}).Get(ctx, nil)
if err != nil {
return err
}
err = temporal_workflow.
ExecuteActivity(
ctx,
NotifyLeadActivity,
&app.LeadChannelWrapper{
Obj: obj,
APIKey: w.APIKey,
}).Get(ctx, nil)
if err != nil {
return err
}
return nil
}