Running custom queries

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

Teneo Query Language

TQL queries are written in the Query tab and executed using the 'Run Query' button or the short-cut command Ctrl-c. The main Log Data Source window allows for 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, or the chat bot’s response. Note that selection can consist of multiple items.
  • Constraints are optional and are written with a : after the selection; this 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; the constraint is not required.

In the video below, we will construct a query that will return the number of different coffees that have 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 deeper 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.

List number of sessions by day

d date: catd(model="date") s.beginTime as date order by date desc

Example result

date count
"2019-12-16" "67"
"2019-12-15" "4"
"2019-12-14" "19"
"2019-12-13" "91"
"2019-12-12" "70"

List number of transactions by day

d date: catd(model="date") t.time as date order by date desc

Example result

date count
"2019-12-16" "891"
"2019-12-15" "4"
"2019-12-14" "133"
"2019-12-13" "1610"
"2019-12-12" "503"

Flows triggered 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

Example result

date folderPath flowName count
"2019-12-16" "/Greeting Message" "Greeting message" "65"
"2019-12-16" "/Dialogue/Connecting Phrases/Acknowledgement" "The user expresses agreement" "2"
"2019-12-16" "/Dialogue/Connecting Phrases/Acknowledgement" "The user shows encouragement to the conversation" "2"
"2019-12-16" "/Dialogue/Connecting Phrases/Acknowledgement" "The user says Yes" "12"
"2019-12-16" "/Dialogue/Conversational/Conversation" "The user comments on the weather" "2"
"2019-12-16" "/Dialogue/Conversational/Conversation" "The user wants to know the time" "12"
"2019-12-16" "/Dialogue/Connecting Phrases/Social" "The user is telling his name" "38"

List conversations

listAll as sessionId, s.beginTime as beginTime, t.e1.userInput as userInput, t.e3.answerText as response, t.e2.fname as flowName, t.e2.folder as folderName, t.index as transactionIndex, t.time as transactionTime : exists t.e1.userInput, t.e1-{type=="response"}>t.e3, t.e2<{pathType == in {"raise-flow", "continue-flow", "resume-flow"}}-t.e3 order by s.beginTime asc, t.time asc

Example result
(Some values have been shortened for brevity.)

sessionId beginTime userInput response flowName folderName tIndex tTime
"117...E80" "12/16/2019 9:44:33 PM" "" "Hello! My name is Sara." "Greeting message" "/Greeting Message" "0" "12/16/2019 9:44:33 PM"
"117...E80" "12/16/2019 9:44:33 PM" "How are you doing?" "Thanks for asking. I'm having a great time." "The user asks, How are you? How was your day" "/Dialogue/Connecting Phrases/Greetings" "1" "12/16/2019 9:44:46 PM"
"117...E80" "12/16/2019 9:44:33 PM" "Okay. Bye bye." "Goodbye! See you again soon, I hope." "The user says Goodbye" "/Goodbye Message" "2" "12/16/2019 9:44:53 PM"
"420...94B" "12/16/2019 9:44:57 PM" "" "Hi! My name is Sara." "Greeting message" "/Greeting Message" "0" "12/16/2019 9:44:57 PM"
"420...94B" "12/16/2019 9:44:57 PM" "What time is it?" "My watch says it's 10:45 PM." "The user wants to know the time" "/Dialogue/Conversational/ Conversation" "1" "12/16/2019 9:45:09 PM"
"420...94B" "12/16/2019 9:44:57 PM" "fantastic" "Glad to hear that!" "The user says Good, Great, or Excellent" "/Dialogue/Connecting Phrases/ Acknowledgement" "2" "12/16/2019 9:45:17 PM"
"420...94B" "12/16/2019 9:44:57 PM" "Goodbye." "Goodbye! See you again soon, I hope." "The user says Goodbye" "/Goodbye Message" "3" "12/16/2019 9:45:23 PM"

Was this page helpful?