-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support mail option, better display of contacts info
- Loading branch information
Showing
6 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |