How to fetch the last user query

how to fetch the user query into the context variable.
how to fetch the user intent name

@csaitharun
If you create a brand new bot that does not even have a task defined, if you type any utterance you will see it in the context.
image

There are multiple places you will see the utterance captured. Please explore the context object for your use case.

{
“currentLanguage”:“en”,
“currentTraits”:[
],
“userInputs”:{
“originalInput”:{
“sentence”:“What can I get?”,
“spellCorrectedSentence”:“What can I get?”,
“sentenceType”:“question”,
“timestamp”:1626879444444
}
},
“session”:{
“EnterpriseContext”:{
“ENT_CONETXT”:“MyVal”
},
“BotContext”:{
},
“UserContext”:{
“workinghours”:{
“workdays”:“mon,tue,wed,thu,fri”,
“workstart”:“8:00 AM”,
“workend”:“5:00 PM”
},
“profImage”:“no-avatar”,
“jTitle”:null,
“dept”:"",
“profColour”:"",
“fax”:"",
“activationStatus”:“active”,
“emailId":"koresupport@kore.com”,
“firstName”:“Kore”,
“lastName”:“Support”,
“orgId”:“o-12f4144a-f85a-5cc3-8ba3-baec6a9602c4”,
“_id”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“customData”:null,
“LoginName":"koresupport@testdc.com”,
“UserID”:“1234”,
“identities”:[
{
“val":"koresupport@kore.com”,
“type”:“email”
},
{
“val":"emailchannel@bots.kore.com”,
“type”:“email”
},
{
“val":"snikhileshc@gmail.com”,
“type”:“email”
}
]
},
“UserSession”:{
},
“BotUserSession”:{
“channels”:[
{
“type”:“rtm”,
“from”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“botInfo”:{
“chatBot”:“TestBot”,
“taskBotId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”
},
“handle”:{
“handleId”:“c7ec42a7-bbaf-4e19-a426-7b7ab9a68a6a”,
“userId”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“clientId”:“5a37bf24-fea0-4e6b-a816-f9602db08149”,
“taskBotId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”,
“traceId”:“559c872ece899b28”,
“spanId”:“559c872ece899b28”,
“trace”:{
“id”:“RTM-TRACE-FA2122KXK”,
“idPrefix”:“RTM-TRACE”,
“isNew”:true,
“useRemoting”:true
}
},
“client”:“botbuilder”,
“body”:“What can I get?”,
“message”:“The bot is not accessible via Web/Mobile Client.”,
“channelDelete”:true,
“streamId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”,
“tokens”:[
],
“userId”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“requestId”:“ms-4723027b-c2f5-58c1-be8b-86f9365c92d3”,
“botLanguage”:“en”,
“requestContext”:{
“isRuntime”:true,
“isBB”:true
}
}
],
“conversationSessionId”:“60f835cb5432597055d93570”,
“lastMessage”:{
“channel”:“rtm”,
“messagePayload”:{
“clientMessageId”:1626879435216,
“message”:{
“body”:“What can I get?”
},
“resourceid”:"/bot.message",
“isDebugging”:true,
“botInfo”:{
“chatBot”:“TestBot”,
“taskBotId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”
},
“client”:“botbuilder”,
“meta”:{
“timezone”:“Asia/Kolkata”,
“locale”:“en-US”,
“location”:{
“city”:"",
“country”:"",
“latitude”:17.4116551,
“longitude”:78.3811394,
“street”:""
}
},
“id”:1626879435216
}
}
},
“opts”:{
“userId”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“streamId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”
}
},
“updatedOn”:“2021-07-21T14:57:24.448Z”
}

Now if there is a task called “MyTestDialog” which is trained with ML “This is a trained ml utterance to invoke a task”

When you enter “This is a trained ml utterance to invoke a task”

Here is what you see in the context object.

