gpt4 book ai didi

actions-on-google - 如何从我的 webhook 触发 `action.intent.INTENT_NAME` 意图?

转载 作者:行者123 更新时间:2023-12-04 07:43:40 26 4
gpt4 key购买 nike

我想用 Dialogflow 和 Google Assistant 以及 Google Transactions API 创建一个聊天机器人,让用户能够订购巧克力盒。现在我的代理包含以下四个意图:

  • Default Welcome Intent (文字回复:你好,要买巧克力盒吗?)
  • Default Fallback Intent
  • Int1 (训练短语:是的,我想要,实现:启用 webhook 调用)
  • Int2 (事件:actions_intent_TRANSACTION_REQUIREMENTS_CHECK)

  • 我正在使用 Dialogflow Json 而不是 Node.js 将我的代理与 Transactions API 连接起来。我想通过使用 actions.intent.TRANSACTION_REQUIREMENTS_CHECK 来测试用户是否满足交易要求(订购巧克力盒时)。谷歌行动的行动。出于这个原因,按照 Google 文档,当 Int1被触发我正在使用一个将 Google Assistant 连接到以下 python 脚本(后端)的 webhook:
    from flask import Flask, render_template, request, jsonify
    from flask_cors import CORS
    import requests

    app = Flask(__name__)
    CORS(app)

    @app.route("/", methods=['POST'])

    def index():

    data = request.get_json()
    intent = data["queryResult"]["intent"]["displayName"]

    if (intent == 'Int1'):

    return jsonify({ "data": {
    "google": {
    "expectUserResponse": True,
    "isSsml": False,
    "noInputPrompts": [],
    "systemIntent": {
    "data": {
    "@type": "type.googleapis.com/google.actions.v2.TransactionRequirementsCheckSpec",
    "paymentOptions": {
    "actionProvidedOptions": {
    "displayName": "VISA-1234",
    "paymentType": "PAYMENT_CARD"
    }
    }
    },
    "intent": "actions.intent.TRANSACTION_REQUIREMENTS_CHECK"
    }
    }
    }
    })
    else:
    return jsonify({'message': 'HERE'})

    if __name__== "__main__":
    app.run(debug=True)

    我在上面返回的 json intent = 'Int1'是 Google 文档中指定的“使用您自己的付款方式检查要求”的选项。
    根据谷歌文档,接下来必须这样做:

    Receiving the result of a requirements check

    After the Assistant fulfills the intent, it sends your fulfillment a request with the actions.intent.TRANSACTION_REQUIREMENTS_CHECK intent with the result of the check.

    To properly handle this request, declare a Dialogflow intent that's triggered by the actions_intent_TRANSACTION_REQUIREMENTS_CHECK event.



    为此,我定义了 Int2并且作为它的事件 actions_intent_TRANSACTION_REQUIREMENTS_CHECK .

    但是,我的后端没有收到任何检查结果,因此我不知道操作 actions.intent.TRANSACTION_REQUIREMENTS_CHECK真的被触发了。为什么会这样?

    一般来说,我怎样才能触发一个actions.intent.INTENT_NAME来自我的 webhook/后端的意图?

    当我使用 Dialogflow 的 v2 版本时,我在 Int1 时收到以下关于 Dialogflow 上的 webhook 的信息/消息。被触发:
      "webhookStatus": {
    "code": 3,
    "message": "Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: data in message google.cloud.dialogflow.v2.WebhookResponse."
    }

    在同样的情况下,当 Int1 时,我在 Google Assistant 模拟器上收到以下关于 webhook 的信息/消息。被触发:
      "responseMetadata": {
    "status": {
    "code": 14,
    "message": "Webhook error (206)"
    }

    最后,让我提一下,我正在使用 Python 测试所有这些。和 ngrok在我的本地计算机上,所以这可能会造成问题,因为在 Google 文档的开头提到了以下内容:

    Warning: The Actions Web Simulator should not be used to test an app with transactions. Please use an Assistant-enabled Android or iOS device to accurately test your app during development.

    最佳答案

    我终于解决了这个问题。

    我不得不更换 key "data"Int1 时我发回的 json 中由键 "payload" 触发.换句话说,我必须将我的履行响应调整为 v2 version。的 Dialogflow .

    因此,现在我确实在我的后端收到了第二个发布请求,该请求是由于 actions.intent.TRANSACTION_REQUIREMENTS_CHECK 的触发而发送的。和 Int2 .

    具体来说,我得到以下信息:

    {
    "responseId": "*****************************",
    "queryResult": {
    "queryText": "actions_intent_TRANSACTION_REQUIREMENTS_CHECK",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentText": "HERE",
    "fulfillmentMessages": [
    {
    "text": {
    "text": [
    "HERE"
    ]
    }
    }
    ],
    "outputContexts": [
    {
    "name": "*****************************"
    },
    {
    "name": "*****************************"
    },
    {
    "name": "*****************************"
    },
    {
    "name": "*****************************"
    },
    {
    "name": "*****************************"
    },
    {
    "name": "*****************************",
    "parameters": {
    "TRANSACTION_REQUIREMENTS_CHECK_RESULT": {
    "@type": "type.googleapis.com/google.actions.v2.TransactionRequirementsCheckResult",
    "resultType": "OK"
    }
    }
    }
    ],
    "intent": {
    "name": "*****************************",
    "displayName": "Int2"
    },
    "intentDetectionConfidence": 1,
    "diagnosticInfo": {},
    "languageCode": "en-us"
    },
    "originalDetectIntentRequest": {
    "source": "google",
    "version": "2",
    "payload": {
    "isInSandbox": true,
    "surface": {
    "capabilities": [
    {
    "name": "actions.capability.WEB_BROWSER"
    },
    {
    "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
    },
    {
    "name": "actions.capability.SCREEN_OUTPUT"
    },
    {
    "name": "actions.capability.AUDIO_OUTPUT"
    }
    ]
    },
    "inputs": [
    {
    "rawInputs": [
    {
    "inputType": "KEYBOARD"
    }
    ],
    "arguments": [
    {
    "extension": {
    "@type": "type.googleapis.com/google.actions.v2.TransactionRequirementsCheckResult",
    "resultType": "OK"
    },
    "name": "TRANSACTION_REQUIREMENTS_CHECK_RESULT"
    }
    ],
    "intent": "actions.intent.TRANSACTION_REQUIREMENTS_CHECK"
    }
    ],
    "user": {
    "lastSeen": "2018-05-16T11:15:14Z",
    "locale": "en-US",
    "userId": "*****************************"
    },
    "conversation": {
    "conversationId": "1526470000479",
    "type": "ACTIVE",
    "conversationToken": "[]"
    },
    "availableSurfaces": [
    {
    "capabilities": [
    {
    "name": "actions.capability.SCREEN_OUTPUT"
    },
    {
    "name": "actions.capability.AUDIO_OUTPUT"
    }
    ]
    }
    ]
    }
    },
    "session": "*****************************"
    }

    关于actions-on-google - 如何从我的 webhook 触发 `action.intent.INTENT_NAME` 意图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50355250/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com