At the end of each transaction during a Teneo session we would like to extract some general information about what happened during the session: which trigger became active, which flows and sub flows were raised and dropped, etc. More or less the information you see in try out in the icons under the user input:
We also would like to log the Teneo and solution version as shown in the publish view.
We will use TQL of course, but this requirement is for an additional logging platform. So during the session we want to save this information, and at session end we would log it via an external api.
How can we use groovy to extract trigger/flow path from the processing path?
Which API call returns the solution/teneo version? (could not find one in the api description).
As for the first question, I believe the best option is to to this in an End Dialog groovy script, where you use the dialog history to pick out the information you need.
Here’s a groovy snippet which picks out a few fields, but you will need to change the structure to suit the requirements for where you’re sending the information.
def log = []
_.dialogHistory.each { t ->
def transaction = []
t.path.each { e ->
// The type of events that you're interested in, these mirror the names of pathType in Inquire, but in camel case
if(e.type in ['raiseFlow', 'flowTrigger', 'dropFlow']) {
def event = [:]
event['type'] = e.type
event['flowName'] = e.flowName
event['flowFolder'] = e.flowFolder
event['flowId'] = e.flowId
// Use the elvis operator to get a default value in the event object
event['subFlow'] = e.subFlow ?: false
transaction.add(event)
}
}
log.add(transaction)
}
def json = new groovy.json.JsonBuilder(log).toString()
// Instead of println you would here send the json to the logging service
println json
As for your second question, the bot has a /status endpoint which with the verbose flag can provide you with this information.
So you can reach it with https://bot-server.example/bot-name/status?verbose and it should give you Version and Current-Solution-Revision .
One question, though. Can we also do this in what we know will be the last transaction?
At the End Dialog location we no longer have access to the calling service. So we would intend to return the information via an output parameter.
This then ensures that you get the exact property value that you are after
With the contains("Version") approach the value you end up with will be whichever one was last in the version response as several of the property names contain “Version”
As an extension to the script which extracts information from the dialogue history, how can we extract the same from the current transaction? This appears not yet to exist in the history. Is that doable?
Hi Fred,
yes, the data for the current transaction is available using _.processingPath , please see more in EngineAccess (Teneo Engine Scripting API) . This corresponds to one of the entries in the Dialog History.
Is there a way to combine _.dialogHistory with _.processingPath to have one structure to process instead scanning both of them?
E.g. def dh=.dialogHistory; dh= dh<<.processingPath
Was trying a bit and couldn’t find anything that worked. (Except repeating the same processing steps with the separate structures, which is a bit of redundant code).
This will let you implement the logic for path elements once and use it in both places.
(You might need to adapt this to use .collect instead of .each depending on if you’re collecting the information on each path element or iterating over all path elements.)