{
“currentLanguage”:“en”,
“currentTraits”:[
],
“userInputs”:{
“originalInput”:{
“sentence”:“This is a trained ml utterance to invoke a task”,
“spellCorrectedSentence”:“This is a trained ml utterance to invoke a task”,
“sentenceType”:“statement”,
“timestamp”:1626879935559
}
},
“currentTags”:{
“tags”:[
“MyTestDialog”
]
},
“endOfTask”:{
“endOfTaskReason”:“Fulfilled”,
“intentType”:“dialog”,
“taskName”:“MyTestDialog”,
“lastNode”:“message1”
},
“session”:{
“EnterpriseContext”:{
“ENT_CONETXT”:“MyVal”
},
“BotContext”:{
},
“UserContext”:{
“workinghours”:{
“workdays”:“mon,tue,wed,thu,fri”,
“workstart”:“8:00 AM”,
“workend”:“5:00 PM”
},
“profImage”:“no-avatar”,
“jTitle”:null,
“dept”:"",
“profColour”:"",
“fax”:"",
“activationStatus”:“active”,
“emailId":"koresupport@kore.com”,
“firstName”:“Kore”,
“lastName”:“Support”,
“orgId”:“o-12f4144a-f85a-5cc3-8ba3-baec6a9602c4”,
“_id”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“customData”:null,
“LoginName":"koresupport@testdc.com”,
“UserID”:“1234”,
“identities”:[
{
“val":"koresupport@kore.com”,
“type”:“email”
},
{
“val":"emailchannel@bots.kore.com”,
“type”:“email”
},
{
“val":"snikhileshc@gmail.com”,
“type”:“email”
}
]
},
“UserSession”:{
},
“BotUserSession”:{
“channels”:[
{
“type”:“rtm”,
“from”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“botInfo”:{
“chatBot”:“TestBot”,
“taskBotId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”
},
“handle”:{
“handleId”:“2511659e-8fee-4ce7-ac44-d0bc9e3a71f7”,
“userId”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“clientId”:“5a37bf24-fea0-4e6b-a816-f9602db08149”,
“taskBotId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”,
“traceId”:“db5cf9d5f65eaf37”,
“spanId”:“db5cf9d5f65eaf37”,
“trace”:{
“id”:“RTM-TRACE-JVAWD57SV”,
“idPrefix”:“RTM-TRACE”,
“isNew”:true,
“useRemoting”:true
}
},
“client”:“botbuilder”,
“body”:“This is a trained ml utterance to invoke a task”,
“message”:“The bot is not accessible via Web/Mobile Client.”,
“channelDelete”:true,
“streamId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”,
“tokens”:[
],
“userId”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“requestId”:“ms-71836325-489c-5fe4-ad79-dd1b9e24a0a4”,
“botLanguage”:“en”,
“requestContext”:{
“isRuntime”:true,
“isBB”:true
}
}
],
“conversationSessionId”:“60f837be0f4c2f0977756771”,
“lastMessage”:{
“channel”:“rtm”,
“messagePayload”:{
“clientMessageId”:1626879934335,
“message”:{
“body”:“This is a trained ml utterance to invoke a task”
},
“resourceid”:"/bot.message",
“isDebugging”:true,
“botInfo”:{
“chatBot”:“TestBot”,
“taskBotId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”
},
“client”:“botbuilder”,
“meta”:{
“timezone”:“Asia/Kolkata”,
“locale”:“en-US”,
“location”:{
“city”:"",
“country”:"",
“latitude”:17.411679,
“longitude”:78.3811296,
“street”:""
}
},
“id”:1626879934335
}
}
},
“opts”:{
“userId”:“u-adb7cfc7-e9d1-55dd-acfc-214b82dc51d8”,
“streamId”:“st-4d6df759-eac6-58ab-97e9-ca87233dd475”
}
},
“updatedOn”:“2021-07-21T15:05:35.883Z”
}

You will notice that the called intent should be under “currentTags”. After the task execution completes it will be under “endOfTask”

1 Like