Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(leadiq, smartlead): change field to optional #892

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ repos:
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: local
hooks:
- id: generate-docs
name: Generate Docs
entry: bash -c 'make gen-component-doc'
language: system
files: ^pkg/component/.*\.(json|mdx)$
24 changes: 12 additions & 12 deletions pkg/component/application/leadiq/v0/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ type FindProspectsInput struct {
// Company is the company information to find prospects for.
type Company struct {
// Name is the name of the company.
Names []string `instill:"names,omitempty"`
Names []*string `instill:"names"`
// RevenueSize is the revenue size of the company.
RevenueSize RevenueSize `instill:"revenue-size,omitempty"`
RevenueSize *RevenueSize `instill:"revenue-size"`
// Countries is the list of countries the company operates in.
Countries []string `instill:"countries,omitempty"`
Countries []*string `instill:"countries"`
// States is the list of states the company operates in.
States []string `instill:"states,omitempty"`
States []*string `instill:"states"`
// Cities is the list of cities the company operates in.
Cities []string `instill:"cities,omitempty"`
Cities []*string `instill:"cities"`
// Industries is the list of industries the company are.
Industries []string `instill:"industries,omitempty"`
Industries []*string `instill:"industries"`
// Descriptions is the list of descriptions of the company.
Descriptions []string `instill:"descriptions,omitempty"`
Descriptions []*string `instill:"descriptions"`
// Technologies is the list of technologies the company uses.
Technologies []string `instill:"technologies,omitempty"`
Technologies []*string `instill:"technologies"`
}

// RevenueSize is the revenue size of the company.
Expand All @@ -44,17 +44,17 @@ type RevenueSize struct {
// Max is the maximum revenue size.
Max int `instill:"max"`
// Description is the description of the revenue size.
Description string `instill:"description,omitempty"`
Description *string `instill:"description"`
}

// FilterBy is the filter to apply to the prospects.
type FilterBy struct {
// JobTitle is the job title to filter by.
JobTitle string `instill:"job-title,omitempty"`
JobTitle *string `instill:"job-title"`
// Seniorities is the seniorities to filter by.
Seniorities []string `instill:"seniorities,omitempty"`
Seniorities []*string `instill:"seniorities"`
// Function is the function to filter by.
Function string `instill:"function,omitempty"`
Function *string `instill:"function"`

jobTitleRegex *regexp.Regexp
functionRegex *regexp.Regexp
Expand Down
28 changes: 14 additions & 14 deletions pkg/component/application/leadiq/v0/task_find_prospects.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (e *execution) executeFindProspects(ctx context.Context, job *base.Job) err
}

flatAdvancedSearchIn := buildFlatAdvancedSearchInput(inputStruct)

flatAdvancedSearchResp := flatAdvancedSearchResp{}
if err := e.sendRequest(ctx, client, logger, flatAdvancedSearchQuery, flatAdvancedSearchIn, &flatAdvancedSearchResp); err != nil {
msg := fmt.Sprintf("LeadIQ API result error: %v", err)
Expand Down Expand Up @@ -76,7 +77,7 @@ func (e *execution) executeFindProspects(ctx context.Context, job *base.Job) err
RevenueSize: RevenueSize{
Min: person.Company.RevenueRange.Start,
Max: person.Company.RevenueRange.End,
Description: person.Company.RevenueRange.Description,
Description: &person.Company.RevenueRange.Description,
},
}
prospects = append(prospects, prospect)
Expand Down Expand Up @@ -187,16 +188,15 @@ func (e *execution) sendRequest(ctx context.Context, client *graphql.Client, log
func buildFlatAdvancedSearchInput(in FindProspectsInput) map[string]interface{} {
companyFilter := make(map[string]interface{})

// Now, we don't support optional fields in the Console/API input.
// So, we set the default value with the " " string.
// If it is the default value, it means the users don't provide any information.
// So, we won't add the field to the companyFilter.
filterNonBlank := func(slice []string) []string {
result := []string{}
filterNonBlank := func(slice []*string) []*string {
result := []*string{}
for _, s := range slice {
trimmed := strings.TrimSpace(s)
if s == nil {
continue
}
trimmed := strings.TrimSpace(*s)
if trimmed != "" {
result = append(result, trimmed)
result = append(result, &trimmed)
}
}
return result
Expand Down Expand Up @@ -262,14 +262,14 @@ func buildSearchPeopleInput(prospect Prospect) map[string]interface{} {

func (f *FilterBy) compile() error {
var err error
if f.JobTitle != "" {
f.jobTitleRegex, err = regexp.Compile(f.JobTitle)
if f.JobTitle != nil {
f.jobTitleRegex, err = regexp.Compile(*f.JobTitle)
if err != nil {
return fmt.Errorf("compiling job title filter: %w", err)
}
}
if f.Function != "" {
f.functionRegex, err = regexp.Compile(f.Function)
if f.Function != nil {
f.functionRegex, err = regexp.Compile(*f.Function)
if err != nil {
return fmt.Errorf("compiling seniority filter: %w", err)
}
Expand All @@ -284,7 +284,7 @@ func (f *FilterBy) beforeAPICallingMatch(person person) bool {
if len(f.Seniorities) > 0 {
found := false
for _, seniority := range f.Seniorities {
if seniority == person.Seniority {
if *seniority == person.Seniority {
found = true
break
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/component/application/smartlead/v0/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Setup a campaign. You can update campaign settings to this campaign. For Smartle
| Task ID (required) | `task` | string | `TASK_SETUP_CAMPAIGN` |
| Campaign Name (required) | `campaign-name` | string | Name of the campaign. |
| Timezone (required) | `timezone` | string | Timezone of the campaign. Please choose the value in [List of Timezones](https://help.smartlead.ai/Timezones-20fcff9ddbb5441790c7c8e5ce0e9233). |
| Days of the Week | `days-of-the-week` | array[number] | Days of the week when the campaign will run. A number value ranging from 0 to 6; i.e [0,1,2,3,4,5,6]. 0 is Sunday, 1 is Monday, and so on. |
| Days of the Week (required) | `days-of-the-week` | array[number] | Days of the week when the campaign will run. A number value ranging from 0 to 6; i.e [0,1,2,3,4,5,6]. 0 is Sunday, 1 is Monday, and so on. |
| Start Hour (required) | `start-hour` | string | Start hour of the campaign. Time to start the campaign in 24-hour format (HH:MM). |
| End Hour (required) | `end-hour` | string | End hour of the campaign. Time to end the campaign in 24-hour format (HH:MM). |
| Minimum Time Between Emails (required) | `min-time-btw-emails` | number | Minimum time between emails in minutes. The minimum value is 3 minutes. |
Expand Down Expand Up @@ -154,8 +154,8 @@ A Smartlead sequence is a series of automated emails sent to potential customers
| Field | Field ID | Type | Note |
| :--- | :--- | :--- | :--- |
| Email Body | `email-body` | string | Body of the email. If you want to set the variable according to different leads, you can use {{variable_name}}. It will be replaced by the actual value from the lead. |
| Sequence Number | `seq-number` | number | Sequence number means the order of the sequence. |
| Sequence Delay Days | `sequence-delay-days` | number | Number of days to wait before sending the next email. |
| Sequence Number | `seq-number` | number | Sequence number means the order of the sequence. If you don't specify this, it will be automatically assigned by the order of the sequences. |
| Sequence Delay Days | `sequence-delay-days` | number | Number of days to wait before sending the next email. If you don't specify this, the default value is 1 day. |
| Subject | `subject` | string | Subject of the email. If you want to set the variable according to different leads, you can use {{variable_name}}. It will be replaced by the actual value from the lead. |
</div>
</details>
Expand Down
8 changes: 5 additions & 3 deletions pkg/component/application/smartlead/v0/config/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"required": [
"campaign-name",
"timezone",
"days-of-the-week",
"start-hour",
"end-hour",
"min-time-btw-emails",
Expand Down Expand Up @@ -260,7 +261,7 @@
"properties": {
"seq-number": {
"title": "Sequence Number",
"description": "Sequence number means the order of the sequence.",
"description": "Sequence number means the order of the sequence. If you don't specify this, it will be automatically assigned by the order of the sequences.",
"type": "number",
"instillFormat": "number",
"instillAcceptFormats": [
Expand All @@ -270,13 +271,14 @@
},
"sequence-delay-days": {
"title": "Sequence Delay Days",
"description": "Number of days to wait before sending the next email.",
"description": "Number of days to wait before sending the next email. If you don't specify this, the default value is 1 day.",
"type": "number",
"instillFormat": "number",
"instillAcceptFormats": [
"number"
],
"instillUIOrder": 1
"instillUIOrder": 1,
"default": 1
},
"subject": {
"title": "Subject",
Expand Down
24 changes: 11 additions & 13 deletions pkg/component/application/smartlead/v0/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type setupCampaignInput struct {
MaxNewLeadsPerDay int `instill:"max-new-leads-per-day"`
ScheduleStartTime string `instill:"schedule-start-time"`
TrackSettings []string `instill:"track-settings"`
StopLeadSettings string `instill:"stop-lead-settings"`
StopLeadSettings *string `instill:"stop-lead-settings"`
SendAsPlainText bool `instill:"send-as-plain-text"`
FollowUpPercentage int `instill:"follow-up-percentage"`
FollowUpPercentage *int `instill:"follow-up-percentage"`
AddUnsubscribeTag bool `instill:"add-unsubscribe-tag"`
IgnoreSsMailboxSendingLimit bool `instill:"ignore-ss-mailbox-sending-limit"`
}
Expand All @@ -37,11 +37,11 @@ type saveSequencesInput struct {
}

type sequence struct {
SeqID string `instill:"seq-id"`
SeqNumber int `instill:"seq-number"`
SequenceDelayDays int `instill:"sequence-delay-days"`
Subject string `instill:"subject"`
EmailBody string `instill:"email-body"`
SeqID *string `instill:"seq-id"`
SeqNumber *int `instill:"seq-number"`
SequenceDelayDays *int `instill:"sequence-delay-days"`
Subject string `instill:"subject"`
EmailBody string `instill:"email-body"`
}

type saveSequencesOutput struct {
Expand All @@ -64,10 +64,10 @@ type addLeadsInput struct {

type lead struct {
Email string `instill:"email"`
FirstName string `instill:"first-name"`
LastName string `instill:"last-name"`
Company string `instill:"company"`
Location string `instill:"location"`
FirstName *string `instill:"first-name"`
LastName *string `instill:"last-name"`
Company *string `instill:"company"`
Location *string `instill:"location"`
CustomFields []customField `instill:"custom-fields"`
}

Expand Down Expand Up @@ -111,8 +111,6 @@ type updateCampaignStatusOutput struct {

type getCampaignMetricInput struct {
CampaignName string `instill:"campaign-name"`
StartDate string `instill:"start-date"`
EndDate string `instill:"end-date"`
}

type getCampaignMetricOutput struct {
Expand Down
8 changes: 4 additions & 4 deletions pkg/component/application/smartlead/v0/task_add_leads.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ type addLeadsReq struct {
}

type leadReq struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
FirstName *string `json:"first_name,omitempty"`
LastName *string `json:"last_name,omitempty"`
Email string `json:"email"`
CompanyName string `json:"company_name"`
Location string `json:"location"`
CompanyName *string `json:"company_name,omitempty"`
Location *string `json:"location,omitempty"`
CustomFields map[string]string `json:"custom_fields"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ func (e *execution) getSequences(ctx context.Context, job *base.Job) error {

var sequences []sequence
for _, s := range sequenceResp {
seqID := fmt.Sprintf("%d", s.ID)
sequences = append(sequences, sequence{
SeqID: fmt.Sprintf("%d", s.ID),
SeqNumber: s.SeqNumber,
SeqID: &seqID,
SeqNumber: &s.SeqNumber,
Subject: s.Subject,
EmailBody: s.EmailBody,
SequenceDelayDays: s.SeqDelayDetails.DelayInDays,
SequenceDelayDays: &s.SeqDelayDetails.DelayInDays,
})
}

Expand Down
30 changes: 22 additions & 8 deletions pkg/component/application/smartlead/v0/task_save_sequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,28 @@ func (e *execution) saveSequences(ctx context.Context, job *base.Job) error {

func buildSaveSequenceReq(input saveSequencesInput) saveSequencesReq {
var sequences []sequenceReq
for _, seq := range input.Sequences {
for i, seq := range input.Sequences {
var seqDelayDetails sequenceDelayDetails
if seq.SequenceDelayDays != nil {
seqDelayDetails = sequenceDelayDetails{
DelayInDays: *seq.SequenceDelayDays,
}
} else {
seqDelayDetails = sequenceDelayDetails{
DelayInDays: 1,
}
}
var seqNumber int
if seq.SeqNumber != nil {
seqNumber = *seq.SeqNumber
} else {
seqNumber = i + 1
}
sequences = append(sequences, sequenceReq{
SeqNumber: seq.SeqNumber,
SeqDelayDetails: sequenceDelayDetails{
DelayInDays: seq.SequenceDelayDays,
},
Subject: seq.Subject,
EmailBody: seq.EmailBody,
SeqNumber: &seqNumber,
SeqDelayDetails: seqDelayDetails,
Subject: seq.Subject,
EmailBody: seq.EmailBody,
})
}
return saveSequencesReq{
Expand All @@ -99,7 +113,7 @@ type saveSequencesReq struct {
}

type sequenceReq struct {
SeqNumber int `json:"seq_number"`
SeqNumber *int `json:"seq_number,omitempty"`
SeqDelayDetails sequenceDelayDetails `json:"seq_delay_details"`
Subject string `json:"subject"`
EmailBody string `json:"email_body"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func buildGeneralSettingReq(input setupCampaignInput) setupGeneralCampaignReq {

type setupGeneralCampaignReq struct {
TrackSettings []string `json:"track_settings,omitempty"`
StopLeadSettings string `json:"stop_lead_settings,omitempty"`
StopLeadSettings *string `json:"stop_lead_settings,omitempty"`
SendAsPlainText bool `json:"send_as_plain_text,omitempty"`
FollowUpPercentage int `json:"follow_up_percentage,omitempty"`
FollowUpPercentage *int `json:"follow_up_percentage,omitempty"`
AddUnsubscribeTag bool `json:"add_unsubscribe_tag,omitempty"`
IgnoreSsMailboxSendingLimit bool `json:"ignore_ss_mailbox_sending_limit,omitempty"`
}
Loading
Loading