2021-01-13 02:41:43 +00:00
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"html/template"
|
|
|
|
|
|
|
|
"code.tnxs.net/taxnexus/lib/api/crm/crm_client/contacts"
|
|
|
|
"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"
|
2021-01-19 01:50:45 +00:00
|
|
|
httptransport "github.com/go-openapi/runtime/client"
|
2021-01-13 02:41:43 +00:00
|
|
|
"go.temporal.io/sdk/workflow"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StoreContactActivity posts a new contact object to datastore
|
2021-01-19 20:23:02 +00:00
|
|
|
func StoreContactActivity(ctx workflow.Context, w app.ContactActivityWrapper) error { //nolint:gocritic // what we want
|
2021-01-19 21:18:59 +00:00
|
|
|
obj := &crm_models.Contact{
|
|
|
|
AccountID: w.AccountID,
|
|
|
|
AssistantName: w.AssistantName,
|
|
|
|
AssistantPhone: w.AssistantPhone,
|
|
|
|
BirthDate: w.BirthDate,
|
|
|
|
Department: w.Department,
|
|
|
|
Description: w.Description,
|
|
|
|
Email: w.Email,
|
|
|
|
FirstName: w.FirstName,
|
|
|
|
HomePhone: w.HomePhone,
|
|
|
|
LastName: w.LastName,
|
|
|
|
LeadSource: w.LeadSource,
|
|
|
|
Level: w.Level,
|
|
|
|
LinkedIn: w.LinkedIn,
|
|
|
|
MobilePhone: w.MobilePhone,
|
|
|
|
Name: w.Name,
|
|
|
|
OtherPhone: w.OtherPhone,
|
|
|
|
OwnerID: w.OwnerID,
|
|
|
|
PersonalEmail: w.PersonalEmail,
|
|
|
|
Phone: w.Phone,
|
|
|
|
PhotoURL: w.PhotoURL,
|
|
|
|
Ref: w.Ref,
|
|
|
|
ReportsToID: w.ReportsToID,
|
|
|
|
Salutation: w.Salutation,
|
|
|
|
Status: w.Status,
|
|
|
|
Title: w.Title,
|
|
|
|
Type: w.Type,
|
|
|
|
MailingAddress: w.MailingAddress.MarshalToCrm(),
|
|
|
|
OtherAddress: w.OtherAddress.MarshalToCrm(),
|
|
|
|
}
|
|
|
|
if obj.Name == "" {
|
|
|
|
obj.Name = obj.FirstName + " " + obj.LastName
|
2021-01-13 02:41:43 +00:00
|
|
|
}
|
2021-01-19 21:18:59 +00:00
|
|
|
postContactParams := contacts.NewPostContactsParamsWithTimeout(postTimeout)
|
2021-01-13 02:41:43 +00:00
|
|
|
postContactParams.ContactsRequest = &crm_models.ContactRequest{
|
2021-01-19 21:18:59 +00:00
|
|
|
Data: []*crm_models.Contact{obj},
|
2021-01-13 02:41:43 +00:00
|
|
|
}
|
2021-01-19 01:50:45 +00:00
|
|
|
_, err := crmClient.Contacts.PostContacts(postContactParams,
|
|
|
|
httptransport.APIKeyAuth(
|
|
|
|
"X-API-Key",
|
|
|
|
"header",
|
|
|
|
w.APIKey,
|
|
|
|
))
|
2021-01-13 02:41:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sugar.Info("crm.storeContact: 👍 📤")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NotifyContactActivity sends an email to a new lead
|
2021-01-19 20:23:02 +00:00
|
|
|
func NotifyContactActivity(ctx context.Context, w *app.ContactActivityWrapper) error {
|
2021-01-13 02:41:43 +00:00
|
|
|
sugar.Info("workflow.notifyContact: 📥")
|
|
|
|
var buf bytes.Buffer
|
|
|
|
const textBody = `
|
|
|
|
|
|
|
|
Alert! New Contact 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{
|
|
|
|
{
|
2021-01-19 21:18:59 +00:00
|
|
|
Subject: "New lead from " + w.Name,
|
2021-01-13 02:41:43 +00:00
|
|
|
ValidatedFromAddress: "support@taxnexus.net",
|
|
|
|
ToAddress: "info@taxnexus.net",
|
|
|
|
FromName: "Taxnexus Onboarding",
|
|
|
|
Text: buf.String(),
|
|
|
|
HTML: "<pre>" + buf.String() + "</pre>",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-01-19 01:50:45 +00:00
|
|
|
_, err = workflowClient.OutgoingEmailMessage.PostOutgoingEmailMessages(emailParams,
|
|
|
|
httptransport.APIKeyAuth(
|
|
|
|
"X-API-Key",
|
|
|
|
"header",
|
|
|
|
w.APIKey,
|
|
|
|
))
|
2021-01-13 02:41:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sugar.Info("workflow.notifyContact: 👍 📤")
|
|
|
|
return nil
|
|
|
|
}
|