通过 api.ai 从 php webhook 响应 AoG 上的基本卡

Responding with basic card on AoG from php webhook through api.ai

我正在尝试使用我的 webhook 服务创建一张卡片。我的网站在 php,但我不知道如何响应 api.ai 以在客户 phone 上以卡片格式显示我的结果。我在 here.

中更详细地询问了我的问题

Considering, you know receiving and checking action from Api.ai request in php

要用卡片回复,您可以使用:

$request== file_get_contents("php://input");
$messages=[];
// Building Card
 array_push($messages, array(
    "type"=> "basic_card",
    "platform"=> "google",
    "title"=> "Card title",
    "subtitle"=> "card subtitle",
    "image"=>[
      "url"=>'http://image-url',
      "accessibility_text"=>'image-alt'
      ],
      "formattedText"=> 'Text for card',
      "buttons"=> [
        [
          "title"=> "Button title",
          "openUrlAction"=> [
            "url"=> "http://url redirect for button"
            ]
          ]
        ]
      )
   );
  // Adding simple response (mandatory)
  array_push($messages, array(
     "type"=> "simple_response",
     "platform"=> "google",
     "textToSpeech"=> "Here is speech and additional msg for card"
    )
  );
  $response=array(
          "source" => $request["result"]["source"],
          "speech" => "Speech for response",
          "messages" => $messages,
          "contextOut" => array()
      );
 json_encode($response);

确保你推的牌不超过一张,并且有'simple response'。