我想用Dialogflow和Google智能助理以及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
操作最终使用用户满足交易要求,为用户构建购物车和订单。出于这个原因,在Google文档之后,当Int3
被触发时,我正在使用webhook连接Google Assistant我的后端,后端发回以下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智能助理的日志如下:
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文档订单预览的示例,其中包含送货地址详细信息:
P.S。 object(Cart)
包含"notes": string
,可以在最终订单预览中添加一个部分,确切地将交货地址部分放置在上面照片的订单预览处。因此,我可以添加
"notes": "Lola\n1950 Charleston Road\nMountain View, CA 94043\n415 789 8934"
或我的个人地址详细信息到object(Cart)
然后我可以将交付详细信息显示在最终订单预览中,如下图所示:Image。 < / p>
然而,通过这种方式,订单预览中此部分的标题为Notes
,而我显然希望Delivery address
作为上面照片中显示的标题。
答案 0 :(得分:2)
根据您获得的错误,@type
的URI值看起来不正确。
由于您已经构建了ProposedObject
,因此您需要在@type: type.googleapis.com/google.actions.v2.orders.GenericExtension
的{{1}}字段内使用extension
(注意订单< / strong>在URI中)。根据您提到的docs,ProposedObject
将有一个GenericExtension
数组,其中包含locations
类型的对象,您可以在其中指定传递地址。
扩展程序的最终JSON将如下所示:
OrderLocation
其他"extension": {
"@type": "type.googleapis.com/google.actions.v2.orders.GenericExtension",
"locations": [
{
type: 'DELIVERY',
location: {
"postalAddress": {
"regionCode": "USA",
"recipients": [
"Me"
],
},
"phoneNumber": "123456789"
}
}
]
}
字段与示例中的字段相同。
有关详细信息,请参阅official sample中使用Transactions API的示例。