Skip to content

Commit

Permalink
Merge pull request #40 from ExpressApp/feature/ki/open-message
Browse files Browse the repository at this point in the history
Add openChatMessage method
  • Loading branch information
ikudinov authored Jan 16, 2024
2 parents 4960534 + eeba409 commit 0406b7b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,26 @@ const response = yield createDeeplink({
yield subscribeClientEvents('connection_status', (event) => {
// TODO: обработать event.data.connectionStatus
})
// Второй аргумент опциональный, поэтому можно вызывать так
yield subscribeClientEvents('connection_status')
```

Отписаться от изменения статуса подключения:
```
yield unsubscribeClientEvents('connection_status', functionName)
// Второй аргумент опциональный, поэтому можно вызывать так
yield unsubscribeClientEvents('connection_status')
```

__Открытие сообщения в чате__

```
yield openChatMessage({
groupChatId: "123e4567-e89b-12d3-a456-426655440000",
syncId: "123e4567-e89b-12d3-a456-426655440000",
})
```

Метод отправляет клиенту запрос на открытие сообщения в чате. Если сообщение существует, оно будет подсвечено.
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.4.1-alpha.0",
"version": "1.4.2-alpha.1",
"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 @@ -3,6 +3,7 @@ import {
createDeeplink,
getChats,
getConnectionStatus,
openChatMessage,
openClientSettings,
openFile,
openGroupChat,
Expand Down Expand Up @@ -60,4 +61,5 @@ export {
subscribeClientEvents,
unsubscribeClientEvents,
createDeeplink,
openChatMessage,
}
2 changes: 1 addition & 1 deletion src/lib/client/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const installBridgeEventListener = () => {
/**
* Subscribe to special client events
* @param eventType Event from SubscriptionEventType enum to be subscribed
* @param callback Optinonal function to be handled when event is coming
* @param callback Optional function to be handled when event is coming
* @returns Promise that'll be fullfilled on successful subscription, otherwise rejected with reason
*/
const subscribeClientEvents = (eventType: SubscriptionEventType, callback?: Function): Promise<{ status: string }> => {
Expand Down
55 changes: 38 additions & 17 deletions src/lib/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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'
export * from './events'

Expand All @@ -9,24 +10,24 @@ const openClientSettings = () => {
})
}

const getChats = ({filter = null}: { filter: string | null }) => {
const getChats = ({ filter = null }: { filter: string | null }) => {
return bridge?.sendClientEvent({
method: METHODS.GET_CHATS,
params: {filter},
params: { filter },
})
}

const searchCorporatePhonebook = ({filter = null}: { filter: string | null }) => {
const searchCorporatePhonebook = ({ filter = null }: { filter: string | null }) => {
return bridge?.sendClientEvent({
method: METHODS.SEARCH_CORPORATE_PHONEBOOK,
params: {filter},
params: { filter },
})
}

const openGroupChat = ({groupChatId}: { groupChatId: string }) => {
const openGroupChat = ({ groupChatId }: { groupChatId: string }) => {
return bridge?.sendClientEvent({
method: METHODS.OPEN_GROUP_CHAT,
params: {groupChatId},
params: { groupChatId },
})
}

Expand All @@ -37,17 +38,15 @@ const openFile = (file: File) => {
})
}

const sendBotCommand = (
{
userHuid,
body,
data,
}: {
userHuid: string
body: string
data: { command: string } | null
}
) => {
const sendBotCommand = ({
userHuid,
body,
data,
}: {
userHuid: string
body: string
data: { command: string } | null
}) => {
if (typeof data !== 'object') return

return bridge?.sendClientEvent({
Expand Down Expand Up @@ -104,6 +103,27 @@ const createDeeplink = async (
return response as CreateDeeplinkResponse
}

/**
* Open message in chat
* @param groupChatId Chat identifier
* @param syncId Message identifier
* @returns Promise that'll be fullfilled with success response
*/
const openChatMessage = async ({
groupChatId,
syncId,
}: {
groupChatId: string
syncId: string
}): Promise<EmitterEventPayload> => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)

return await bridge.sendClientEvent({
method: METHODS.OPEN_CHAT_MESSAGE,
params: { groupChatId, syncId },
})
}

export {
openFile,
openClientSettings,
Expand All @@ -114,4 +134,5 @@ export {
requestLocation,
getConnectionStatus,
createDeeplink,
openChatMessage,
}
1 change: 1 addition & 0 deletions src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum METHODS {
UNSUBSCRIBE_CLIENT_EVENTS = 'unsubscribe_client_events',
GET_CONNECTION_STATUS = 'get_connection_status',
CREATE_DEEPLINK = 'create_deeplink',
OPEN_CHAT_MESSAGE = 'open_chat_message',
}

export enum STATUS {
Expand Down

0 comments on commit 0406b7b

Please sign in to comment.