Skip to content

Commit

Permalink
feat(core): Allow to set an auto idle message in Handoff Builder (#2218)
Browse files Browse the repository at this point in the history
* feat(core): add autoIdleMessage in HandoffBuilder to be able to set an auto message when the case is set to IDLE status

* test(core): test the new withAutoIdleMessage function in HandoffBuilder
  • Loading branch information
asastre authored and vanbasten17 committed Mar 23, 2023
1 parent 73c8c32 commit 4149686
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/botonic-core/src/handoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class HandOffBuilder {
_agentId: string
_note: string
_caseInfo: string
_autoIdleMessage: string
_shadowing: boolean

constructor(botState: any) {
Expand Down Expand Up @@ -105,6 +106,11 @@ export class HandOffBuilder {
return this
}

withAutoIdleMessage(message: string): this {
this._autoIdleMessage = message
return this
}

withShadowing(shadowing = true): this {
this._shadowing = shadowing
return this
Expand All @@ -119,6 +125,7 @@ export class HandOffBuilder {
this._agentId,
this._caseInfo,
this._note,
this._autoIdleMessage,
this._shadowing
)
}
Expand Down Expand Up @@ -150,6 +157,7 @@ interface HubtypeHandoffParams {
agent_id?: string
case_info?: string
note?: string
auto_idle_message?: string
shadowing?: boolean
on_finish?: string
}
Expand All @@ -161,6 +169,7 @@ async function _humanHandOff(
agentId = '',
caseInfo = '',
note = '',
autoIdleMessage = '',
shadowing = false
) {
const params: HubtypeHandoffParams = {}
Expand All @@ -179,6 +188,9 @@ async function _humanHandOff(
if (note) {
params.note = note
}
if (autoIdleMessage) {
params.auto_idle_message = autoIdleMessage
}
if (shadowing) {
params.shadowing = shadowing
}
Expand Down
15 changes: 14 additions & 1 deletion packages/botonic-core/tests/handoff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { PATH_PAYLOAD_IDENTIFIER } from '../src'
import { HandOffBuilder, humanHandOff } from '../src/handoff'

describe.skip('handOff', () => {
describe('Handoff', () => {
test.each([
[
`create_case:{
Expand Down Expand Up @@ -60,4 +60,17 @@ describe.skip('handOff', () => {
builder.handOff()
expect(builder._session._botonic_action).toEqual(expected)
})

test('receives the auto idle message', () => {
const builder = new HandOffBuilder({}).withAutoIdleMessage(
'the case is in IDLE status'
)
builder.handOff()
const expectedBotonicAction =
'create_case:' +
JSON.stringify({
auto_idle_message: 'the case is in IDLE status',
})
expect(builder._session._botonic_action).toEqual(expectedBotonicAction)
})
})

0 comments on commit 4149686

Please sign in to comment.