多重阵列正确安排JSON_ENCODE

时间:2018-02-10 08:28:49

标签: php json multidimensional-array facebook-messenger-bot

我正确地做这个数组吗?

这是facebook开发人员在messenger bot中的示例API

'{
  "recipient":{
    "id":"<PSID>"
  },
  "message":{
    "attachment":{
      "type":"template",
      "payload":{
        "template_type":"generic",
        "elements":[
           {
            "title":"Welcome to Peter'\''s Hats",
            "image_url":"https://petersfancybrownhats.com/company_image.png",
            "subtitle":"We'\''ve got the right hat for everyone.",
            "default_action": {
              "type": "web_url",
              "url": "https://peterssendreceiveapp.ngrok.io/view?item=103",
              "messenger_extensions": true,
              "webview_height_ratio": "tall",
              "fallback_url": "https://peterssendreceiveapp.ngrok.io/"
            },
            "buttons":[
              {
                "type":"web_url",
                "url":"https://petersfancybrownhats.com",
                "title":"View Website"
              },{
                "type":"postback",
                "title":"Start Chatting",
                "payload":"DEVELOPER_DEFINED_PAYLOAD"
              }              
            ]      
          }
        ]
      }
    }
  }
}

&#39;

我需要它看起来像这样。所以我做得对吗?

 $response = [
    'recipient' => [ 'id' => $senderId ],
    'message' => [ 
        'attachment' => [ 
            'type' => 'template',
            'payload' => [
                'template_type' => 'generic',
                'elements' => [
                    'title' => $item_name,
                    'image_url' => $item_photo_url,
                    'subtitle' => $item_description,
                    'default_action' => [
              'type' => 'web_url',
              'url' => 'https://peterssendreceiveapp.ngrok.io/view?item=103',
              'messenger_extensions' => true,
              'webview_height_ratio' => 'tall',
              'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/'
            ],
            'buttons' => [
               [
                'type' => 'web_url',
                'url' => 'https://petersfancybrownhats.com',
                'title' => 'View Website'
              ],[
                'type' => 'postback',
                'title' => 'Start Chatting',
                'payload' => 'DEVELOPER_DEFINED_PAYLOAD'
              ]              
            ]
                    ],
                ],
            ]
        ]
];

请帮我安排。

这是信使平台API,用于通过模板附件的信使回复。

我正在尝试回复我的用户,而不是只回复文本我想在模板中回复。喜欢ptoho和描述

0 个答案:

没有答案