diff --git a/README.MD b/README.MD index 54e5afa..1c4b3c4 100644 --- a/README.MD +++ b/README.MD @@ -80,7 +80,7 @@ nodeSDK.start().then( () => { done(); }, this); - chatbot.onTicket((tag, history, from, start, end) => { + chatbot.onTicket((tag, history, from, start, end, state) => { // Do something when a user has completed a scenario ... }, this); @@ -281,7 +281,7 @@ In that sample, depending on the step, the user and the answer received, a rerou ### Tickets reporting -Each time a user has finished a scenario, a ticket is generated that contains all inputs received from that user associated with all actions done. +Each time a user has finished a scenario or has exited a scenario, a ticket is generated that contains all inputs received from that user associated with all actions done. #### Listening to tickets @@ -289,7 +289,7 @@ If you want to listen to tickets generated, you have to add the following code: ```js -chatbot.onTicket((tag, history, from, startdate, enddate) => { +chatbot.onTicket((tag, history, from, startdate, enddate, state) => { // Do something with the ticket ... }, this); @@ -308,6 +308,8 @@ This callback will receive: - `enddate`: The date when the scenario has finished for this user +- `state`: The state of the ticket. The possible values are `CLOSED` when the scenario has been finished successfully or `ABORTED` if the scenario didn't reach the last step. + #### Tickets storage It's up to your application to store tickets. Once generated, tickets are not saved by the chatbot. If you don't catch them and store them, tickets will be lost. diff --git a/index.js b/index.js index 3626eb9..cf04950 100644 --- a/index.js +++ b/index.js @@ -61,7 +61,7 @@ class RainbowAgent { disable() { this._isEnabled = false; this.logger.log("warn", LOG_ID + "disable() - Mode is disabled"); - this.works.reset(); + this.works.purge(); } get state() { @@ -130,7 +130,7 @@ class RainbowAgent { } fireTicketEvent(work) { - this._callbackTicket.call(this._contextTicket, work.tag, work.history, work.from, work.createdOn, work.endedOn); + this._callbackTicket.call(this._contextTicket, work.tag, work.history, work.from, work.createdOn, work.endedOn, work.state); } addPostListener() { diff --git a/modules/works.js b/modules/works.js index c1a6304..79d6655 100644 --- a/modules/works.js +++ b/modules/works.js @@ -52,10 +52,17 @@ class Works { }); } - reset() { + purge() { this._works.forEach((work) => { - work.abort(); - this._event.emit("ontaskfinished", work); + // purge opened tickets from the base when chatbot is stopped + if( work.state === Work.STATE.INPROGRESS || + work.state === Work.STATE.NEW || + work.state === Work.STATE.BLOCKED || + work.state === Work.STATE.TERMINATED) { + + work.abort(); + this._event.emit("ontaskfinished", work); + } }); } diff --git a/package.json b/package.json index d908c52..c38dde9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rainbow-chatbot", - "version": "1.34.3", + "version": "1.34.4", "description": "Rainbow ChatBot library for the Rainbow SDK for Node.JS", "main": "index.js", "scripts": { diff --git a/samples/sample_message.js b/samples/sample_message.js index 8c70c14..bd12db7 100644 --- a/samples/sample_message.js +++ b/samples/sample_message.js @@ -28,8 +28,8 @@ nodeSDK.start().then( () => { } }, this); - chatbot.onTicket((tag, history, from, start, end) => { - console.log("::: On ticket>", tag, history, from, start, end); + chatbot.onTicket((tag, history, from, start, end, state) => { + console.log("::: On ticket>", tag, history, from, start, end, state); }, this); });