Skip to content

Commit

Permalink
Add searchLocalPhonebook method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kudinov committed Feb 27, 2024
1 parent 8824f57 commit 2976472
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
openGroupChat,
requestLocation,
searchCorporatePhonebook,
searchLocalPhonebook,
sendBotCommand,
subscribeClientEvents,
unsubscribeClientEvents,
Expand Down Expand Up @@ -74,4 +75,5 @@ export {
clientStorageClear,
openPersonalChat,
handleDeeplink,
searchLocalPhonebook,
}
18 changes: 18 additions & 0 deletions src/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GetConnectionStatusResponse,
METHODS,
StatusResponse,
SearchLocalPhonebookResponse,
} from '../../types'
export * from './events'
export * from './storage'
Expand Down Expand Up @@ -148,6 +149,22 @@ const handleDeeplink = ({ link }: { link: string }): Promise<StatusResponse> =>
.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<SearchLocalPhonebookResponse> => {
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,
Expand All @@ -160,4 +177,5 @@ export {
createDeeplink,
openChatMessage,
handleDeeplink,
searchLocalPhonebook,
}
1 change: 1 addition & 0 deletions src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 21 additions & 1 deletion src/types/client.ts
Original file line number Diff line number Diff line change
@@ -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",
}
Expand All @@ -18,4 +21,21 @@ export type CreateDeeplinkResponse = ({
deeplink: string,
}
}
})
})

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<LocalPhonebookEntry>,
}
}

0 comments on commit 2976472

Please sign in to comment.