jolicode / slack-php-api

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

Added metadata definition for chat.postMessage and history #156

Closed tchapuis closed 8 months ago

tchapuis commented 1 year ago

The Slack documentation says that we can include metadata in chat.postMessage arguments. See : https://api.slack.com/metadata

OpenApi spec for this argument doesn't seem to be up to date.

So I added it to the patched version for message definition and chat.postMessage method. I also added the include_all_metadata argument for the conversations.history method

yngc0der commented 8 months ago

The temporary solution is create a custom endpoint class, and use this class to call api method:

<?php

use JoliCode\Slack\Api\Endpoint\ChatPostMessage;

final class FixedChatPostMessageEndpoint extends ChatPostMessage
{
    protected function getFormOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
    {
        $optionsResolver = parent::getFormOptionsResolver();
        $optionsResolver->setDefined(['metadata']);
        $optionsResolver->setAllowedTypes('metadata', ['string']);
        return $optionsResolver;
    }
}

$slack->executeEndpoint(new FixedChatPostMessageEndpoint([
    'channel' => $channel,
    'text' => $text,
    'metadata' => $metadata,
]));
tchapuis commented 8 months ago

Hello, The patch file was a pain to get it right 😅

damienalexandre commented 8 months ago

Thanks for working on this!

Tests on main were red, so I fixed them in https://github.com/jolicode/slack-php-api/pull/162 ; could you please:

And push?

damienalexandre commented 8 months ago

Awesome, thank you so much!

damienalexandre commented 8 months ago

Version v4.6.0 is published!