Update API

This commit is contained in:
Ilya Laktyushin 2023-08-26 16:36:08 +04:00
parent 03db11e5ee
commit a1ba5cca74
3 changed files with 18 additions and 17 deletions

View File

@ -1807,15 +1807,15 @@ public extension Api.functions.auth {
}
}
public extension Api.functions.bots {
static func allowSendMessage(bot: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
static func allowSendMessage(bot: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
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
})

View File

@ -258,23 +258,24 @@ func _internal_canBotSendMessages(postbox: Postbox, network: Network, botId: Pee
|> switchToLatest
}
func _internal_allowBotSendMessages(postbox: Postbox, network: Network, botId: PeerId) -> Signal<Bool, NoError> {
return postbox.transaction { transaction -> Signal<Bool, NoError> in
func _internal_allowBotSendMessages(postbox: Postbox, network: Network, stateManager: AccountStateManager, botId: PeerId) -> Signal<Never, NoError> {
return postbox.transaction { transaction -> Signal<Never, NoError> 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<Api.Bool, NoError> in
return .single(.boolFalse)
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.Updates?, NoError> 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
}

View File

@ -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<Bool, NoError> {
return _internal_allowBotSendMessages(postbox: self.account.postbox, network: self.account.network, botId: botId)
public func allowBotSendMessages(botId: PeerId) -> Signal<Never, NoError> {
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<String, InvokeBotCustomMethodError> {