2017-04-24 4 views
1

저는 api.ai를 사용하여 Facebook 봇을 구축 중이며 Facebook 일반 템플릿을 사용하여 응답을 보내야하는 시점에 도달했습니다. 데이터베이스에서 나열된 항목 목록을 가져 와서 배열에 넣고 변수에 할당합니다. 내 문제는 데이터가 Ngrok에 표시된 것처럼 실제로 반환되지만 페이스 북에는 일반 템플릿으로 표시되지 않는다는 것입니다. 아무것도 보여주지 않습니다. 여기 내 코드가있다.페이스 북의 메신저 봇 일반 템플릿이 작동하지 않습니다.

while($result = mysqli_fetch_assoc($res)){ 
        $array[] = array(

          "title"=> $result['title'], 
           "image_url"=> $result['img_url'], 
           "subtitle"=> "See all our colors", 
           "buttons"=>[ 
             [ 
             "type"=>"postback", 
             "title"=>$result['title'], 
             "payload"=>$result['payload_id'] 
             ] 
           ] 
        ); 

       } 

      if ($intentName == "sex"){ 
        $data =json_encode([ 
        'speech' => "Hi ".$firstname, 
        'displayText' => "test", 
        'source' => "source", 
        'data' => ["facebook" => [ 
         "attachment"=>[ 
         "type"=>"template", 
         "payload"=>[ 
         "template_type"=>"generic", 
         "elements"=>[ 
         //One attachment 
         $array 
         //First attachment ends 

         ] 
        ] 
        ] ] 
       ] 

       ]); 
        echo $data; 
      } 

답변

1

나는 그것을 풀었다. 다음과 같아야합니다.

"elements"=> $array 
관련 문제