通过php webhook通过api.ai回复AoG上的基本卡

时间:2017-07-14 17:35:03

标签: php dialogflow actions-on-google

我正在尝试使用我的webhook服务创建一张卡片。我的网站是在PHP但我不知道如何回应api.ai以在客户的手机上以卡片格式显示我的结果。我在here中详细询问了我的问题。

1 个答案:

答案 0 :(得分:3)

  

考虑到,您知道从php

中的Api.ai请求接收和检查操作

要使用该卡进行回复,您可以使用:

$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);

请确保您不要推送多张卡并对其进行“简单回复”。