订单预览时未正确计算小计

时间:2018-05-22 12:29:14

标签: actions-on-google dialogflow

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

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

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

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

最终订单预览看起来像这样(这是借用Google文档示例):

enter image description here

1 个答案:

答案 0 :(得分:0)

答案似乎出现在错误消息中:API期望每个订单项的价格是该订单项中的总项目数而不是数量价格的总和(相关错误短语:&#34 ;订单项价格总和&#34;)。更正的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"
      }
    }
  }
}