async def _generate_message_entities(
        self, client: httpx.AsyncClient, channel_id: str
    ) -> AsyncGenerator[ChunkEntity, None]:
        """Generate SlackMessageEntity objects for a given channel using conversations.history.

        Endpoint: https://slack.com/api/conversations.history
        Scope(s): channels:history, groups:history, im:history, mpim:history
        """
        url = "https://slack.com/api/conversations.history"
        params = {"channel": channel_id, "limit": 200}

        try:
            while True:
                try:
                    data = await self._get_with_auth(client, url, params=params)

                    for message in data.get("messages", []):
                        yield SlackMessageEntity(
                            entity_id=f"{channel_id}-{message.get('ts')}",
                            channel_id=channel_id,
                            user_id=message.get("user"),
                            text=message.get("text"),
                            ts=message.get("ts"),
                            thread_ts=message.get("thread_ts"),
                            team=message.get("team"),
                            attachments=message.get("attachments", []),
                            blocks=message.get("blocks", []),
                            files=message.get("files", []),
                            reactions=message.get("reactions", []),
                            is_bot=message.get("bot_id") is not None,
                            subtype=message.get("subtype"),
                            edited=message.get("edited"),
                        )

                    next_cursor = data.get("response_metadata", {}).get("next_cursor")
                    if not next_cursor:
                        break
                    params["cursor"] = next_cursor

                except httpx.HTTPError as e:
                    # Check if this is a rate limit error
                    if "429" in str(e):
                        # Let tenacity retry with backoff
                        raise
                    # Handle 'not_in_channel' error before re-raising other errors
                    elif "not_in_channel" in str(e):
                        print(
                            f"Warning: Cannot access messages in channel {channel_id}. "
                            f"User is not a member of this channel."
                        )
                        # Break out of the loop and yield nothing for this channel
                        return
                    else:
                        # Re-raise any other HTTP errors
                        raise
        except httpx.HTTPError as e:
            # This is the critical part - we need to catch and
            # handle the not_in_channel error completely
            if "not_in_channel" in str(e):
                print(
                    f"Warning: Cannot access messages in channel {channel_id}. "
                    f"Bot is not a member of this channel."
                )
                return  # Don't re-raise, just return with no entities
            else:
                # For other errors, we can still re-raise
                raise
Generate SlackMessageEntity objects for a given channel using conversations.history.

        Endpoint: https://slack.com/api/conversations.history
        Scope(s): channels:history, groups:history, im:history, mpim:history
        
backend/airweave/platform/sources/slack.py