Skip to content

Commit

Permalink
feat: support mail option, better display of contacts info
Browse files Browse the repository at this point in the history
  • Loading branch information
Avivbens committed Jun 7, 2024
1 parent 28a0b7c commit 5ca4e20
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 14 deletions.
Binary file added 0B935763-800C-48CC-9AC6-938A999A89A8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
<string>Tools</string>
<key>connections</key>
<dict>
<key>0B935763-800C-48CC-9AC6-938A999A89A8</key>
<array>
<dict>
<key>destinationuid</key>
<string>EA32942B-CBBB-4905-936E-5DE495CCC2A0</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false></false>
</dict>
</array>
<key>0D0645C0-EC0C-45FA-823E-FCC07F34732B</key>
<array>
<dict>
Expand Down Expand Up @@ -243,6 +256,55 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false></false>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<true></true>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>ecm</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<false></false>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Searching...</string>
<key>script</key>
<string>./build/Release/run-node.sh build/contacts.js "$1" "mail"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Send an email</string>
<key>title</key>
<string>Search for Contacts...</string>
<key>type</key>
<integer>5</integer>
<key>withspace</key>
<true></true>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>0B935763-800C-48CC-9AC6-938A999A89A8</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -300,6 +362,13 @@ See the workflow codebase in here:
https://github.com/Avivbens/alfred-engage-contact</string>
<key>uidata</key>
<dict>
<key>0B935763-800C-48CC-9AC6-938A999A89A8</key>
<dict>
<key>xpos</key>
<integer>75</integer>
<key>ypos</key>
<integer>475</integer>
</dict>
<key>0D0645C0-EC0C-45FA-823E-FCC07F34732B</key>
<dict>
<key>xpos</key>
Expand Down
10 changes: 4 additions & 6 deletions src/main/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ import { searchContacts } from '@services/search.service.js'
platform: platform as SupportedPlatform,
}

const subtitle =
phoneNumbers.length > 0
? `Phone: ${phoneNumbers[0]}`
: emailAddresses.length > 0
? `Email: ${emailAddresses[0]}`
: ''
const emailSubtitle = emailAddresses.length ? `Email: ${emailAddresses[0]}` : ''
const phoneSubtitle = phoneNumbers.length ? `Phone: ${phoneNumbers[0]}` : ''

const subtitle = [phoneSubtitle, emailSubtitle].filter(Boolean).join(' | ')

return {
title: `${firstName} ${lastName}`,
Expand Down
7 changes: 6 additions & 1 deletion src/main/engage-contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { buildOpenUrl } from '@services/platform-url-builder.service.js'

const { number }: PhoneNumber = parsePhoneNumber(inputPhoneNumber, inputCountryCode)

const openUrl = buildOpenUrl(platform, number)
const parsedInput = {
...input,
phoneNumber: number,
}

const openUrl = buildOpenUrl(platform, parsedInput)

await execPromise(`open ${openUrl}`)
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/models/platform.model.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const SUPPORTED_PLATFORMS = ['whatsapp', 'sms', 'call'] as const
export const SUPPORTED_PLATFORMS = ['whatsapp', 'sms', 'call', 'mail'] as const
export type SupportedPlatform = (typeof SUPPORTED_PLATFORMS)[number]
33 changes: 27 additions & 6 deletions src/services/platform-url-builder.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import type { ContactPayload } from '@models/contact-payload.model.js'
import type { SupportedPlatform } from '@models/platform.model.js'

const PLATFORMS_URLS: Record<SupportedPlatform, (phoneNumber: string) => string> = {
whatsapp: (phoneNumber: string) => `whatsapp://send?phone=${phoneNumber}`,
sms: (phoneNumber: string) => `sms:${phoneNumber}`,
call: (phoneNumber: string) => `tel:${phoneNumber}`,
const PLATFORMS_URLS: Record<SupportedPlatform, (referrer: string) => string> = {
whatsapp: (referrer: string) => `whatsapp://send?phone=${referrer}`,
sms: (referrer: string) => `sms:${referrer}`,
call: (referrer: string) => `tel:${referrer}`,
mail: (referrer: string) => `mailto:${referrer}`,
}

export function buildOpenUrl(platform: SupportedPlatform, phoneNumber: string): string {
const EXTRACT_REFERRER: Record<SupportedPlatform, keyof ContactPayload> = {
call: 'phoneNumber',
mail: 'emailAddress',
sms: 'phoneNumber',
whatsapp: 'phoneNumber',
}

export function buildOpenUrl(platform: SupportedPlatform, payload: ContactPayload): string {
const urlBuilder = PLATFORMS_URLS[platform]

if (!urlBuilder) {
throw new Error(`Unsupported platform: ${platform}`)
}

const res = urlBuilder(phoneNumber)
const referrerKey = EXTRACT_REFERRER[platform]

if (!referrerKey) {
throw new Error(`Unsupported platform: ${platform}`)
}

const referrer = payload[referrerKey]

if (!referrer) {
throw new Error(`Referrer is empty: ${referrerKey}`)
}

const res = urlBuilder(referrer)
return res
}

0 comments on commit 5ca4e20

Please sign in to comment.