errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.12k stars 614 forks source link

Slack: How can I send attachments in a message using pytest? #1488

Closed ppinzon closed 3 years ago

ppinzon commented 3 years ago

In order to let us help you better, please fill out the following fields as best you can:

I am...

I am running...

Issue description

Hello!

We use errbot with Slack. One of the pluggins that we have is used to capture a channel ID and store it. The channel information is given by the user just putting the channel name and slack fills up the details.

These are then sent to the bot as a message with an attachment. The bot sees this in msg.extras

Now, my problem is that im writting tests for this plugin but the function testbot.push_message() doesnt add the attachment by itself. Now, I could create the attachment manually but doesn't look like push_message takes any more arguments to add an attachment.

Is there another way to send an attachment for tests for Slack?

Steps to reproduce

Not a bug, but you can easily repo this:

  1. create a plugin and add this for logging: self.log.debug(msg) self.log.debug(msg.extras)

  2. in slack, send a message to the bot mentioning a channel. e.g. !command this is my channel #mychannel

  3. you will see msg.extras populated with the channel info

  4. write a test for that command: testbot.push_message('!command this is my channel #mychannel')

  5. msg,extras will show up empty

Additional info

If you have any more information, please specify it here.

ppinzon commented 3 years ago

Ok, so I found the problem:

The method used to send the message in pytest only accepts one argument which is used a the text of the message https://github.com/errbotio/errbot/blob/54542fd38250b4cb977283854c5cb2b446b1281b/errbot/backends/test.py#L333

And once here, the message is pulled from the queue, the only fields updated are the To and From https://github.com/errbotio/errbot/blob/54542fd38250b4cb977283854c5cb2b446b1281b/errbot/backends/test.py#L266

I tried to update the attribute msg.extras but the property doesn't have a setter so it cant be updated. Instead i also tried adding it to object creation as a keyword argument and that seems to work great. by changing line 267 to msg = Message(entry, extras=extras). I also had extra in all the other methods that eventually end up there.

Would this be an acceptable change to create a PR?

ppinzon commented 3 years ago

Made a PR to show what I added for this to work. https://github.com/errbotio/errbot/pull/1489.

nvm, looks like I goofed something and the checks are failing.

ppinzon commented 3 years ago

PR passing the checks succesfully now

ppinzon commented 3 years ago

this being my first PR here I'm not that familiar with the lifecycle of this repo. How long, on average, does it take for this to be reviewed?

sijis commented 3 years ago

I appreciate your PR. We really don't have a specific time frame to review PRs. I try to spend a few days a month reviewing issues as free time allows.

ppinzon commented 3 years ago

cool beans, thank you Sijis

sijis commented 3 years ago

Closed via https://github.com/errbotio/errbot/pull/1489.