Skip to content

Custom Slack client#955

Open
MattBlack85 wants to merge 1 commit intoDonDebonair:mainfrom
MattBlack85:patch-1
Open

Custom Slack client#955
MattBlack85 wants to merge 1 commit intoDonDebonair:mainfrom
MattBlack85:patch-1

Conversation

@MattBlack85
Copy link
Copy Markdown

@MattBlack85 MattBlack85 commented Jan 3, 2024

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


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
@DonDebonair
Copy link
Copy Markdown
Owner

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

@MattBlack85
Copy link
Copy Markdown
Author

MattBlack85 commented Jan 4, 2024

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

@DonDebonair DonDebonair force-pushed the main branch 2 times, most recently from ce5a823 to 52a3294 Compare May 25, 2024 21:28
@DonDebonair
Copy link
Copy Markdown
Owner

Hey @MattBlack85 do you still want this feature? If so, can you rebase your branch, fix the tests etc.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants