Skip to content

Commit

Permalink
Add work state to ticket report
Browse files Browse the repository at this point in the history
  • Loading branch information
oanguenot committed Jan 10, 2018
1 parent f4d27f6 commit 0157265
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -281,15 +281,15 @@ 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

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);
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 10 additions & 3 deletions modules/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 0157265

Please sign in to comment.