Skip to content

Conversation

@Ashex
Copy link
Collaborator

@Ashex Ashex commented Apr 7, 2021

Resolves #429

Incorporate logic from #369 for sending direct messages and adding some logic to allow passing a user id into send_file that will trigger opening a direct message channel. This PR also adds support for handling messages from bots and webhooks.

Example code:

    @respond_to(r"send me a file")
    def test_send_file(self, message):
        """give me a file: Just send a file for testing."""
        r = requests.get('https://gist.githubusercontent.com/Ashex/703ef3311bcb4fa50d1268303f5b08ab/raw/87159c75045d723908488c0e9ce99774858f7fb2/guide.md')
        self.send_file(message=message, content=r.text, filename='readme.md', text='Here is your file!', 
                       filetype='text/markdown', is_direct=True, channel=self.get_user_id(message.sender.handle))

    def get_user_id(self, user_id):
        people_cache = self.load('slack_people_cache', {})
        for k, c in people_cache.items():
            if user_id == c.handle:
                logging.info(f'Found {c.id}')
                return c.id

Very open to feedback on this implimentation.

CC: @pastorhudson

@Ashex Ashex added this to the 2.2 milestone Apr 7, 2021
@Ashex Ashex merged commit 9710692 into master Apr 13, 2021
@Ashex Ashex deleted the file_dm_support branch April 13, 2021 10:31
Ashex added a commit that referenced this pull request Feb 5, 2022
* Support sending files directly to user via direct message

* Cleaning filenames caused files to lose extension

* Update Authors, added @BrianGallew
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.

Support unsolicitied direct file uploads

3 participants