Skip to content
This repository has been archived by the owner on Oct 21, 2019. It is now read-only.

Add reactions #9

Open
anxodio opened this issue Feb 2, 2018 · 3 comments
Open

Add reactions #9

anxodio opened this issue Feb 2, 2018 · 3 comments

Comments

@anxodio
Copy link

anxodio commented Feb 2, 2018

Reactions are a nice feature of slack, and would be great to add the capability to opsdroid slack connector to react to messages.
I investigated a lite and to archive this, we need to do some changes:

  • Reactions are implemented in slacker. But in order to react to a message, you need the channel and the exact timestamp of the message. Actually, opsdroid Message class don't save the message origin timestamp. So a ts property should be created, or created property should be used for this prupose.
  • So in the listen method of the slack connector, this new property should be filled with the timestamp of the message (m["ts"])
  • An add_reaction method should be implemented in the slack connector, with something like:
    async def add_reaction(self, message, reaction):
        """ Respond with a message """
        _LOGGER.debug("Adding reaction '"+reaction+"' with: '" + message.text +
                      "' in room " + message.room)
        await self.sc.reactions.add(
            reaction, channel=message.room, timestamp=message.ts)
  • In the test I made, slacker fails in Reactions.add when using channel and timestamp. To resolve it, I removed file and file_comment from the post call. We should try it again and if it fails as I saw, open an issue in slacker.
  • With all changes done, this can be used from an skill:
if message.connector.name == 'slack':
    await message.connector.add_reaction(message, 'thumbsup')

What do you think?

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Feb 7, 2018

I really like this idea. I've been thinking about other types of responses for a while. For example opsdroid/opsdroid#195 covers sending images to chat clients.

I totally agree with keeping track of the other metadata which comes with the message. Perhaps the whole response should be stored in message.raw_message or something? This would avoid us having to extend the Message class each time this crops up in a connector.

I think I would prefer to extend the Message class with a method called message.react('thumbsup') which connectors like Slack could then implement. If the connector does not implement it then it simply logs to say is cannot do it and silently fails, similar to your if statement checking if the connector is slack. This approach would mean we could easily add other clients which support reactions in the future and skills wouldn't need slack specific code.

What do you think?

@anxodio
Copy link
Author

anxodio commented Feb 7, 2018

I totally prefer to implement react in the base and don't use lots of ifs (it's always better to use extension 😉)
And I agree too with save the whole raw_message to have the different information that different connectors can use.

So I will start checking if the problem I detected in slacker Reactions.add is real, and if it is raise an issue there.

Meanwhile, we should open an issue on opsdroid main repository explaining the Message modifications (raw + react).

@jacobtomlinson
Copy link
Member

Once opsdroid/opsdroid#442 and opsdroid/opsdroid#443 are done they will need implementing in this connector.

@anxodio anxodio mentioned this issue Feb 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants