【问题标题】:How to add the delivery address details to the order preview?如何在订单预览中添加收货地址详细信息?
【发布时间】: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


    【解决方案1】:

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

    由于您已经在构建ProposedObject,因此您需要在ProposedObjectextension 字段内使用@type: type.googleapis.com/google.actions.v2.orders.GenericExtension(注意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 的示例以获取更多详细信息。

    【讨论】:

    • 感谢您的回复。但是,当我使用您的 json 时出现此错误:“抱歉,出了点问题。请稍后再试。”。 json 被处理并发送回 Google 助理,但在此之后没有任何反应,而 TRANSACTION_DECISION 应该被触发。我的印象是这与我正在使用会话 webhook 文档这一事实有关,而您正在参考 Node.js 客户端库版本 1 迁移指南,因为您使用的是订单类。任何其他想法如何解决这个问题?
    • 如果不查看您发送的对话 Webhook 请求,很难知道问题出在哪里。可以发在这里吗?我怀疑问题可能与您发送的请求有关。您可以尝试在 Actions 模拟器中对其进行故障排除 - 它会准确显示您收到的请求和响应。此外,您还可以查看日志。我认为问题不在于 Node.js 客户端库与对话 webhook,因为在文档中,每个官方文档都有相同的 @type 值。 developers.google.com/actions/reference/rest/…
    • 好的,是的,我在上面编辑了整个帖子,并在使用您的回复后发布了我所做的事情。顺便说一句,请注意,在您的 json 中,typelocation 缺少一些双引号。因此,您能从我更新的帖子中了解出了什么问题吗?
    • 我没有看到任何明显的错误。可以查看模拟器中的日志吗?
    • 我编辑了我的帖子以包含日志。事实是我在使用orders.GenericExtension 时收到此错误Sorry, something went wrong. Please try again later.,而如果我使用错误的类型,则会收到一个错误,明确表示没有这样的类型。这让我认为orders.GenericExtension 是正确的,但它与 Google 助理中的其他内容冲突,这可能与权限等有关,正如这篇文章中提到的那样:stackoverflow.com/questions/49346394/…
    猜你喜欢
    • 2011-12-11
    • 2013-04-09
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    相关资源
    最近更新 更多