From 8824f57fec58103ce90a83a6fa646e0fbae00c05 Mon Sep 17 00:00:00 2001 From: Ivan Kudinov Date: Mon, 29 Jan 2024 16:31:18 +0300 Subject: [PATCH] Add handleDeeplink method --- package.json | 2 +- src/index.ts | 2 ++ src/lib/client/index.ts | 27 +++++++++++++++++++++++++-- src/types/bridge.ts | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d532432..7b6b850 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@expressms/smartapp-sdk", - "version": "1.5.0", + "version": "1.6.0-alpha.1", "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 7480e3d..c1cf584 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { createDeeplink, getChats, getConnectionStatus, + handleDeeplink, openChatMessage, openClientSettings, openFile, @@ -72,4 +73,5 @@ export { clientStorageRemove, clientStorageClear, openPersonalChat, + handleDeeplink, } diff --git a/src/lib/client/index.ts b/src/lib/client/index.ts index 06d6e0b..ecc6dbd 100644 --- a/src/lib/client/index.ts +++ b/src/lib/client/index.ts @@ -1,10 +1,16 @@ import bridge from '@expressms/smartapp-bridge' import { EmitterEventPayload } from '@expressms/smartapp-bridge/build/main/types/eventEmitter' -import { CreateDeeplinkResponse, ERROR_CODES, File, GetConnectionStatusResponse, METHODS } from '../../types' +import { + CreateDeeplinkResponse, + ERROR_CODES, + File, + GetConnectionStatusResponse, + METHODS, + StatusResponse, +} from '../../types' export * from './events' export * from './storage' - const openClientSettings = () => { return bridge?.sendClientEvent({ method: METHODS.OPEN_CLIENT_SETTINGS, @@ -126,6 +132,22 @@ const openChatMessage = async ({ }) } +/** + * Handle deeplink to join call/conference/chat/channel + * @param link Deeplink URL + * @returns Promise that'll be fullfilled with success response, otherwise rejected with reason + */ +const handleDeeplink = ({ link }: { link: string }): Promise => { + if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) + + return bridge + .sendClientEvent({ + method: METHODS.HANDLE_DEEPLINK, + params: { link }, + }) + .then(event => event as StatusResponse) +} + export { openFile, openClientSettings, @@ -137,4 +159,5 @@ export { getConnectionStatus, createDeeplink, openChatMessage, + handleDeeplink, } diff --git a/src/types/bridge.ts b/src/types/bridge.ts index 8bc270b..b730248 100644 --- a/src/types/bridge.ts +++ b/src/types/bridge.ts @@ -31,6 +31,7 @@ export enum METHODS { CLIENT_STORAGE_SET = 'client_storage_set', CLIENT_STORAGE_REMOVE = 'client_storage_remove', CLIENT_STORAGE_CLEAR = 'client_storage_clear', + HANDLE_DEEPLINK = 'handle_deeplink', } export enum STATUS {