gpt4 book ai didi

actions-on-google - 如何在订单预览中添加收货地址详情?

转载 作者:行者123 更新时间:2023-12-01 14:33:48 25 4
gpt4 key购买 nike

我想使用 Dialogflow 和 Google Assistant 以及 Google Transactions API 创建一个聊天机器人,让用户能够订购一些商品。目前我的代理包含以下四个意图:

  • 默认欢迎意图(文本响应:你好,你想买巧克力盒吗?)
  • 默认后备意图
  • Int3(训练短语:Yes, I want, fulfilment: enabled webhook)
  • Int4(事件:actions_intent_TRANSACTION_DECISION,实现:已启用 webhook)

我使用 Dialogflow Json 而不是 Node.js 将我的代理与交易 API 连接起来。我想通过最终使用 Google 操作的 actions.intent.TRANSACTION_DECISION 操作满足用户满足交易要求,从而为用户构建购物车和订单。出于这个原因,按照 Google 文档,当 Int3 被触发时,我正在使用连接 Google Assistant 我的后端的 webhook,它发回以下 json 以触发 actions.intent.TRANSACTION_DECISION.

因此,订单预览会在 Google 智能助理(在手机上)上呈现给用户。但是,此订单预览中未显示送货地址详细信息,如下图所示。

请注意,我已经转到 Google Assistant 应用 -> 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 Assistant 模拟器上收到此错误:

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 文档的订单预览示例,其中包括送货地址详细信息: enter image description here

附言object(Cart) 包含 "notes": string,它可以在最终订单预览中添加一个部分,恰好在交货地址部分放置在订单预览中的位置上面的照片。因此,我可以添加

"notes": "Lola\n1950 Charleston Road\nMountain View, CA 94043\n415 789 8934"

或我的个人地址详细信息object(Cart),然后我可以将交货详细信息显示到最终订单预览中,如下图所示:Image

然而,在订单预览中,这部分的标题是 Notes,而我显然想要 Delivery address 作为标题,因为它显示在上面的照片。

最佳答案

根据您遇到的错误,@type 的 URI 值似乎不正确。

由于您已经在构建一个ProposedObject,您将需要使用一个@type: type.googleapis.com/google.actions.v2.orders.GenericExtensionProposedObjectextension 字段内(注意 URI 中的 orders)。根据您提到的 docsGenericExtension 将有一个 locations 数组,其中包含一个 OrderLocation 类型的对象,您可以在其中指定送货地址。

扩展的最终 JSON 如下所示:

"extension": {
"@type": "type.googleapis.com/google.actions.v2.orders.GenericExtension",
"locations": [
{
type: 'DELIVERY',
location: {
"postalAddress": {
"regionCode": "USA",
"recipients": [
"Me"
],
},
"phoneNumber": "123456789"
}
}
]
}

ProposedOrder 字段的其余部分将与示例中的相同。

有关详细信息,请参阅 official sample 中使用事务 API 的示例。

关于actions-on-google - 如何在订单预览中添加收货地址详情?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50408893/

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