lib/rules/new-lead.go

51 lines
1.0 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 {
Lead crm_models.Lead
Principal app.User
SagaID string
SagaType string
}
// NewLeadWorkflow is a Temporal workflow
func NewLeadWorkflow(ctx temporal_workflow.Context, payload *NewLeadWrapper) error {
ctx = temporal_workflow.
WithActivityOptions(
ctx,
temporal_workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
})
err := temporal_workflow.
ExecuteActivity(
ctx,
StoreLeadActivity,
&app.LeadChannelWrapper{
Obj: payload.Lead,
Principal: payload.Principal,
}).Get(ctx, nil)
if err != nil {
return err
}
err = temporal_workflow.
ExecuteActivity(
ctx,
NotifyLeadActivity,
&app.LeadChannelWrapper{
Obj: payload.Lead,
Principal: payload.Principal,
}).Get(ctx, nil)
if err != nil {
return err
}
return nil
}