【发布时间】:2018-10-28 18:02:42
【问题描述】:
我想使用 Dialogflow 和 Google Assistant 以及 Google Transactions API 创建一个聊天机器人,以使用户能够订购一些商品。目前我的代理包含以下四个意图:
-
Default Welcome Intent(短信回复:你好,要买巧克力盒吗?) Default Fallback Intent-
Int3(训练短语:是的,我想要,实现:启用 webhook) -
Int4(事件:actions_intent_TRANSACTION_DECISION,实现:启用 webhook)
我正在使用 Dialogflow Json 而不是 Node.js 将我的代理与 Transactions API 连接起来。我想通过使用 Google 操作的 actions.intent.TRANSACTION_DECISION 操作最终用户满足交易要求来为用户构建购物车和订单。出于这个原因,按照谷歌文档,当Int3被触发时,我正在使用一个连接谷歌助手我的后端的网络钩子,它发回以下json来触发actions.intent.TRANSACTION_DECISION。
因此,订单预览会在 Google 助理(在手机上)上呈现给用户。但是,如下图所示,此订单预览中未显示送货地址详细信息。
请注意,我已经去了Google Assistant app -> Settings -> Payments 并在那里填写了我的地址详细信息。结果,当我触发actions.intent.DELIVERY_ADDRESS 意图时,正如预期的那样,我得到Google Assistant app -> Settings -> Payments 的交货地址,如下图所示:Image。因此,我并没有预料到我的收货地址会在没有首先设置的情况下突然出现在订单预览中。
我的印象是,这可以通过将extension object 添加到ProposedOrder object 的整个结构中来完成,如下所示:
{ "id": string,
"cart": {
object(Cart) },
"otherItems": [
{
object(LineItem)
} ], "image": {
object(Image) },
"termsOfServiceUrl": string,
"totalPrice": {
object(Price) },
"extension": {
"@type": string,
field1: ...,
... } }
所以通过我的 webhook 触发 actions.intent.TRANSACTION_DECISION 的整个 json 响应如下:
{
"fulfillmentText": "This is your order preview:",
"payload": {
"google": {
"expectUserResponse": true,
"isSsml": false,
"noInputPrompts": [],
"systemIntent": {
"data": {
"@type": "type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec",
"orderOptions": {
"requestDeliveryAddress": true
},
"paymentOptions": {
"actionProvidedOptions": {
"displayName": "VISA **** **** **** 3235",
"paymentType": "PAYMENT_CARD"
}
},
"proposedOrder": {
"cart": {
"lineItems": [
{
"description": "Book",
"id": "1",
"name": "Book",
"price": {
"amount": {
"currencyCode": "USD",
"nanos": 0,
"units": 31
},
"type": "ACTUAL"
},
"quantity": 2,
"subLines": [],
"type": "REGULAR"
}
],
"merchant": {
"id": "Amazon",
"name": "Amazon"
},
"otherItems": []
},
"extension": {
"@type": "type.googleapis.com/google.actions.v2.orders.GenericExtension",
"locations": [
{
"location": {
"phoneNumber": "123456789",
"postalAddress": {
"recipients": [
"Me"
],
"regionCode": "USA"
}
},
"type": "DELIVERY"
}
]
},
"id": "<UNIQUE_ORDER_ID>",
"otherItems": [],
"totalPrice": {
"amount": {
"currencyCode": "USD",
"units": 31
},
"type": "ACTUAL"
}
}
},
"intent": "actions.intent.TRANSACTION_DECISION"
}
}
}
}
但后来我在 Google 助理模拟器上收到此错误:
Sorry, something went wrong. Please try again later.
因此,如果我在 extension object 的类型和格式方面做得不对,我真的无法理解。
在这种情况下,Google Assistant 的日志如下:
2018-05-23 09:12:47.024 BST
Received response from agent with body: HTTP/1.1 200 OK Server: nginx/1.13.6 Date: Wed, 23 May 2018 08:12:46 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 1782 X-Cloud-Trace-Context: **************************/**************************;o=1 Google-Actions-API-Version: 2 Via: 1.1 google Alt-Svc: clear {"conversationToken":"[\"more\"]","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"richInitialPrompt":{"items":[{"simpleResponse":{"textToSpeech":"This is your order preview:"}}]}},"possibleIntents":[{"intent":"actions.intent.TRANSACTION_DECISION","inputValueData":{"orderOptions":{"requestDeliveryAddress":true},"paymentOptions":{"actionProvidedOptions":{"displayName":"VISA **** **** **** 3235","paymentType":"PAYMENT_CARD"}},"@type":"type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec","proposedOrder":{"extension":{"@type":"type.googleapis.com/google.actions.v2.orders.GenericExtension","locations":[{"location":{"phoneNumber":"123456789","postalAddress":{"regionCode":"USA","recipients":["Me"]}},"type":"DELIVERY"}]},"totalPrice":{"amount":{"nanos":0.0,"units":36.0,"currencyCode":"USD"},"type":"ACTUAL"},"id":"<UNIQUE_ORDER_ID>","otherItems":[{"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Subtotal","id":"Subtotal","type":"SUBTOTAL"},{"price":{"amount":{"nanos":0.0,"units":5.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Delivery fees","id":"Delivery fees","type":"FEE"}],"cart":{"lineItems":[{"quantity":2.0,"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Book","description":"Book","id":"1","type":"REGULAR"}], "merchant":{"name":"Amazon","id":"Amazon"},"otherItems":[]}}}}],"speechBiasingHints":["$polar","$products"]}],"responseMetadata":{"status":{"message":"Success (200)"},"queryMatchInfo":{"queryMatched":true,"intent":"df9de4fe-fc2a-4735-a45e-f1688da93201","parameterNames":["polar"]}}}.
Expand all | Collapse all {
insertId: "**************************"
labels: {…}
logName: "**************************/logs/actions.googleapis.com%2Factions"
receiveTimestamp: "2018-05-23T08:12:47.035898145Z"
resource: {…}
severity: "DEBUG"
textPayload: "Received response from agent with body: HTTP/1.1 200 OK
Server: nginx/1.13.6
Date: Wed, 23 May 2018 08:12:46 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 1782
X-Cloud-Trace-Context: **************************/**************************;o=1
Google-Actions-API-Version: 2
Via: 1.1 google
Alt-Svc: clear
{"conversationToken":"[\"more\"]","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"richInitialPrompt":{"items":[{"simpleResponse":{"textToSpeech":"This is your order preview:"}}]}},"possibleIntents":[{"intent":"actions.intent.TRANSACTION_DECISION","inputValueData":{"orderOptions":{"requestDeliveryAddress":true},"paymentOptions":{"actionProvidedOptions":{"displayName":"VISA **** **** **** 3235","paymentType":"PAYMENT_CARD"}},"@type":"type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec","proposedOrder":{"extension":{"@type":"type.googleapis.com/google.actions.v2.orders.GenericExtension","locations":[{"location":{"phoneNumber":"123456789","postalAddress":{"regionCode":"USA","recipients":["Me"]}},"type":"DELIVERY"}]},"totalPrice":{"amount":{"nanos":0.0,"units":36.0,"currencyCode":"USD"},"type":"ACTUAL"},"id":"<UNIQUE_ORDER_ID>","otherItems":[{"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Subtotal","id":"Subtotal","type":"SUBTOTAL"},{"price":{"amount":{"nanos":0.0,"units":5.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Delivery fees","id":"Delivery fees","type":"FEE"}],"cart":{"lineItems":[{"quantity":2.0,"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Book","description":"Book","id":"1","type":"REGULAR"}],"merchant":{"name":"Amazon","id":"Amazon"},"otherItems":[]}}}}],"speechBiasingHints":["$polar","$products"]}],"responseMetadata":{"status":{"message":"Success (200)"},"queryMatchInfo":{"queryMatched":true,"intent":"df9de4fe-fc2a-4735-a45e-f1688da93201","parameterNames":["polar"]}}}."
timestamp: "2018-05-23T08:12:47.024908542Z"
trace: "**************************"
}
如何在订单预览中添加收货地址详情?
这是来自 Google 文档的订单预览示例,其中包括送货地址详细信息:
附注object(Cart) 包含"notes": string,它可以在最终订单预览中添加一个部分,该部分恰好位于上图订单预览中的交货地址部分。因此,我可以添加
"notes": "Lola\n1950 Charleston Road\nMountain View, CA 94043\n415 789 8934"
或我的个人地址详细信息到object(Cart),然后我可以在最终订单预览中显示交货详细信息,如下图所示:Image。
但是,在订单预览中,此部分的标题是 Notes,而我显然希望 Delivery address 作为上面照片中显示的标题。
【问题讨论】:
标签: actions-on-google dialogflow-es