How to use the opsdroid.events.Reaction function in opsdroid

To help you get started, we’ve selected a few opsdroid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opsdroid / opsdroid / tests / test_connector_matrix.py View on Github external
async def test_reaction(self):
        with amock.patch(api_string.format("get_event_in_room")) as patched_send:
            patched_send.return_value = asyncio.Future()
            patched_send.return_value.set_result(self.message_json)
            event = await self.event_creator.create_event(self.reaction_json, "hello")

        assert isinstance(event, events.Reaction)
        assert event.emoji == "👍"
        assert event.user == "Rabbit Hole"
        assert event.user_id == "@neo:matrix.org"
        assert event.target == "hello"
        assert event.event_id == "$4KOPKFjdJ5urFGJdK4lnS-Fd3qcNWbPdR_rzSCZK_g0"
        assert event.raw_event == self.reaction_json

        assert isinstance(event.linked_event, events.Message)
github opsdroid / opsdroid / tests / test_connector_slack.py View on Github external
async def test_react(self):
        connector = ConnectorSlack({"token": "abc123"})
        connector.slack.api_call = amock.CoroutineMock()
        prev_message = Message(
            text="test",
            user="user",
            target="room",
            connector=connector,
            raw_event={"ts": 0},
        )
        with OpsDroid():
            await prev_message.respond(Reaction("😀"))
        self.assertTrue(connector.slack.api_call)
        self.assertEqual(
            connector.slack.api_call.call_args[1]["data"]["name"], "grinning_face"
        )
github opsdroid / opsdroid / tests / test_events.py View on Github external
async def test_react(self):
        with OpsDroid() as opsdroid:
            mock_connector = Connector(
                {"name": "shell", "thinking-delay": 2, "type": "connector"},
                opsdroid=opsdroid,
            )
            with amock.patch("asyncio.sleep") as mocksleep:
                message = events.Message(
                    "Hello world", "user_id", "user", "default", mock_connector
                )
                with self.assertRaises(TypeError):
                    await message.respond(events.Reaction("emoji"))
                self.assertTrue(mocksleep.called)
github opsdroid / opsdroid / tests / test_connector_matrix.py View on Github external
async def test_send_reaction(self):
        message = events.Message(
            "hello",
            event_id="$11111",
            connector=self.connector,
            target="!test:localhost",
        )
        reaction = events.Reaction("⭕")
        with OpsDroid() as _:
            with amock.patch(api_string.format("send_message_event")) as patched_send:
                patched_send.return_value = asyncio.Future()
                patched_send.return_value.set_result(None)

                await message.respond(reaction)

                content = {
                    "m.relates_to": {
                        "rel_type": "m.annotation",
                        "event_id": "$11111",
                        "key": reaction.emoji,
                    }
                }

                assert patched_send.called_once_with(
github opsdroid / opsdroid / tests / test_connector.py View on Github external
def test_unsupported_event(self):
        connector = Connector({}, opsdroid=OpsDroid())
        with self.assertRaises(TypeError):
            self.loop.run_until_complete(connector.send(Reaction("emoji")))
github opsdroid / opsdroid / opsdroid / connector / matrix / connector.py View on Github external
    @register_event(events.Reaction)
    @ensure_room_id_and_send
    async def _send_reaction(self, reaction):
        content = {
            "m.relates_to": {
                "rel_type": "m.annotation",
                "event_id": reaction.linked_event.event_id,
                "key": reaction.emoji,
            }
        }
        return await self.connection.send_message_event(
            reaction.target, "m.reaction", content
        )
github opsdroid / opsdroid / opsdroid / connector / __init__.py View on Github external
Args:
            message (Message): A message received by the connector.
            emoji    (string): The emoji name with which opsdroid will react

        Returns:
            bool: True for message successfully sent. False otherwise.

        """
        warnings.warn(
            "Connector.react is deprecated. Use "
            "Connector.send(events.Reaction(emoji)) instead.",
            DeprecationWarning,
        )

        return await message.respond(Reaction(emoji))
github opsdroid / opsdroid / opsdroid / connector / matrix / create_events.py View on Github external
async def create_reaction(self, event, roomid):
        """Send a Reaction event."""
        parent_event_id = event["content"]["m.relates_to"]["event_id"]
        parent_event = await self.create_event_from_eventid(parent_event_id, roomid)
        return events.Reaction(
            emoji=event["content"]["m.relates_to"]["key"],
            user=await self.connector.get_nick(roomid, event["sender"]),
            user_id=event["sender"],
            target=roomid,
            connector=self.connector,
            event_id=event["event_id"],
            linked_event=parent_event,
            raw_event=event,
        )