如何将送货地址详细信息添加到订单预览中? [英] How to add the delivery address details to the order preview?

查看:82
本文介绍了如何将送货地址详细信息添加到订单预览中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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




  • 默认欢迎意图(文本回复:您好,您想购买一个巧克力盒吗?)

  • 默认后备意图

  • 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 Assistant上向用户显示(在移动设备上电话)。但是,送货地址的详细信息未在此订单预览中显示,如下图所示。



让我注意,我已经去过 Google助手应用-> 设置-> 付款,然后在此填写我的地址详细信息。结果,当我触发 actions.intent.DELIVERY_ADDRESS 意图时,按预期方式我得到了 Google Assistant应用-> 设置-> 付款,如下图所示:



PS object(Cart)包含 notes:字符串,可在最终订单预览中的确切位置添加一个部分交货地址部分位于上图的订单预览中。因此,我可以添加



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



或我的个人地址详细信息对象(购物车),然后我可以将交货详细信息显示到最终订单预览,如下图所示:图片



但是,通过这种方式,订单预览中本节的标题为注释,而我显然希望收货地址作为标题,如上图所示。

解决方案

根据收到的错误, @type 的URI值似乎是不正确



由于您已经在构建 ProposedObject ,因此您需要使用 @在扩展名字段内输入type.googleapis.com/google.actions.v2.orders.GenericExtension ProposedObject (请注意URI中的订单)。根据您提到的文档 GenericExtension 将具有一个位置数组,其中将包含一个 OrderLocation 类型的对象指定送货地址。



扩展的最终JSON如下:

 扩展名:{
@type: type.googleapis.com/google.actions.v2.orders.GenericExtension,
位置:[
{
类型:交付,
位置:{
postalAddress:{
regionCode: USA,
收件人:[

],
},
phoneNumber: 123456789
}
}
]
}

ProposedOrder 其余字段与你的例子



请在官方示例以获取更多详细信息。


I want to create a chatbot with Dialogflow and Google Assistant along with Google Transactions API for enabling a user to order some items. For now my agent contains the following four intents:

  • Default Welcome Intent (text response: Hello, do you want to buy a chocolate box?)
  • Default Fallback Intent
  • Int3 (training phrase: Yes, I want, fulfilment: enabled webhook)
  • Int4 (event: actions_intent_TRANSACTION_DECISION, fulfilment: enabled webhook)

I am using Dialogflow Json instead of Node.js to connect my agent with Transactions API. I want to build a cart and an order for the user by using finally that the user meets the transaction requirements by using the actions.intent.TRANSACTION_DECISION action of Google actions. For this reason, following Google docs, when Int3 is triggered I am using a webhook which connect Google Assistant my back-end which sends back the following json to trigger actions.intent.TRANSACTION_DECISION.

As a result, the preview of the order is presented to the user on Google Assistant (on mobile phone). However, the delivery address details are not presented on this order preview as at the photo below.

Let me note that I have already gone to Google Assistant app -> Settings -> Payments and there I filled in my address details. As a result, when I trigger the actions.intent.DELIVERY_ADDRESS intent then as expected I get the delivery address of Google Assistant app -> Settings -> Payments as this is shown at this image: Image. Therefore, it is not that I anticipated that my delivery address will appear on the order preview out of nowhere without having set it first of all.

I have the impression that this can be done by adding the extension object to the whole structure of ProposedOrder object which is the following:

{   "id": string,   
"cart": {
        object(Cart)   },  
 "otherItems": [
        {
          object(LineItem)
        }   ],   "image": {
        object(Image)   },   
"termsOfServiceUrl": string,   
"totalPrice": {
        object(Price)   },   
"extension": {
        "@type": string,
        field1: ...,
        ...   } }

So the whole json response through my webhook to trigger actions.intent.TRANSACTION_DECISION is the following:

{
    "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"
            }
        }
    }
}

but then I am getting this error on the Google Assistant simulator:

Sorry, something went wrong. Please try again later.

So I cannot really understand if I am not doing something right regarding the type and the format of the extension object.

The logs at Google Assistant in this case are the following:

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:  "**************************"  
}

How to add the delivery address details to the order preview?

This is an example of an order preview from Google docs which includes delivery address details:

P.S. The object(Cart) contains the "notes": string which can add a section at the final order preview exactly where the Delivery address section is placed at the order preview at the photo above. Therefore, I can add

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

or my personal address details to the object(Cart) and then I can display the delivery details to the final order preview as it is shown at this image: Image.

However in this way the title of this section at the order preview is Notes while I want obviously Delivery address as the title as it it shown at the photo above.

解决方案

Based on the error you're getting, it looks like the URI value for @type is incorrect.

Since you're already building a ProposedObject, you will need to use a @type: type.googleapis.com/google.actions.v2.orders.GenericExtension inside of the extension field of the ProposedObject (note orders in the URI). Per the docs you mentioned, GenericExtension will have a locations array that will contain an object of type OrderLocation where you can specify the delivery address.

The final JSON for an extension will look like:

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

The rest of ProposedOrder fields will be the same as in your example.

Please see an example of using Transactions API in the official sample for more details.

这篇关于如何将送货地址详细信息添加到订单预览中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