Skip to content

Commit 1d0888d

Browse files
committed
feat: complete slack resp
1 parent 78c1732 commit 1d0888d

File tree

2 files changed

+190
-16
lines changed

2 files changed

+190
-16
lines changed

pkg/slack/model.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ type Attachment struct {
2222
}
2323

2424
type Block struct {
25-
Type string `json:"type"`
26-
Text Text `json:"text"`
27-
Fields []Text `json:"fields,omitempty"`
25+
Type string `json:"type"`
26+
Text *Text `json:"text,omitempty"`
27+
Fields *[]Text `json:"fields,omitempty"`
2828
}
2929

3030
type Text struct {

pkg/slack/response.go

+187-13
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ func FinderResponse(data models.Finder) Model {
6161
Blocks: []Block{
6262
{
6363
Type: "section",
64-
Text: Text{
64+
Text: &Text{
6565
Type: "mrkdwn",
6666
Text: fmt.Sprintf("Email *%s* \n\n<https://app.tomba.io/|Tomba web app>\n\n", email),
6767
},
68-
Fields: fields,
68+
Fields: &fields,
6969
},
7070
{
7171
Type: "divider",
7272
},
7373
{
7474
Type: "section",
75-
Text: Text{
75+
Text: &Text{
7676
Type: "mrkdwn",
7777
Text: fmt.Sprintf("We found `%d` sources for *%s* on the web.\n %s", len(data.Data.Sources), email, sources),
7878
},
@@ -87,25 +87,199 @@ func FinderResponse(data models.Finder) Model {
8787
}
8888

8989
// SearchResponse
90-
func SearchResponse(data models.Search) []Model {
90+
func SearchResponse(data models.Search) Model {
9191

92-
attachment := make([]Attachment, 0, 5)
92+
block := make([]Block, 0, 5)
9393
emails := data.Data.Emails
94+
block = append(block, Block{
95+
Type: "section",
96+
Text: &Text{
97+
Type: "mrkdwn",
98+
Text: fmt.Sprintf("%d results for your search %s\n", len(emails), *data.Data.Organization.WebsiteURL),
99+
},
100+
})
101+
94102
for i := 0; i < len(emails); i++ {
95-
attachment = append(attachment, Attachment{
96-
Color: "",
97-
Blocks: []Block{},
103+
fields := make([]Text, 0, 5)
104+
if emails[i].FullName != nil {
105+
fields = append(fields, Text{
106+
Type: "mrkdwn",
107+
Text: fmt.Sprintf("\n\n*Name*\n\n %s at \n\n", *emails[i].FullName),
108+
})
109+
}
110+
if emails[i].Email != "" {
111+
fields = append(fields, Text{
112+
Type: "mrkdwn",
113+
Text: fmt.Sprintf("\n\n*Email*\n\n %s \n\n", emails[i].Email),
114+
})
115+
}
116+
if emails[i].Position != nil {
117+
fields = append(fields, Text{
118+
Type: "mrkdwn",
119+
Text: fmt.Sprintf("\n\n*Bio*\n\n %s at %s \n\n", *emails[i].Position, data.Data.Organization.Organization),
120+
})
121+
}
122+
123+
if emails[i].Country != nil {
124+
fields = append(fields, Text{
125+
Type: "mrkdwn",
126+
Text: fmt.Sprintf("\n\n*Location*\n\n %s \n\n", *emails[i].Country),
127+
})
128+
}
129+
130+
if emails[i].Linkedin != nil {
131+
fields = append(fields, Text{
132+
Type: "mrkdwn",
133+
Text: fmt.Sprintf("\n\n*Linkedin*\n\n %s \n\n", *emails[i].Linkedin),
134+
})
135+
}
136+
137+
if emails[i].Twitter != nil {
138+
fields = append(fields, Text{
139+
Type: "mrkdwn",
140+
Text: fmt.Sprintf("\n\n*Twitter*\n\n %s \n\n", emails[i].Twitter),
141+
})
142+
}
143+
sources := ""
144+
if len(emails[i].Sources) > 0 {
145+
for i := 0; i < len(emails[i].Sources); i++ {
146+
sources += emails[i].Sources[i].URI + "\n"
147+
}
148+
}
149+
block = append(block, Block{Type: "divider"})
150+
block = append(block, Block{
151+
Type: "section",
152+
Text: &Text{
153+
Type: "mrkdwn",
154+
Text: fmt.Sprintf("Email *%s* \n\n<https://app.tomba.io/|Tomba web app>\n\n", emails[i].Email),
155+
},
156+
Fields: &fields,
98157
})
158+
block = append(block, Block{
159+
Type: "section",
160+
Text: &Text{
161+
Type: "mrkdwn",
162+
Text: fmt.Sprintf("We found `%d` sources for *%s* on the web.\n %s", len(emails[i].Sources), emails[i].Email, sources),
163+
},
164+
})
165+
block = append(block, Block{Type: "divider"})
99166
}
100167

101-
return []Model{
168+
return Model{Attachments: []Attachment{
102169
{
103-
Attachments: []Attachment{},
104-
},
105-
}
170+
Color: "#3f77e8",
171+
Blocks: block,
172+
}}}
106173
}
107174

108175
// VerifyResponse
109176
func VerifyResponse(data models.Verifier) Model {
110-
return Model{}
177+
email := data.Data.Email.Email
178+
fields := make([]Text, 0, 5)
179+
180+
fields = append(fields, Text{
181+
Type: "mrkdwn",
182+
Text: fmt.Sprintf("\n\n*Email*\n\n %s \n\n", email),
183+
})
184+
185+
Format := "Invalid"
186+
if data.Data.Email.Regex && !data.Data.Email.Gibberish {
187+
Format = "Valid"
188+
}
189+
if data.Data.Email.Gibberish {
190+
Format = "Gibberish"
191+
}
192+
fields = append(fields, Text{
193+
Type: "mrkdwn",
194+
Text: fmt.Sprintf("\n\n*Format*\n\n %s \n\n", Format),
195+
})
196+
ServerStatus := "Invalid"
197+
if data.Data.Email.MXRecords {
198+
ServerStatus = "Valid"
199+
}
200+
fields = append(fields, Text{
201+
Type: "mrkdwn",
202+
Text: fmt.Sprintf("\n\n*Server status*\n\n %s \n\n", ServerStatus),
203+
})
204+
Type := "Professional"
205+
if data.Data.Email.Webmail {
206+
Type = "Webmail"
207+
}
208+
if data.Data.Email.Disposable {
209+
Type = "Disposable"
210+
}
211+
fields = append(fields, Text{
212+
Type: "mrkdwn",
213+
Text: fmt.Sprintf("\n\n*Email Type*\n\n %s \n\n", Type),
214+
})
215+
EmailStatus := "Invalid"
216+
if data.Data.Email.Result == "deliverable" {
217+
EmailStatus = "Valid"
218+
}
219+
if data.Data.Email.AcceptAll {
220+
EmailStatus = "Accept all"
221+
}
222+
if data.Data.Email.Block {
223+
EmailStatus = "Blocked"
224+
}
225+
fields = append(fields, Text{
226+
Type: "mrkdwn",
227+
Text: fmt.Sprintf("\n\n*Email status*\n\n %s \n\n", EmailStatus),
228+
})
229+
230+
if data.Data.Email.Whois.CreatedDate != "" {
231+
fields = append(fields, Text{
232+
Type: "mrkdwn",
233+
Text: fmt.Sprintf("\n\n*Whois Creation Date*\n\n %s \n\n", data.Data.Email.Whois.CreatedDate),
234+
})
235+
}
236+
if data.Data.Email.Whois.ReferralURL != "" {
237+
fields = append(fields, Text{
238+
Type: "mrkdwn",
239+
Text: fmt.Sprintf("\n\n*RWhois*\n\n %s \n\n", data.Data.Email.Whois.ReferralURL),
240+
})
241+
}
242+
if data.Data.Email.Whois.RegistrarName != "" {
243+
fields = append(fields, Text{
244+
Type: "mrkdwn",
245+
Text: fmt.Sprintf("\n\n*Whois Name*\n\n %s \n\n", data.Data.Email.Whois.RegistrarName),
246+
})
247+
}
248+
sources := ""
249+
if len(data.Data.Sources) > 0 {
250+
for i := 0; i < len(data.Data.Sources); i++ {
251+
sources += data.Data.Sources[i].URI + "\n"
252+
}
253+
}
254+
255+
return Model{
256+
Attachments: []Attachment{
257+
{
258+
Color: "#3f77e8",
259+
Blocks: []Block{
260+
{
261+
Type: "section",
262+
Text: &Text{
263+
Type: "mrkdwn",
264+
Text: fmt.Sprintf("Email *%s* \n\n<https://app.tomba.io/|Tomba web app>\n\n", email),
265+
},
266+
Fields: &fields,
267+
},
268+
{
269+
Type: "divider",
270+
},
271+
{
272+
Type: "section",
273+
Text: &Text{
274+
Type: "mrkdwn",
275+
Text: fmt.Sprintf("We found `%d` sources for *%s* on the web.\n %s", len(data.Data.Sources), email, sources),
276+
},
277+
},
278+
{
279+
Type: "divider",
280+
},
281+
},
282+
},
283+
},
284+
}
111285
}

0 commit comments

Comments
 (0)