jolicode / slack-php-api

:hash: PHP Slack Client based on the official OpenAPI specification
https://jolicode.github.io/slack-php-api/
MIT License
223 stars 56 forks source link

Files array missing from messages in channels.history #21

Closed kylelondonuk closed 5 years ago

kylelondonuk commented 5 years ago

Hi,

When I load messages from a channel using:

$announcements = $client->channelsHistory(['channel' => 'CHANNEL_ID', 'count' => 5])->getMessages();

the array I get back has a private 'storage' array with the 'files' array inside it, instead of just having a 'files' array. When I use the API tester here it's all fine: https://api.slack.com/methods/channels.history/test

So i think it's something to do with the normalizer or PHP conversion?

damienalexandre commented 5 years ago

Ok so in the official specification I see this:

https://github.com/slackapi/slack-api-specs/blob/fbfd2921822d4d7846491f863025dc3043fa85c2/web-api/slack_web_openapi_v2.json#L4454-L4480

On the messages I see a "file" but no "files":

https://github.com/slackapi/slack-api-specs/blob/fbfd2921822d4d7846491f863025dc3043fa85c2/web-api/slack_web_openapi_v2.json#L1367-L1369

There is no "files" in the specification, but as you found, there is one on the API. That's something we can fix via patches.

The "storage" you saw is a standard PHP ArrayObject, so you can access files via $response['files']. So even data not mapped to real objects can be read.

kylelondonuk commented 5 years ago

Hi thanks Damien. Yes I read the bit on items missing from the spec and patches, so I thought this must be that. However, I tried accessing the files array, but it comes back as a private PHP ArrayObject, so I can't. Do I have to access it in the response before the PHP object normalization occurs?

damienalexandre commented 5 years ago

Thanks for your patience here.

I'm not able to reproduce, could you show a full var_dump of the resource you got? Could you call getArrayCopy() on the ObjsMessage?

Have you check ArrayObject documentation? https://www.php.net/manual/en/class.arrayobject.php Because from where I stand you should be able to get that data.

kylelondonuk commented 5 years ago

Hi Damien, I actually decided to just use cURL to access the API directly, because our requirements were very simple (just 2 endpoints). So I don't have the PHP api installed on the site anymore, and it's gone live so I can't add it back to help you test, I'm sorry.

If it helps: the raw responses from the API are definitely fine, just something happened in normalization or conversion to PHP, which made the files array a private array I couldn't access. My assumption was that any "extra data" that comes back from the API (which wasn't explicitly defined in the auto-generated Jane files), got marked private as a kind of safety, because it didn't know what to do with that data?

damienalexandre commented 5 years ago

Ok, glad you didn't got stuck :grimacing:

I'm keeping this issue open:

Cheers

kylelondonuk commented 5 years ago

Great - hope I helped :)

damienalexandre commented 5 years ago

Just so you know, this has been fixed :tada: and the "files" property is now mapped to DTO.

I also added documentation about how to get not mapped data: https://github.com/jolicode/slack-php-api#missing-data-in-the-dto