mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
add passport in API
This commit is contained in:
parent
0c71133969
commit
1dc3ce2fb5
@ -19,6 +19,8 @@
|
|||||||
* `onVisualMediaGroup` now is just an alternative to `onVisualGallery`
|
* `onVisualMediaGroup` now is just an alternative to `onVisualGallery`
|
||||||
* `command` and `onCommand` expectations has been added for commands `String` variant
|
* `command` and `onCommand` expectations has been added for commands `String` variant
|
||||||
* New extensions `BehaviourContext#oneOf`, `BehaviourContext#parallel` and `Deferred<T>#withAction`
|
* New extensions `BehaviourContext#oneOf`, `BehaviourContext#parallel` and `Deferred<T>#withAction`
|
||||||
|
* `API`:
|
||||||
|
* **PASSPORT** New extensions `TelegramBot#setPassportDataErrors`
|
||||||
|
|
||||||
## 0.31.0
|
## 0.31.0
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.utils.passport
|
|||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.requests.DownloadFile
|
import dev.inmo.tgbotapi.requests.DownloadFile
|
||||||
import dev.inmo.tgbotapi.requests.get.GetFile
|
import dev.inmo.tgbotapi.requests.get.GetFile
|
||||||
|
import dev.inmo.tgbotapi.types.passport.EncryptedCredentials
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile
|
import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData
|
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData
|
||||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||||
@ -25,7 +26,7 @@ suspend fun Decryptor.decrypt(
|
|||||||
).decrypt()
|
).decrypt()
|
||||||
}
|
}
|
||||||
fun Decryptor.decryptData(
|
fun Decryptor.decryptData(
|
||||||
data: WithData
|
data: EncryptedCredentials
|
||||||
) = nonstrictJsonFormat.decodeFromString(
|
) = nonstrictJsonFormat.decodeFromString(
|
||||||
JsonObject.serializer(),
|
JsonObject.serializer(),
|
||||||
data.data.encodeToByteArray().decrypt().decodeToString()
|
data.data.encodeToByteArray().decrypt().decodeToString()
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.passport
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.SetPassportDataErrors
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.PassportMessage
|
||||||
|
import dev.inmo.tgbotapi.types.passport.PassportData
|
||||||
|
import dev.inmo.tgbotapi.types.passport.PassportElementError
|
||||||
|
import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement
|
||||||
|
import dev.inmo.tgbotapi.utils.passport.Decryptor
|
||||||
|
|
||||||
|
suspend fun TelegramBot.setPassportDataErrors(
|
||||||
|
userId: UserId,
|
||||||
|
errors: List<PassportElementError>
|
||||||
|
) = execute(SetPassportDataErrors(userId, errors))
|
||||||
|
suspend fun TelegramBot.setPassportDataErrors(
|
||||||
|
user: User,
|
||||||
|
errors: List<PassportElementError>
|
||||||
|
) = setPassportDataErrors(user.id, errors)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.setPassportDataErrors(
|
||||||
|
userId: UserId,
|
||||||
|
passportData: PassportData,
|
||||||
|
decryptor: Decryptor,
|
||||||
|
mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError
|
||||||
|
): Boolean = setPassportDataErrors(
|
||||||
|
userId,
|
||||||
|
passportData.data.map { decryptor.mapper(it) }.also {
|
||||||
|
if (it.isEmpty()) {
|
||||||
|
return@setPassportDataErrors false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
suspend fun TelegramBot.setPassportDataErrors(
|
||||||
|
user: User,
|
||||||
|
passportData: PassportData,
|
||||||
|
decryptor: Decryptor,
|
||||||
|
mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError
|
||||||
|
) = setPassportDataErrors(user.id, passportData, decryptor, mapper)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.setPassportDataErrors(
|
||||||
|
passportMessage: PassportMessage,
|
||||||
|
decryptor: Decryptor,
|
||||||
|
mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError
|
||||||
|
) = setPassportDataErrors(passportMessage.user, passportMessage.passportData, decryptor, mapper)
|
Loading…
Reference in New Issue
Block a user