package rules import ( "bytes" "context" "html/template" "code.tnxs.net/taxnexus/lib/api/crm/crm_client/leads" "code.tnxs.net/taxnexus/lib/api/crm/crm_models" "code.tnxs.net/taxnexus/lib/api/workflow/workflow_client/outgoing_email_message" "code.tnxs.net/taxnexus/lib/api/workflow/workflow_models" "code.tnxs.net/taxnexus/lib/app" "go.temporal.io/sdk/workflow" ) // StoreLeadActivity posts a new lead object to datastore func StoreLeadActivity(ctx workflow.Context, w app.LeadChannelWrapper) error { //nolint:gocritic // what we want postLeadParams := leads.NewPostLeadsParamsWithTimeout(postTimeout) if w.Obj.Name == "" { w.Obj.Name = w.Obj.FirstName + " " + w.Obj.LastName } postLeadParams.LeadRequest = &crm_models.LeadRequest{ Data: []*crm_models.Lead{&w.Obj}, } _, err := crmClient.Leads.PostLeads(postLeadParams, w.Principal.Auth) if err != nil { return err } sugar.Info("crm.storeLead: 👍 📤") return nil } // NotifyLeadActivity sends an email to a new lead func NotifyLeadActivity(ctx context.Context, w *app.LeadChannelWrapper) error { sugar.Info("workflow.notifyLead: 📥") var buf bytes.Buffer const textBody = ` Alert! New Lead Inquiry from Taxnexus.io website. Taxnexus ID: {{.ID}} First Name: {{.FirstName}} Last Name: {{.LastName}} Email: {{.Email}} Message: {{.Description}} -- end -- ` t := template.Must(template.New("textBody").Parse(textBody)) err := t.Execute(&buf, w) if err != nil { return err } emailParams := outgoing_email_message.NewPostOutgoingEmailMessagesParamsWithTimeout(postTimeout) emailParams.OutgoingEmailMessageRequest = &workflow_models.OutgoingEmailMessageRequest{ Data: []*workflow_models.OutgoingEmailMessage{ { Subject: "New lead from " + w.Obj.Name, ValidatedFromAddress: "support@taxnexus.net", ToAddress: "info@taxnexus.net", FromName: "Taxnexus Onboarding", Text: buf.String(), HTML: "
" + buf.String() + "
", }, }, } _, err = workflowClient.OutgoingEmailMessage.PostOutgoingEmailMessages(emailParams, w.Principal.Auth) if err != nil { return err } sugar.Info("workflow.notifyLead: 👍 📤") return nil }