且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DialogFlow实现-如何同时获取参数的原始值和默认值

更新时间:2022-04-11 21:41:58

首先,您需要 @sys .date 实体,如果您想捕获诸如明天之类的实体而不是 @ sys.time

First, you would need @sys.date entity if you want to catch value of entities like tomorrow instead of @sys.time

现在要问的是,直接提取参数值只会为我们提供解析后的日期值,而不是原始值。

但是我们设置了一个输出上下文,然后从该上下文中我们可以按预期提取解析后的值和原始值。

Now coming to the question, directly extracting the parameter value will only give us parsed date value, not the original value.
But if we set an output context, then from that context we can extract both parsed value and the original value as intended.

这是我们在webhook上获得的请求date和date.original通过解析我们在意图中设置的输出上下文:

Here is a request that we get on webhook we can get date and date.original by parsing the output-context that we set in the intent:


{ responseId: ###, queryResult:{ queryText:明天打开
, parameters:{ date :: 2018-12-28T12:00:00 + 05:30}, allRequiredParamsPresent:true, fulfillmentText:, fulfillmentMessages:[{ text:{ text:[] }}], outputContexts:[{名称:项目/ ### /代理/会话/ ### /上下文/时间, lifespanCount:5,参数:{日期: 2018-12-28T12:00:00 + 05:30, date.original:明天 }}}],意图:{名称:项目/ ### / agent / intents / ###, displayName:时间意图}, intentDetectionConfidence:1, languageCode: en}}

{"responseId":"###","queryResult":{"queryText":"are you open tomorrow","parameters":{"date":"2018-12-28T12:00:00+05:30"},"allRequiredParamsPresent":true,"fulfillmentText":"","fulfillmentMessages":[{"text":{"text":[""]}}],"outputContexts":[{"name":"projects/###/agent/sessions/###/contexts/time","lifespanCount":5,"parameters":{"date":"2018-12-28T12:00:00+05:30","date.original":"tomorrow"}}],"intent":{"name":"projects/###/agent/intents/###","displayName":"time-intent"},"intentDetectionConfidence":1,"languageCode":"en"}}