lib/rules/new-lead.go

51 lines
1.0 KiB
Go
Raw Permalink 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-13 05:09:16 +00:00
// NewLeadWrapper wraps a Lead and a user identifier (app.User)
type NewLeadWrapper struct {
2021-01-19 02:48:56 +00:00
Lead crm_models.Lead
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
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{
2021-01-19 01:50:45 +00:00
Obj: payload.Lead,
2021-01-19 02:48:56 +00:00
APIKey: payload.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,
&app.LeadChannelWrapper{
2021-01-19 01:50:45 +00:00
Obj: payload.Lead,
2021-01-19 02:48:56 +00:00
APIKey: payload.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
}