Facebook Messenger 机器人通用模板不起作用

Facebook messenger bot generic template not working

我正在使用 api.ai 构建一个 Facebook 机器人,我已经到了需要使用 Facebook 通用模板发送响应的地步。我从数据库中获取要列出的项目列表并将它们放入一个数组中并分配给一个变量。我的问题是数据实际上如 Ngrok 所示返回,但它没有作为通用模板显示在 Facebook 上。没有显示。这是我的代码。

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; 
            }

我解决了。应该是:

"elements"=> $array