如何在订单预览时更改芯片建议?

2024-05-15 17:46:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用DialogflowGoogle Assistant以及Google Transactions API创建一个聊天机器人,让用户能够订购巧克力盒。目前,我的代理人有以下四个意图:

  • Default Welcome Intent(短信回复:你好,你想买巧克力盒吗?)你知道吗
  • Default Fallback Intent
  • Int1(培训短语:是,我想要,实现:启用webhook调用)
  • Int2(事件:actions_intent_TRANSACTION_REQUIREMENTS_CHECK

我使用Dialogflow Json而不是Node.js将代理与事务API连接起来。我想通过使用googleactions的actions.intent.TRANSACTION_REQUIREMENTS_CHECK操作来呈现订单预览(在订购巧克力盒时)。因此,在Google docs之后,当触发Int1时,我使用一个webhook将Google Assistant连接到以下python脚本(后端):

from flask import Flask, render_template, request, jsonify
import  requests

app = Flask(__name__)

@app.route("/",  methods=['POST'])
def index():

    data = request.get_json()    
    intent = data["queryResult"]["intent"]["displayName"]

    if (intent == 'Int1'):

        proposedOrder = order.proposed_order(location)

        return jsonify({
                    "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": proposedOrder

                                  },
                                    "intent": "actions.intent.TRANSACTION_DECISION"
                                }
                              }
                    }
                    })


if __name__== "__main__":
    app.run(debug=True)

其中proposed_order是我在模块order中编写的一个函数,它以googledocs指定的所需方式形成用户的顺序。你知道吗

intent == 'Int1'时,这将向用户(在移动电话Google Assistant上)呈现订单预览,如下所示(示例来自Google docs):

enter image description here

如您所见,在订单预览的底部有三个芯片建议:下订单更改付款方式无所谓

我的问题是:如何(以编程方式)编辑这些芯片建议并添加我的建议(例如,添加一个芯片建议“更改订购的项目数”


Tags: 用户订单actionstrueappdatagoogle方式