Query for last transaction

Our customer would like to do a query that counts sessions that ended with the safetynet.
E.g. the user receives an “Sorry, didn’t understand” response and then ends the conversation.

As far as I know it’s not possible to determine if a particular transaction was the final one using TQL. It can probably be done using adorners, but we would like to know if there is an easier way to do it.

E.g. logically, one would expect this query to work:

ca s.id: t.e.vname==“safetynet”, s.transactionCount == t.index + 1

Any suggestions would be most helpful!

Thank you!

Hi Fred,

According to what i’ve tested, it seems that calculations in constraints such as t.index + 1 may receive unexpected results. So my suggestions is use adorner.

Cheers,

Chunlin

Thank you, Chunlin. In case you have it, could you please post a code here that adorns the final transaction of a session? That would be very helpful for our team.

Kind regards,
Fred

Hi Fred,

You can create a groovy adorner called t.a.b:isLastTransaction with the following code:

int nLastTransactionIndex = session.transactions.size() - 1;
boolean isLastTransaction = false;
session.transactions.each{ t->
        if (t.index == nLastTransactionIndex) {
            isLastTransaction = true;
        } else {
            isLastTransaction = false;
        }
        callback.adornTransaction( t.getId(), 't.a.b:isLastTransaction' , isLastTransaction )
}

Then use this query to count sessions that ended with safetynet:

ca t.id : t.a.b:isLastTransaction == true, t.e.fname == “safetynet”

4 Likes

Thank you, Chunlin!

1 Like