Actions on google 如何在simple intent DialogFlow中添加两个数字?

Actions on google 如何在simple intent DialogFlow中添加两个数字?,actions-on-google,dialogflow-es,Actions On Google,Dialogflow Es,我正在尝试使用DialogFlow添加两个数字 问题:添加5和6 我的Ans:结果是5+6 但这次我得到了回应 Ans逻辑:结果为$number+$number1 它是一个API,用于为用户创建自然语言理解模型 对话界面。如果您有自定义业务逻辑或 平台特定的消息格式要求 为此,您需要打开“实现”,在这一部分中,使用queryResult.parameters.获取在action和parameters中识别的参数,然后执行以下任务: let num1 = parseInt(queryResult

我正在尝试使用DialogFlow添加两个数字

问题:添加5和6
我的Ans:结果是5+6

但这次我得到了回应

Ans逻辑:结果为$number+$number1

它是一个API,用于为用户创建自然语言理解模型 对话界面。如果您有自定义业务逻辑或 平台特定的消息格式要求

为此,您需要打开“实现”,在这一部分中,使用
queryResult.parameters.
获取在
action和parameters
中识别的参数,然后执行以下任务:

let num1 = parseInt(queryResult.parameters.number);
let num2 = parseInt(queryResult.parameters.number1);
let responseText =  {
    "fulfillmentText": "",
    "fulfillmentMessages": [],
    "source": "example.com",
    "payload": {},
    "outputContexts": [],
    "followupEventInput": {}
};
responseText.fulfillmentText = "" + num1 + num2;
res.status(200).send(JSON.stringify(responseText));

如果您需要执行一些操作,那么您需要使用实现webhook概念。我使用Django框架捕获请求,并将响应作为jsonresponse发回

下面是一段代码:

@csrf_exempt
def webhook(request):
  # build a request object
  req = json.loads(request.body)
  # get action from json (i.e) arithmetic operation that we need to perform
  action = req.get('queryResult').get('action')
  #get the numbers from the json
  num = req.get('queryResult').get('parameters')
  n1 = int(num.get('number'))
  n2 = int(num.get('number1'))
  if action == 'addition':
  # return a fulfillment message
      fulfillmentText = {'fulfillmentText': n1+n2}
return JsonResponse(fulfillmentText, safe=False)
如果您有兴趣了解更多信息,请花些时间阅读完整的代码片段以及实现步骤