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

Support Slack Blocks #9

Closed
nzlosh opened this issue Mar 20, 2019 · 4 comments
Closed

Support Slack Blocks #9

nzlosh opened this issue Mar 20, 2019 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@nzlosh
Copy link
Owner

nzlosh commented Mar 20, 2019

Add support to the backend chat adapter. This feature may also require updating errbot's slack backend code.

https://api.slack.com/messaging/attachments-to-blocks

@nzlosh nzlosh added enhancement New feature or request help wanted Extra attention is needed labels Mar 20, 2019
@nzlosh
Copy link
Owner Author

nzlosh commented May 14, 2019

@nzlosh
Copy link
Owner Author

nzlosh commented May 14, 2019

@bloodywing
Copy link

from errbot import BotPlugin
from errbot.backends.base import Identifier
from pprint import pformat

class SlackBlocks(BotPlugin):

    def block(self, to: Identifier, blocks: []):
        self.log.debug('blocks: %s' % pformat(blocks))
        if self._bot.mode == 'slack':
            self._bot.api_call('chat.postMessage', data={
                'channel': to,
                'as_user': True,
                'attachments': [
                    {
                        "blocks": blocks
                    }
                ]
            })

I made a plugin which does something like that, it takes the blocks as dictionary. Slack is a bit wonky regarding the blocks and empty strings cause issues. I'll make it a full plugin when I tested this more. The to parameter is something like: self.build_identifier('#mychannel') When you write your plugin use the SlackBlocks as DependsOn and you can use it in your own Plugin.

The blocks list is what Slack shows you in the blockbuilder on their site.

@nzlosh
Copy link
Owner Author

nzlosh commented Mar 17, 2021

@bloodywing Thank you for sharing your implementation. 👍 I finally got around to implementing this and your example was useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants