errbotio / err-backend-slackv3

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

`send_card` is only in-thread while `send_stream_request` is only in-channel #93

Open torgeirl opened 2 years ago

torgeirl commented 2 years ago

send_card (and send_stream_request) used to not reply in-thread (Errbot #1549), but within the last few months send_card is suddenly only reply in-thread when invoked.

As noted by @nzlosh this repo have recently made changes to its send_card implimentation:

This sounds specific to the slack backend, which was patched to reply to threads here errbotio/err-backend-slackv3#76

Do you mind opening an issue under the slackv3 repository please?

torgeirl commented 10 months ago

Had another look at this after upgrading to Errbot 6.2.0, and when attempting to provide card.parent, as exemplified by @TheJokersThief in #76 ...

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

... I get an error stating that send_card() doesn't have a parent keyword argument:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/errbot/core.py", line 574, in _execute_and_send
    reply = method(msg, match) if match else method(msg, args)
                                             ^^^^^^^^^^^^^^^^^
  File "/app/plugins/tradingpost-errbot/tradingpost.py", line 40, in card
    self.send_card(title=card['name'],
TypeError: BotPlugin.send_card() got an unexpected keyword argument 'parent'
"
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/errbot/core.py", line 574, in _execute_and_send
    reply = method(msg, match) if match else method(msg, args)
                                             ^^^^^^^^^^^^^^^^^
  File "/app/plugins/tradingpost-errbot/tradingpost.py", line 40, in card
    self.send_card(title=card['name'],
TypeError: BotPlugin.send_card() got an unexpected keyword argument 'parent'

Trying to only use card.to (instead of card.in_reply_to as instructed in the docs) gives a similar error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/errbot/core.py", line 574, in _execute_and_send
    reply = method(msg, match) if match else method(msg, args)
                                             ^^^^^^^^^^^^^^^^^
  File "/app/plugins/tradingpost-errbot/tradingpost.py", line 38, in card
    self.send_card(title=card['name'],
  File "/usr/local/lib/python3.11/site-packages/errbot/botplugin.py", line 654, in send_card
    self._bot.send_card(
  File "/usr/local/lib/python3.11/site-packages/slackv3/slackv3.py", line 860, in send_card
    to_humanreadable, to_channel_id = self._prepare_message(card)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/slackv3/slackv3.py", line 687, in _prepare_message
    to_humanreadable = msg.to.username
                       ^^^^^^^^^^^^^^^
AttributeError: 'Message' object has no attribute 'username'

As a side note it seems strange that the default behavior of send_card() isn't similar to send_message(): only reply in-thread when prompted in a thread.

Also note that send_card() and send_stream_request() have the opposite behavior: