【问题标题】:How to add Two number in simple intent DialogFlow?如何在简单的意图 DialogFlow 中添加两个数字?
【发布时间】:2018-06-26 09:47:58
【问题描述】:

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

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

但我收到了这个回复。

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

【问题讨论】:

    标签: actions-on-google dialogflow-es


    【解决方案1】:

    https://discuss.api.ai/t/start-conversation-with-user-programatically-from-the-server-side-api-ais-side-on-a-notification/1876/2

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

    为此,您需要打开履行,并在该部分中使用 queryResult.parameters.<nameofparam> 获取在 action and 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));
    

    【讨论】:

      【解决方案2】:

      如果你需要执行一些操作,那么你需要使用fulfillment - 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)
      

      如果您有兴趣了解更多信息,请花一些时间阅读my blog,其中包含完整的代码以及实现步骤。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-22
        • 2021-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多