def get_user_chat_messages()

in ees_microsoft_teams/microsoft_teams_client.py [0:0]


    def get_user_chat_messages(self, next_url, start_time, end_time, chat_id):
        """ Get user chat messages from the Microsoft Teams with the support of pagination and filtration.
            :param next_url: URL to invoke Graph API call
            :param start_time: Starting time to fetch user chats messages
            :param end_time: Ending time to fetch user chat messages
            :param chat_id: Chat ID to fetch user chat messages
        """
        response_list = {"value": []}
        is_calling_first_time = True
        while next_url:
            try:
                query = self.query_builder.get_query_for_channel_and_chat_messages().strip()
                if is_calling_first_time:
                    url = f"{next_url}{query}"
                    is_calling_first_time = False
                else:
                    url = next_url
                response_json = self.get(url=url, object_type=constant.USER_CHATS_MESSAGE)

                # Filter response based on lastModifiedDateTime
                response_value = response_json.get("value")
                if response_value:
                    for chat_message in response_value:
                        last_modified_date_time = chat_message.get("lastModifiedDateTime")
                        if start_time <= last_modified_date_time <= end_time:
                            response_list["value"].append(chat_message)

                next_url = response_json.get("@odata.nextLink")

                if not next_url or next_url == url:
                    next_url = None

            except Exception as unknown_exception:
                self.logger.exception(
                    f"Error while fetching the Microsoft User Chats Messages. Error: {unknown_exception}"
                )

        parsed_response = get_data_from_http_response(
            logger=self.logger,
            response=response_list,
            error_message=f"Could not fetch the User Chats Messages from Microsoft Teams for chat id: {chat_id}",
            exception_message=f"Error while fetching User Chats Messages from Microsoft Teams for chat id: {chat_id}",
        )

        return parsed_response