mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Audio transcription
This commit is contained in:
@@ -97,7 +97,11 @@ private class AdMessagesHistoryContextImpl {
|
||||
|
||||
self.opaqueId = try container.decode(Data.self, forKey: .opaqueId)
|
||||
|
||||
self.messageType = (try container.decodeIfPresent(MessageType.self, forKey: .messageType)) ?? .sponsored
|
||||
if let messageType = try container.decodeIfPresent(Int32.self, forKey: .messageType) {
|
||||
self.messageType = MessageType(rawValue: messageType) ?? .sponsored
|
||||
} else {
|
||||
self.messageType = .sponsored
|
||||
}
|
||||
|
||||
self.text = try container.decode(String.self, forKey: .text)
|
||||
self.textEntities = try container.decode([MessageTextEntity].self, forKey: .textEntities)
|
||||
@@ -116,7 +120,7 @@ private class AdMessagesHistoryContextImpl {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
try container.encode(self.opaqueId, forKey: .opaqueId)
|
||||
try container.encode(self.messageType, forKey: .messageType)
|
||||
try container.encode(self.messageType.rawValue, forKey: .messageType)
|
||||
try container.encode(self.text, forKey: .text)
|
||||
try container.encode(self.textEntities, forKey: .textEntities)
|
||||
|
||||
|
||||
@@ -322,6 +322,10 @@ public extension TelegramEngine {
|
||||
return _internal_translate(network: self.account.network, text: text, fromLang: fromLang, toLang: toLang)
|
||||
}
|
||||
|
||||
public func transcribeAudio(messageId: MessageId) -> Signal<String?, NoError> {
|
||||
return _internal_transcribeAudio(postbox: self.account.postbox, network: self.account.network, messageId: messageId)
|
||||
}
|
||||
|
||||
public func requestWebView(peerId: PeerId, botId: PeerId, url: String?, payload: String?, themeParams: [String: Any]?, fromMenu: Bool, replyToMessageId: MessageId?) -> Signal<RequestWebViewResult, RequestWebViewError> {
|
||||
return _internal_requestWebView(postbox: self.account.postbox, network: self.account.network, stateManager: self.account.stateManager, peerId: peerId, botId: botId, url: url, payload: payload, themeParams: themeParams, fromMenu: fromMenu, replyToMessageId: replyToMessageId)
|
||||
}
|
||||
|
||||
@@ -28,3 +28,28 @@ func _internal_translate(network: Network, text: String, fromLang: String?, toLa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_transcribeAudio(postbox: Postbox, network: Network, messageId: MessageId) -> Signal<String?, NoError> {
|
||||
return postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(messageId.peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapToSignal { inputPeer -> Signal<String?, NoError> in
|
||||
guard let inputPeer = inputPeer else {
|
||||
return .single(nil)
|
||||
}
|
||||
return network.request(Api.functions.messages.transcribeAudio(peer: inputPeer, msgId: messageId.id))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<Api.messages.TranscribedAudio?, NoError> in
|
||||
return .single(nil)
|
||||
}
|
||||
|> mapToSignal { result -> Signal<String?, NoError> in
|
||||
guard let result = result else {
|
||||
return .single(nil)
|
||||
}
|
||||
switch result {
|
||||
case let .transcribedAudio(string):
|
||||
return .single(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,17 +470,23 @@ func _internal_sendBotPaymentForm(account: Account, formId: Int64, source: BotPa
|
||||
for media in message.media {
|
||||
if let action = media as? TelegramMediaAction {
|
||||
if case .paymentSent = action.action {
|
||||
for attribute in message.attributes {
|
||||
if let reply = attribute as? ReplyMessageAttribute {
|
||||
switch source {
|
||||
case let .message(messageId):
|
||||
switch source {
|
||||
case let .slug(slug):
|
||||
for media in message.media {
|
||||
if let action = media as? TelegramMediaAction, case let .paymentSent(_, _, invoiceSlug?) = action.action, invoiceSlug == slug {
|
||||
if case let .Id(id) = message.id {
|
||||
receiptMessageId = id
|
||||
}
|
||||
}
|
||||
}
|
||||
case let .message(messageId):
|
||||
for attribute in message.attributes {
|
||||
if let reply = attribute as? ReplyMessageAttribute {
|
||||
if reply.messageId == messageId {
|
||||
if case let .Id(id) = message.id {
|
||||
receiptMessageId = id
|
||||
}
|
||||
}
|
||||
case .slug:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user