errbotio / err-backend-slackv3

Slack Events and RTM backend for Errbot
GNU General Public License v3.0
27 stars 28 forks source link

Send cards to threads, when asked #76

Closed TheJokersThief closed 2 years ago

TheJokersThief commented 2 years ago

What

Why

Cards can be pretty big, it's nice to keep them limited to threads when appropriate.

Example Usage

If the message it received was part of a thread, it will respond in a thread.

@botcmd
def hello(self, msg, args):
    """Say hello to someone"""
    return_msg = Card(
        to=msg.frm,
        title="Hello, world",
        parent=msg.parent if msg.parent else None,
    )

    self._bot.send_card(return_msg)

Or if you wanted to default to sending a threaded message, you could make the parent the received message:


@botcmd
def hello(self, msg, args):
    """Say hello to someone"""
    return_msg = Card(
        to=msg.frm,
        title="Hello, world",
        parent=msg
    )

    self._bot.send_card(return_msg)
``
sijis commented 2 years ago

Could you show an example of code of how this change is supposed to be used?

TheJokersThief commented 2 years ago

It's the same principle as send_message, so they're not dissimilar :)

If the message it received was part of a thread, it will respond in a thread.

@botcmd
def hello(self, msg, args):
    """Say hello to someone"""
    return_msg = Card(
        to=msg.frm,
        title="Hello, world",
        parent=msg.parent if msg.parent else None,
    )

    self._bot.send_card(return_msg)

Or if you wanted to default to sending a threaded message, you could make the parent the received message:


@botcmd
def hello(self, msg, args):
    """Say hello to someone"""
    return_msg = Card(
        to=msg.frm,
        title="Hello, world",
        parent=msg
    )

    self._bot.send_card(return_msg)
``
nzlosh commented 2 years ago

Thank you for the contribution.