【问题标题】:Subtotal is not calculated correctly at order preview订单预览时未正确计算小计
【发布时间】:2018-05-22 12:29:13
【问题描述】:

我想用 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):

  {
    "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": []
                        },
                        "id": "<UNIQUE_ORDER_ID>",
                        "otherItems": [
                            {
                                "id": "Subtotal",
                                "name": "Subtotal",
                                "price": {
                                    "amount": {
                                        "currencyCode": "USD",
                                        "nanos": 0,
                                        "units": 62
                                    },
                                    "type": "ACTUAL"
                                },
                                "type": "SUBTOTAL"
                            },
                            {
                                "id": "Delivery fees",
                                "name": "Delivery fees",
                                "price": {
                                    "amount": {
                                        "currencyCode": "USD",
                                        "nanos": 0,
                                        "units": 10
                                    },
                                    "type": "ACTUAL"
                                },
                                "type": "FEE"
                            }
                        ],
                        "totalPrice": {
                            "amount": {
                                "currencyCode": "USD",
                                "units": 72
                            },
                            "type": "ACTUAL"
                        }
                    }
                },
                "intent": "actions.intent.TRANSACTION_DECISION"
            }
        }
    }
}

但是,我在 Google 助理模拟器上收到以下错误:

MalformedResponse
expected_inputs[0].possible_intents[0].input_value_data.transaction_decision_value_spec.proposed_order: subtotal price is not sum of regular lineItems. Expected-> Sum of line item price: units: 31 nanos: 0 currency: USD Actual-> Provided total price: units: 62 nanos: 0 currency: USD.

MalformedResponse
expected_inputs[0].possible_intents[0].input_value_data.transaction_decision_value_spec.proposed_order: total price is not sum of lineItems and otherItems. Expected-> Sum of line item price: units: 42 nanos: 0 currency: USD Actual-> Provided total price: units: 72 nanos: 0 currency: USD.

为什么我在相应的 lineItem 中指定了 "quantity": 2 后收到此错误?

很明显,小计应该是units: 62,因为我订购了"quantity": 2的产品,每个units: 31的价格...

最终的订单预览如下所示(这是从 Google 文档示例中借用的):

【问题讨论】:

    标签: actions-on-google dialogflow-es


    【解决方案1】:

    答案似乎在错误消息中:API 期望每个订单项的价格是该订单项中所有项目的总和,而不是数量价格(相关错误短语:“订单项价格总和” )。更正后的 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": 62
                        },
                        "type": "ACTUAL"
                      },
                      "quantity": 2,
                      "subLines": [],
                      "type": "REGULAR"
                    }
                  ],
                  "merchant": {
                    "id": "Amazon",
                    "name": "Amazon"
                  },
                  "otherItems": []
                },
                "id": "<UNIQUE_ORDER_ID>",
                "otherItems": [
                  {
                    "id": "Subtotal",
                    "name": "Subtotal",
                    "price": {
                      "amount": {
                        "currencyCode": "USD",
                        "nanos": 0,
                        "units": 62
                      },
                      "type": "ACTUAL"
                    },
                    "type": "SUBTOTAL"
                  },
                  {
                    "id": "Delivery fees",
                    "name": "Delivery fees",
                    "price": {
                      "amount": {
                        "currencyCode": "USD",
                        "nanos": 0,
                        "units": 10
                      },
                      "type": "ACTUAL"
                    },
                    "type": "FEE"
                  }
                ],
                "totalPrice": {
                  "amount": {
                    "currencyCode": "USD",
                    "units": 72
                  },
                  "type": "ACTUAL"
                }
              }
            },
            "intent": "actions.intent.TRANSACTION_DECISION"
          }
        }
      }
    }
    

    【讨论】:

    • 感谢您的回答@matthew。老实说,这是我写完这篇文章后实现的。但是,我希望 Google Assistant 本身会计算一件商品的总价,因为我提供了单个商品的价格和订购的商品数量。因此,这不是 Google Assistant 的选项/可能性吗? (如果不是那么显然你的答案,我也实现了,是唯一的可能性)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多