How to use the opsdroid.events.Message 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_facebook.py View on Github external
async def test_respond(self):
        """Test that responding sends a message."""
        post_response = amock.Mock()
        post_response.status = 200

        with OpsDroid() as opsdroid, amock.patch(
            "aiohttp.ClientSession.post", new=asynctest.CoroutineMock()
        ) as patched_request:
            self.assertTrue(opsdroid.__class__.instances)
            connector = ConnectorFacebook({}, opsdroid=opsdroid)
            room = "a146f52c-548a-11e8-a7d1-28cfe949e12d"
            test_message = Message(
                text="Hello world", user="Alice", target=room, connector=connector
            )
            patched_request.return_value = asyncio.Future()
            patched_request.return_value.set_result(post_response)
            await test_message.respond("Response")
            self.assertTrue(patched_request.called)
github opsdroid / opsdroid / tests / test_connector.py View on Github external
def test_respond(self):
        connector = Connector({}, opsdroid=OpsDroid())
        with self.assertRaises(TypeError):
            self.loop.run_until_complete(connector.send(Message("")))
github opsdroid / opsdroid / tests / test_events.py View on Github external
self.assertTrue(mocksleep.called)

            # Test thinking-delay with a list

            mock_connector_list = Connector(
                {
                    "name": "shell",
                    "typing-delay": [1, 4],
                    "type": "connector",
                    "module_path": "opsdroid-modules.connector.shell",
                },
                opsdroid=opsdroid,
            )

            with amock.patch("asyncio.sleep") as mocksleep_list:
                message = events.Message(
                    "hi", "user_id", "user", "default", mock_connector_list
                )
                with self.assertRaises(TypeError):
                    await message.respond("Hello there")

                self.assertTrue(mocksleep_list.called)
github opsdroid / opsdroid / tests / test_connector_matrix.py View on Github external
async def test_send_reply(self):
        message = events.Message(
            "hello",
            event_id="$11111",
            connector=self.connector,
            target="!test:localhost",
        )
        reply = events.Reply("reply")
        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(reply)

                content = self.connector._get_formatted_message_body(
                    reply.text, msgtype="m.text"
                )
github opsdroid / opsdroid / tests / test_parser_rasanlu.py View on Github external
async def test_call_rasanlu(self):
        opsdroid = amock.CoroutineMock()
        mock_connector = Connector({}, opsdroid=opsdroid)
        message = Message(
            text="how's the weather outside",
            user="user",
            target="default",
            connector=mock_connector,
        )
        config = {"name": "rasanlu", "min-score": 0.3, "token": "12345"}
        result = amock.Mock()
        result.status = 200
        result.json = amock.CoroutineMock()
        result.json.return_value = {
            "entities": [
                {
                    "end": 32,
                    "entity": "state",
                    "extractor": "ner_crf",
                    "confidence": 0.854,
github opsdroid / opsdroid / tests / test_events.py View on Github external
async def test_response_effects(self):
        """Responding to a message shouldn't change the message."""
        with OpsDroid() as opsdroid:
            mock_connector = Connector({}, opsdroid=opsdroid)
            message_text = "Hello world"
            message = events.Message(
                message_text, "user_id", "user", "default", mock_connector
            )
            with self.assertRaises(TypeError):
                await message.respond("Goodbye world")
            self.assertEqual(message_text, message.text)
github opsdroid / opsdroid / tests / test_parser_always.py View on Github external
async def test_parse_always_decorate_no_parens(self):
        with OpsDroid() as opsdroid:
            mock_skill = await self.getMockSkill()
            opsdroid.skills.append(match_always(mock_skill))
            opsdroid.run_skill = amock.CoroutineMock()

            mock_connector = amock.CoroutineMock()
            message = Message(
                text="Hello world",
                user="user",
                target="default",
                connector=mock_connector,
            )

            await parse_always(opsdroid, message)

            self.assertTrue(opsdroid.run_skill.called)
github opsdroid / opsdroid / tests / test_parser_sapcai.py View on Github external
async def test_call_sapcai(self):
        opsdroid = amock.CoroutineMock()
        mock_connector = Connector({}, opsdroid=opsdroid)
        message = Message(
            text="Hello", user="user", target="default", connector=mock_connector
        )
        config = {"name": "recastai", "token": "test"}
        result = amock.Mock()
        result.json = amock.CoroutineMock()
        result.json.return_value = {
            "results": {
                "uuid": "f482bddd-a9d7-41ae-aae3-6e64ad3f02dc",
                "source": "hello",
                "intents": [{"slug": "greetings", "confidence": 0.99}],
                "act": "assert",
                "type": None,
                "sentiment": "vpositive",
                "entities": {},
                "language": "en",
                "processing_language": "en",