I use webhooks to send messages through the Slack API
I need to send a button with a link to the report
I have successfully dealt with Python
But with PHP I am having problems with arrays of actions in attachments
code 1
$data = array(
"text" => $message
);
$actions =
[
'type' => "button",
'text' => "Report1",
'url' => "https://url.report1"
];
$data += [
"attachments" =>
[
"fallback" => "More details...",
'actions' => [$actions]
]
];
$payload = json_encode($data);
print_r($data) conclusion:
Array
(
[text] => teste
[attachments] => Array
(
[fallback] => More details...
[actions] => Array
(
[0] => Array
(
[type] => button
[text] => Report1
[url] => https:
)
)
)
)
Paylod is displayed, but the button is not
code 2
$data = array(
"text" => $message
);
$actions =
[
'type' => "button",
'text' => "Report1",
'url' => "https://url.report1"
];
$data += [
"attachments" =>
[
"fallback" => "More details...",
'actions' => $actions
]
];
$payload = json_encode($data);
print_r($data) conclusion:
Array
(
[text] => teste
[attachments] => Array
(
[fallback] => More details...
[actions] => Array
(
[type] => button
[text] => Report1
[url] => https:
)
)
)
Neither useful data nor buttons are displayed
Here is a sample documentation, it is very easy to send this using python
{
"text": "<@W1A2BC3DD> approved your travel request. Book any airline you like by continuing below.",
"attachments": [
{
"fallback": "Book your flights at https://flights.example.com/book/r123456",
"actions": [
{
"type": "button",
"text": "Book flights 🛫",
"url": "https://flights.example.com/book/r123456"
}
]
}
]
}
How can I create such a structure in PHP?