fork(5) download
  1. <?php
  2. define(SITE_ROOT_URL, "http://w...content-available-to-author-only...e.com/");
  3. $array = array('hits' => array ( 0 => array ( 'ID' => '69', 'Title' => 'This is an example', 'URL' => 'example/1', 'Detail' => 'Some description here...', 'image' => 'image1.png', 'objectID' => '75877631') ));
  4.  
  5. $messages = array();
  6. foreach ($array['hits'] as $key => $value) {
  7. $messages[] = array(
  8. 'title' => $value['Title'],
  9. 'image_url' => $value['image'],
  10. 'subtitle' => substr($value['Detail'], 0, 120),
  11. 'buttons' => array(
  12. 'type' => 'web_url',
  13. 'url' => SITE_ROOT_URL.$value['URL'].'?utm_source=chatbot',
  14. 'title' => "Leia mais"
  15. )
  16. )
  17. );
  18. }
  19. $result = array(
  20. 'messages' => array(
  21. 'attachment' => array(
  22. 'type' => 'template',
  23. 'payload' => array(
  24. 'template_type' => 'generic',
  25. 'elements' => $messages
  26. )
  27. )
  28. )
  29. );
  30. echo json_encode($result, JSON_PRETTY_PRINT);
Success #stdin #stdout #stderr 0.01s 52488KB
stdin
Standard input is empty
stdout
{
    "messages": {
        "attachment": {
            "type": "template",
            "payload": {
                "template_type": "generic",
                "elements": [
                    {
                        "title": "This is an example",
                        "image_url": "image1.png",
                        "subtitle": "Some description here...",
                        "buttons": [
                            {
                                "type": "web_url",
                                "url": "http:\/\/www.example.com\/example\/1?utm_source=chatbot",
                                "title": "Leia mais"
                            }
                        ]
                    }
                ]
            }
        }
    }
}
stderr
PHP Notice:  Use of undefined constant SITE_ROOT_URL - assumed 'SITE_ROOT_URL' in /home/EZBI6X/prog.php on line 2