Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add searchLocalPhonebook method #50

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>,
}
}