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

Feature Request: Please consider implementing 'snippet' support for the Slack connector #1611

Closed
law opened this issue Aug 3, 2020 · 5 comments · Fixed by #2020
Closed

Comments

@law
Copy link
Contributor

law commented Aug 3, 2020

Description

I'm developing a skill that occasionally will return a LARGE amount of text. Rather than flood the public room, it would be nice if the Opsdroid Slack connector had the ability to send a message as a 'snippet' so a small preview of the larger output would be shown, and users would have the ability to click through to see the full data-dump.

Steps to Reproduce

Right now, await message.respond(f"regular message") only sends a regular Slack message. There is the ability to send 'rich' messages with event.respond(Blocks([])), but an event.respond(Snippet([])) that utilizes the https://api.slack.com/types/file type or similar would be ideal.

Expected Functionality

Opsdroid should have the option of sending large messages as a 'snippet' or 'file' type, for cleaner displays of large amounts of data in public channels.

  • Opsdroid version: 0.19.0
  • Python version: 3.8.4
  • OS/Docker version:

Additional Details

Any other details you wish to include such as screenshots, console messages, etc.

@FabioRosado
Copy link
Member

I have just recently written a quick thing using NLTK to get a summary/snippet of a large block of text. I wonder if this should be done on a skill level - although I'm not sure how that would work... Maybe we could create an event that is fired when the text has more than x number of lines? 🤔

Unless you don't really care as much about a summary of that large block of test and instead you just want the first x words of the test? 🤔

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Aug 4, 2020

I think in this case we want to upload the text to Slack as a File object. In Slack a text file under 1MB is referred to as a snippet and is previewed in the chat.

We already have the File event which represents bytes objects

opsdroid/opsdroid/events.py

Lines 336 to 337 in 1e1544d

class File(Event):
"""Event class to represent arbitrary files as bytes."""

We should add a new handler to the Slack connector which can send File events. Something like this.

    @register_event(opsdroid.events.File)
    async def _send_file(self, file_event):
        return await self.slack.api_call(
            "files.upload",
            data={"channels": file_event.target, "content": await file_event.get_file_bytes(), "filetype": await file_event.get_mimetype(), "filename": file_event.name},
        )

Then in order to send this from your skill you would need to construct a File event with a bytearray of the text.

await message.respond(File(file_bytes=f"my long string".encode("utf-8"), mimetype="text", name="mysnippet.txt"))

This would allow the use case here of sending long messages as snippets, but also uploading of files in general.

We could also add a Snippet event to opsdroid.connector.slack.events which subclasses File and provides a nicer interface for converting to bytes, setting the mimetype, etc.

await message.respond(Snippet(f"my long string", type="text"))

Allowing the type to be set means that the user could specify the Slack file type. Perhaps auto would be a sensible default here.

@vxe
Copy link

vxe commented Dec 14, 2022

is uploading files as snippets still on the roadmap?

@pmaresca
Copy link
Contributor

I'm attempting to take a stab at this, we'll see how it goes

@pmaresca
Copy link
Contributor

@jacobtomlinson I put together a small PR based on your input, any additional feedback/guidance you have would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants