Exemple #1
0
    async def teams_message_handler(self, req: Request) -> Response:
        """Handle incoming webhooks from Teams."""
        if "application/json" in req.headers["Content-Type"]:
            body = await req.json()
            _LOGGER.debug(json.dumps(body))
        else:
            return Response(status=415)

        activity = Activity().deserialize(body)

        # Cache service endpoint for channel
        teams_channel_id = teams_get_channel_id(activity)
        if teams_channel_id not in self.service_endpoints:
            self.service_endpoints[teams_channel_id] = activity.service_url
            await self.opsdroid.memory.put("teams_service_endpoints",
                                           self.service_endpoints)

        if activity.type == "message":
            message = Message(
                text=activity.text,
                user=activity.from_property.name,
                target=TurnContext.get_conversation_reference(activity),
                connector=self,
                raw_event=TurnContext(self.adapter, activity),
            )
            await self.opsdroid.parse(message)
        else:
            _LOGGER.info(
                f"Recieved {activity.type} activity which is not currently supported."
            )

        return Response(status=200)
Exemple #2
0
    async def on_message_activity(self, turn_context: TurnContext):
        message = MessageFactory.text("first message")
        channel_id = teams_get_channel_id(turn_context.activity)
        result = await TeamsInfo.send_message_to_teams_channel(
            turn_context, message, channel_id)

        await turn_context.adapter.continue_conversation(
            result[0], self._continue_conversation_callback, self.id)
Exemple #3
0
    def test_teams_get_channel_id_with_none_activity(self):
        # Arrange
        activity = None

        # Act
        result = teams_get_channel_id(activity)

        # Assert
        assert result is None
Exemple #4
0
    def test_teams_get_channel_id_with_no_channel_data(self):
        # Arrange
        activity = Activity(type="type")

        # Act
        result = teams_get_channel_id(activity)

        # Assert
        assert result is None
Exemple #5
0
    def test_teams_get_channel_id_with_no_channel_id(self):
        # Arrange
        activity = Activity(channel_data={"team": {"name": "channel_name"}})

        # Act
        result = teams_get_channel_id(activity)

        # Assert
        assert result is None
    async def on_message_activity(self, turn_context: TurnContext):
        teams_channel_id = teams_get_channel_id(turn_context.activity)
        message = MessageFactory.text("This will be the start of a new thread")
        new_conversation = await self.teams_create_conversation(
            turn_context, teams_channel_id, message)

        await turn_context.adapter.continue_conversation(
            new_conversation[0], self.continue_conversation_callback,
            self._app_id)
Exemple #7
0
    def test_teams_get_channel_id(self):
        # Arrange
        activity = Activity(
            channel_data={"channel": {"id": "id123", "name": "channel_name"}}
        )

        # Act
        result = teams_get_channel_id(activity)

        # Assert
        assert result == "id123"