php-slack / slack

A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax.
BSD 2-Clause "Simplified" License
135 stars 27 forks source link

Sections /w Fields should not have a top level "text" key. Fatal error is generated #48

Closed ewartx closed 4 years ago

ewartx commented 4 years ago

src/Block/Section.php line 146

$data = [
    'type' => $this->getType(),
    'text' => $this->getText()->toArray();
];

Suggestion, add a check

if ( $this->getText() ) {
       $data['text'] = $this->getText()->toArray();
}
cmbuckley commented 4 years ago

The text is required when there are no fields, but is optional when fields are present. So a section may have both attributes, but needs to throw an Exception when there are neither.

ewartx commented 4 years ago

I see. However, the fatal error was thrown when I had fields present. So something is missing here.

cmbuckley commented 4 years ago

Yes, see the link above my comment, #49. That adds the null check and Exception