diff --git a/submodules/TelegramApi/Sources/Api31.swift b/submodules/TelegramApi/Sources/Api31.swift index 30a67f2a8a..ac7815157c 100644 --- a/submodules/TelegramApi/Sources/Api31.swift +++ b/submodules/TelegramApi/Sources/Api31.swift @@ -1807,15 +1807,15 @@ public extension Api.functions.auth { } } public extension Api.functions.bots { - static func allowSendMessage(bot: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func allowSendMessage(bot: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(933102155) + buffer.appendInt32(-248323089) bot.serialize(buffer, true) - return (FunctionDescription(name: "bots.allowSendMessage", parameters: [("bot", String(describing: bot))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + return (FunctionDescription(name: "bots.allowSendMessage", parameters: [("bot", String(describing: bot))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in let reader = BufferReader(buffer) - var result: Api.Bool? + var result: Api.Updates? if let signature = reader.readInt32() { - result = Api.parse(reader, signature: signature) as? Api.Bool + result = Api.parse(reader, signature: signature) as? Api.Updates } return result }) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift index c369a6784c..13f9228fbe 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift @@ -258,23 +258,24 @@ func _internal_canBotSendMessages(postbox: Postbox, network: Network, botId: Pee |> switchToLatest } -func _internal_allowBotSendMessages(postbox: Postbox, network: Network, botId: PeerId) -> Signal { - return postbox.transaction { transaction -> Signal in +func _internal_allowBotSendMessages(postbox: Postbox, network: Network, stateManager: AccountStateManager, botId: PeerId) -> Signal { + return postbox.transaction { transaction -> Signal in guard let bot = transaction.getPeer(botId), let inputUser = apiInputUser(bot) else { - return .single(false) + return .never() } return network.request(Api.functions.bots.allowSendMessage(bot: inputUser)) - |> `catch` { _ -> Signal in - return .single(.boolFalse) + |> map(Optional.init) + |> `catch` { _ -> Signal in + return .single(nil) } - |> map { result -> Bool in - if case .boolTrue = result { - return true - } else { - return false + |> map { updates -> Api.Updates? in + if let updates = updates { + stateManager.addUpdates(updates) } + return updates } + |> ignoreValues } |> switchToLatest } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index 272dc1c39d..2981979a9c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -512,8 +512,8 @@ public extension TelegramEngine { return _internal_canBotSendMessages(postbox: self.account.postbox, network: self.account.network, botId: botId) } - public func allowBotSendMessages(botId: PeerId) -> Signal { - return _internal_allowBotSendMessages(postbox: self.account.postbox, network: self.account.network, botId: botId) + public func allowBotSendMessages(botId: PeerId) -> Signal { + return _internal_allowBotSendMessages(postbox: self.account.postbox, network: self.account.network, stateManager: self.account.stateManager, sbotId: botId) } public func invokeBotCustomMethod(botId: PeerId, method: String, params: String) -> Signal {