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

feat: subscribe to initial queue position in botonic #2975

Merged
10 changes: 10 additions & 0 deletions packages/botonic-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ All notable changes to Botonic will be documented in this file.
### Fixed

</details>

## [0.32.0] - TBD

### Added

- [BLT-1369](https://hubtype.atlassian.net/browse/BLT-1369): Add new `SubscribeHelpdeskEvents` event `InitialQueuePosition`.

### Changed

### Fixed
2 changes: 1 addition & 1 deletion packages/botonic-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botonic/core",
"version": "0.31.1",
"version": "0.32.0-alpha.0",
"license": "MIT",
"description": "Build Chatbots using React",
"main": "./lib/cjs/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/botonic-core/src/handoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface BotEventData {
export enum HelpdeskEvent {
StatusChanged = 'status_changed',
AgentMessageCreated = 'agent_message_created',
InitialQueuePosition = 'initial_queue_position',
}

function contextDefaults(context: any): BackendContext {
Expand Down
2 changes: 2 additions & 0 deletions packages/botonic-core/src/models/legacy-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export enum INPUT {
WHATSAPP_BUTTON_LIST = 'whatsapp-button-list',
WHATSAPP_CTA_URL_BUTTON = 'whatsapp-cta-url-button',
EVENT_AGENT_MESSAGE_CREATED = 'case_event_agent_message_created',
EVENT_INITIAL_QUEUE_POSITION = 'case_event_initial_queue_position',
WHATSAPP_CATALOG = 'whatsapp-catalog',
WHATSAPP_PRODUCT = 'whatsapp-product',
WHATSAPP_PRODUCT_LIST = 'whatsapp-product-list',
Expand Down Expand Up @@ -120,6 +121,7 @@ export type InputType =
| INPUT.WHATSAPP_BUTTON_LIST
| INPUT.WHATSAPP_CTA_URL_BUTTON
| INPUT.EVENT_AGENT_MESSAGE_CREATED
| INPUT.EVENT_INITIAL_QUEUE_POSITION
| INPUT.WHATSAPP_CATALOG
| INPUT.WHATSAPP_PRODUCT
| INPUT.WHATSAPP_PRODUCT_LIST
Expand Down
8 changes: 8 additions & 0 deletions packages/botonic-core/tests/handoff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,12 @@ describe('Handoff', () => {
const expectedBotonicAction = `${BotonicAction.CreateCase}:{"force_assign_if_not_available":true,"on_finish":"payload1","subscribe_helpdesk_events":["agent_message_created"]}`
expect(builder._session._botonic_action).toEqual(expectedBotonicAction)
})
test('Create a handoff and subscribe to initial_queue_position', () => {
const builder = new HandOffBuilder({})
.withSubscribeHelpdeskEvents([HelpdeskEvent.InitialQueuePosition])
.withOnFinishPayload('payload1')
builder.handOff()
const expectedBotonicAction = `${BotonicAction.CreateCase}:{"force_assign_if_not_available":true,"on_finish":"payload1","subscribe_helpdesk_events":["initial_queue_position"]}`
expect(builder._session._botonic_action).toEqual(expectedBotonicAction)
})
})
14 changes: 13 additions & 1 deletion packages/botonic-plugin-flow-builder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ All notable changes to Botonic will be documented in this file.

</details>

## [0.32.0] - TBD

### Added

- Add logic to conditionally [subscribe to `InitialQueuePosition` helpdesk event](https://github.com/hubtype/botonic/pull/2975) when doing a handoff.

### Changed

- Plugin endpoints to point to [new hubtype backend flow builder app](https://github.com/hubtype/botonic/pull/2972).

### Fixed

## [0.31.2] - 2025-02-07

### Changed
Expand All @@ -30,7 +42,7 @@ All notable changes to Botonic will be documented in this file.

### Changed

- Fix isLoading in useWebviewContents[https://github.com/hubtype/botonic/issues/2973](https://github.com/hubtype/botonic/pull/2973)
- Fix [isLoading in useWebviewContents](https://github.com/hubtype/botonic/pull/2973)

## [0.31.0] - 2025-01-22

Expand Down
4 changes: 2 additions & 2 deletions packages/botonic-plugin-flow-builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botonic/plugin-flow-builder",
"version": "0.31.2",
"version": "0.32.0-alpha.1",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"description": "Use Flow Builder to show your contents",
Expand All @@ -14,7 +14,7 @@
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
},
"dependencies": {
"@botonic/react": "^0.31.0",
"@botonic/react": "0.32.0-alpha.0",
"axios": "^1.7.9",
"uuid": "^10.0.0"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/botonic-plugin-flow-builder/src/action/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { INPUT } from '@botonic/core'
import { ActionRequest, Multichannel, RequestContext } from '@botonic/react'
import React from 'react'

Expand Down Expand Up @@ -82,6 +83,10 @@
if (request.session.is_first_interaction) {
return await getContentsByFirstInteraction(context)
}
// TODO: Add needed logic when we can define contents for multilocale queue position message
if (request.input.type === INPUT.EVENT_INITIAL_QUEUE_POSITION) {
return []

Check warning on line 88 in packages/botonic-plugin-flow-builder/src/action/index.tsx

View check run for this annotation

Codecov / codecov/patch

packages/botonic-plugin-flow-builder/src/action/index.tsx#L88

Added line #L88 was not covered by tests
}

if (request.input.payload || contentID) {
const contentsByPayload = await getContentsByPayload(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HandOffBuilder, isDev, isWebchat } from '@botonic/core'
import { HandOffBuilder, HelpdeskEvent, isDev, isWebchat } from '@botonic/core'
import {
ActionRequest,
Multichannel,
Expand All @@ -16,6 +16,7 @@
public queue?: HtQueueLocale
public onFinishPayload?: string
public handoffAutoAssign: boolean
public hasInitialQueuePositionEnabled: boolean
public isTestIntegration: boolean

static fromHubtypeCMS(
Expand All @@ -28,7 +29,8 @@
newHandoff.queue = this.getQueueByLocale(locale, cmsHandoff.content.queue)
newHandoff.onFinishPayload = this.getOnFinishPayload(cmsHandoff, cmsApi)
newHandoff.handoffAutoAssign = cmsHandoff.content.has_auto_assign

newHandoff.hasInitialQueuePositionEnabled =
cmsHandoff.content.has_initial_queue_position_enabled
return newHandoff
}

Expand All @@ -47,6 +49,12 @@
const handOffBuilder = new HandOffBuilder(request.session)
handOffBuilder.withAutoAssignOnWaiting(this.handoffAutoAssign)

if (this.hasInitialQueuePositionEnabled) {
handOffBuilder.withSubscribeHelpdeskEvents([

Check warning on line 53 in packages/botonic-plugin-flow-builder/src/content-fields/flow-handoff.tsx

View check run for this annotation

Codecov / codecov/patch

packages/botonic-plugin-flow-builder/src/content-fields/flow-handoff.tsx#L53

Added line #L53 was not covered by tests
HelpdeskEvent.InitialQueuePosition,
])
}

if (this.onFinishPayload) {
handOffBuilder.withOnFinishPayload(this.onFinishPayload)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export interface HtHandoffNode extends HtBaseNode {
queue: HtQueueLocale[]
payload: HtPayloadLocale[]
has_auto_assign: boolean
has_initial_queue_position_enabled: boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ export const basicFlow = {
],
payload: [],
has_auto_assign: false,
has_initial_queue_position_enabled: false,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export const knowledgeBaseTestFlow = {
],
payload: [],
has_auto_assign: false,
has_initial_queue_position_enabled: false,
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/botonic-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botonic/react",
"version": "0.31.1",
"version": "0.32.0-alpha.0",
"license": "MIT",
"description": "Build Chatbots using React",
"main": "./lib/cjs",
Expand All @@ -20,7 +20,7 @@
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet '.*.js' '*.js' 'src/**/*.js*' --fix"
},
"dependencies": {
"@botonic/core": "^0.31.1",
"@botonic/core": "0.32.0-alpha.0",
"axios": "^1.7.9",
"emoji-picker-react": "^4.12.0",
"lodash.merge": "^4.6.2",
Expand Down