title: Message formatting, send buttons via Slack API with PHP
body: <p>I'm using webhooks to send messages via Slack API</p>
  <p>I need to send a button with a link to a report</p>
  <p>I did it with Python successfully</p>
  <p>But with PHP i'm having trouble with the arrays of actions in the attachments</p>
  <h1>code 1</h1>
  <pre><code>$data = array(
          &quot;text&quot; =&gt; $message
      );
  
      $actions =
          [
              'type' =&gt; &quot;button&quot;,
              'text' =&gt; &quot;Report1&quot;,
              'url' =&gt; &quot;https://url.report1&quot;
          ];
  
      $data += [
          &quot;attachments&quot; =&gt;
              [
                  &quot;fallback&quot; =&gt; &quot;More details...&quot;, //I only get the message and this text in the slack
                  'actions' =&gt; [$actions] // or array($actions) 
  
              ]
      ];
  
      $payload = json_encode($data);
  </code></pre>
  <p><code>print_r($data)</code> output:</p>
  <pre><code>Array
  (
      [text] =&gt; teste
      [attachments] =&gt; Array
          (
              [fallback] =&gt; More details... 
              [actions] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [type] =&gt; button
                              [text] =&gt; Report1
                              [url] =&gt; https://url.report1
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  <p>The paylod is shown, but the button doesn't</p>
  <h1>code 2</h1>
  <pre><code>$data = array(
          &quot;text&quot; =&gt; $message
      );
  
      $actions =
          [
              'type' =&gt; &quot;button&quot;,
              'text' =&gt; &quot;Report1&quot;,
              'url' =&gt; &quot;https://url.report1&quot;
          ];
  
      $data += [
          &quot;attachments&quot; =&gt;
              [
                  &quot;fallback&quot; =&gt; &quot;More details...&quot;,
                  'actions' =&gt; $actions
  
              ]
      ];
  
      $payload = json_encode($data);
  </code></pre>
  <p><code>print_r($data)</code> output:</p>
  <pre><code>Array
  (
      [text] =&gt; teste
      [attachments] =&gt; Array
          (
              [fallback] =&gt; More details...
              [actions] =&gt; Array
                  (
                      [type] =&gt; button
                      [text] =&gt; Report1
                      [url] =&gt; https://url.report1
                  )
  
          )
  
  )
  </code></pre>
  <p>Neither payload or button are showed</p>
  <p>Here's the documentation example, it's very easy to send this with <a href="https://github.com/guilhermebferreira/slack_webhooks/blob/master/webhook-message_with_buttons.ipynb" rel="nofollow noreferrer">python</a></p>
  <pre><code>{
      &quot;text&quot;: &quot;&lt;@W1A2BC3DD&gt; approved your travel request. Book any airline you like by continuing below.&quot;,
      &quot;attachments&quot;: [
          {
              &quot;fallback&quot;: &quot;Book your flights at https://flights.example.com/book/r123456&quot;,
              &quot;actions&quot;: [
                  {
                      &quot;type&quot;: &quot;button&quot;,
                      &quot;text&quot;: &quot;Book flights &quot;,
                      &quot;url&quot;: &quot;https://flights.example.com/book/r123456&quot;
                  }
              ]
          }
      ]
  }
  </code></pre>
  <p>How I can create this kind of structure in PHP?</p>