Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Slack client #955

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

MattBlack85
Copy link

@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
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
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

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