slack-machine icon indicating copy to clipboard operation
slack-machine copied to clipboard

Custom Slack client

Open MattBlack85 opened this issue 7 months ago • 2 comments

This change will allow to pass an importable and valid class that will be used to initialize the base Machine class

Missing methods and additional attributes may be created and used.

It defaults to machine.clients.slack.SlackClient if there is no SLACK_CLIENT in local_settings.py

This is especially useful when in a project some more sugar around the Slack API is needed and the slack-machine default client doesn't provide such APIs

MattBlack85 avatar Jan 03 '24 11:01 MattBlack85

Hey, thanks for your contribution. I'm trying to understand the goal of this change? What do you want to achieve with the ability to pass in a custom SlackClient?

Also, the tests are failing

DonDebonair avatar Jan 04 '24 15:01 DonDebonair

hi @DonDebonair the idea is to have the capability to add some more APIs on the SlackClient itself for very specific use case instead of making standalone functions. The client is injected everywhere and this may provide a nice shortcut to use some additional APIs which are not provided out of the box by the default client. Example

class MySlackCLient(SlackClient):
    _some_fancy_cache = {}
    
    def archive_channel_by_id(self, channel):
        pass
        
    def archive_channel_by_name(self, channel):
        pass

and then in any plugin I can do

self._client.archive_channel_by_id(KAH21438)

or every custom use case one may have.

Will look into tests, I cannot guess atm what's wrong cause I am using this approach already in production and everything is working flawlessy :D maybe something related to mocking

PS: the SlackClient has some useful data already and building APIs on the top of existing API or reference data within the client itself (users, channels) is probably more concise than having to pass the client around

MattBlack85 avatar Jan 04 '24 16:01 MattBlack85