- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用 Dialogflow 和 Google Assistant 以及 Google Transactions API 创建一个聊天机器人,让用户能够订购巧克力盒。现在我的代理包含以下四个意图:
Default Welcome Intent
(文字回复:你好,要买巧克力盒吗?)Default Fallback Intent
Int1
(训练短语:是的,我想要,实现:启用 webhook 调用)Int2
(事件:actions_intent_TRANSACTION_REQUIREMENTS_CHECK)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)
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/后端的意图?
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/
我是一名优秀的程序员,十分优秀!