Running custom queries

Teneo Query Language allows you to write custom queries and retrieve results which can be used to improve your solution. TQL queries run over session’s transactions events. For example, it could be used to identify all inputs from the end user which ended up in the safety net or investigate how often people visits a newly created flow which could be important to your business.

Teneo Query Language

The TQL queries are written in the Query tab and executed using the run query button or the short-cut command ctrl-c. The main LDS window allows multiple tabs to be opened but be aware, studio does not cache these tabs. If you close your main LDS window without saving the queries, they will be lost. Shared queries can be found in the Shared Queries tab and your recent run queries can be found in the tab Recent Queries, both are located to the left in the main LDS window.

Image of the main LDS window

A TQL query consists of a command, one or more selection and optionally, a set of constraints and ordering.

  • Command dictates how the selection will be displayed.
  • Selection is what you want to investigate, such as, session IDs, user inputs, the chat bot’s response. Note that selection can consist of multiple items.
  • Constraints are optional and is written out like this: : after the selection and is used for making the selection stricter.

In the image below the command would be d, distribute and the selection would be t.e.userInput and should be read as distribute the transaction events ‘userInput’. This query will return all the user inputs.

basic query annotated

Constraints can be added to make the selection more strict. The annotated query below should be read as: Distribute the transaction events 'userInputs' where the transaction event 'userInput' is not empty and order the returned results from most to least.

basic query with constraint

Note that you can order a command and a selection, it does not require the constraint.

In the video below we will construct a query that will return the number of different coffees that has been purchased, and then order this list to see which coffee has been purchased the most.

Here is the query that was used in the video: d t.e.fv:s:orderedCoffeeType : t.e.fv:s:orderedCoffeeType != "" order by count desc

The TQL cookbook contains pre-built TQL queries with an explanatory text. If you are interested in diving into TQL, there is the TQL reference document which, goes into all aspects of TQL.

Pre-built queries

Besides the cookbook, here are some pre-defined TQL queries which you can copy and add to your LDS.

TQL - Query Description
d date: catd(model="date") s.beginTime as date order by date desc Sessions by Day
d date: catd(model="date") t.time as date order by date desc Transactions by Day
d date, t.e.folder as folderPath, t.e.fname as flowName: catd(model="date") t.time as date, t.e.pathType == "flow-trigger" order by date desc Flows Triggered by Day

Was this page helpful?