diff --git a/package.json b/package.json index 7b6b850..4bdc9eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@expressms/smartapp-sdk", - "version": "1.6.0-alpha.1", + "version": "1.6.0-alpha.3", "description": "Smartapp SDK", "main": "build/main/index.js", "typings": "build/main/index.d.ts", diff --git a/src/index.ts b/src/index.ts index c1cf584..018e635 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,7 @@ import { openGroupChat, requestLocation, searchCorporatePhonebook, + searchLocalPhonebook, sendBotCommand, subscribeClientEvents, unsubscribeClientEvents, @@ -74,4 +75,5 @@ export { clientStorageClear, openPersonalChat, handleDeeplink, + searchLocalPhonebook, } diff --git a/src/lib/client/index.ts b/src/lib/client/index.ts index ecc6dbd..420b6a9 100644 --- a/src/lib/client/index.ts +++ b/src/lib/client/index.ts @@ -7,6 +7,7 @@ import { GetConnectionStatusResponse, METHODS, StatusResponse, + SearchLocalPhonebookResponse, } from '../../types' export * from './events' export * from './storage' @@ -148,6 +149,22 @@ const handleDeeplink = ({ link }: { link: string }): Promise => .then(event => event as StatusResponse) } +/** + * Search entries in local phonebook + * @param filter Query string + * @returns Promise that'll be fullfilled with `payload.localPhonebookEntries` on success, otherwise rejected with reason + */ +const searchLocalPhonebook = ({ filter = null }: { filter: string | null }): Promise => { + if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) + + return bridge + .sendClientEvent({ + method: METHODS.SEARCH_LOCAL_PHONEBOOK, + params: { filter }, + }) + .then(event => event as SearchLocalPhonebookResponse) +} + export { openFile, openClientSettings, @@ -160,4 +177,5 @@ export { createDeeplink, openChatMessage, handleDeeplink, + searchLocalPhonebook, } diff --git a/src/types/bridge.ts b/src/types/bridge.ts index b730248..34ecb6d 100644 --- a/src/types/bridge.ts +++ b/src/types/bridge.ts @@ -32,6 +32,7 @@ export enum METHODS { CLIENT_STORAGE_REMOVE = 'client_storage_remove', CLIENT_STORAGE_CLEAR = 'client_storage_clear', HANDLE_DEEPLINK = 'handle_deeplink', + SEARCH_LOCAL_PHONEBOOK = 'search_local_phonebook', } export enum STATUS { diff --git a/src/types/client.ts b/src/types/client.ts index 60acce3..f2a37d2 100644 --- a/src/types/client.ts +++ b/src/types/client.ts @@ -1,3 +1,6 @@ +import { EmitterEventPayload } from '@expressms/smartapp-bridge/build/main/types/eventEmitter' +import { STATUS } from './bridge' + export enum SubscriptionEventType { CONNECTION_STATUS = "connection_status", } @@ -18,4 +21,21 @@ export type CreateDeeplinkResponse = ({ deeplink: string, } } -}) \ No newline at end of file +}) + +type LocalPhonebookEntry = ({ + avatar: string | null, + name: string | null, + contacts: { + contactType: string, + contact: string, + }[], +}) + +export interface SearchLocalPhonebookResponse extends EmitterEventPayload { + payload: { + status: STATUS, + errorCode?: string | null, + localPhonebookEntries: Array, + } +}