diff --git a/botx/bots/mixins/requests/mixin.py b/botx/bots/mixins/requests/mixin.py index a8a58bed..98807a1b 100644 --- a/botx/bots/mixins/requests/mixin.py +++ b/botx/bots/mixins/requests/mixin.py @@ -76,10 +76,9 @@ async def call_method( # noqa: WPS211 """ if credentials is not None: debug_bot_id = credentials.bot_id - host = cast(str, credentials.host) bot_id = cast(UUID, credentials.bot_id) method.configure( - host=host, + host=cast(CredentialsSearchProtocol, self).get_account_by_bot_id(bot_id).host, token=cast(CredentialsSearchProtocol, self).get_token_for_bot(bot_id), ) else: diff --git a/botx/models/messages/message.py b/botx/models/messages/message.py index 3fa7b257..909c8923 100644 --- a/botx/models/messages/message.py +++ b/botx/models/messages/message.py @@ -121,10 +121,17 @@ def __init__(self, message: IncomingMessage, bot: "bots.Bot") -> None: self.credentials = SendingCredentials( sync_id=self.sync_id, bot_id=self.bot_id, - host=self.host, + host=self.get_host_by_bot_id(self.bot, self.bot_id), chat_id=self.group_chat_id, ) + @classmethod + def get_host_by_bot_id(cls, bot: "bots.Bot", bot_id: UUID) -> str: + for account in bot.bot_accounts: + if account.bot_id == bot_id: + return account.host + raise ValueError("Not found account by bot_id") + @classmethod def from_dict(cls, message: dict, bot: "bots.Bot") -> Message: """Parse incoming dict into message.