1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-03 00:15:27 +00:00
tgbotapi/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt

81 lines
2.8 KiB
Kotlin
Raw Normal View History

2020-10-04 11:06:30 +00:00
package dev.inmo.tgbotapi.requests.send
2018-12-26 08:07:24 +00:00
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import dev.inmo.tgbotapi.types.message.content.ContactContent
2018-12-26 08:07:24 +00:00
import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<ContactContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
2018-12-26 08:07:24 +00:00
@Serializable
data class SendContact(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(phoneNumberField)
val phoneNumber: String,
@SerialName(firstNameField)
val firstName: String,
@SerialName(lastNameField)
val lastName: String? = null,
@SerialName(disableNotificationField)
override val disableNotification: Boolean = false,
2022-01-01 14:13:22 +00:00
@SerialName(protectContentField)
override val protectContent: Boolean = false,
2018-12-26 08:07:24 +00:00
@SerialName(replyToMessageIdField)
override val replyToMessageId: MessageId? = null,
@SerialName(allowSendingWithoutReplyField)
override val allowSendingWithoutReply: Boolean? = null,
2018-12-26 08:07:24 +00:00
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<ContentMessage<ContactContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<ContactContent>>
2018-12-26 08:07:24 +00:00
{
constructor(
chatId: ChatIdentifier,
contact: Contact,
disableNotification: Boolean = false,
2022-01-01 14:13:22 +00:00
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null,
2018-12-26 08:07:24 +00:00
replyMarkup: KeyboardMarkup? = null
): this(
chatId,
contact.phoneNumber,
contact.firstName,
contact.lastName,
disableNotification,
2022-01-01 14:13:22 +00:00
protectContent,
2018-12-26 08:07:24 +00:00
replyToMessageId,
allowSendingWithoutReply,
2018-12-26 08:07:24 +00:00
replyMarkup
)
override fun method(): String = "sendContact"
override val resultDeserializer: DeserializationStrategy<ContentMessage<ContactContent>>
get() = commonResultDeserializer
2019-12-02 08:35:37 +00:00
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
2018-12-26 08:07:24 +00:00
}
fun Contact.toRequest(
chatId: ChatIdentifier,
disableNotification: Boolean = false,
2022-01-01 14:13:22 +00:00
protectContent: Boolean = false,
replyToMessageId: MessageId? = null,
allowSendingWithoutReply: Boolean? = null,
2018-12-26 08:07:24 +00:00
replyMarkup: KeyboardMarkup? = null
): SendContact = SendContact(
chatId,
this,
disableNotification,
2022-01-01 14:13:22 +00:00
protectContent,
2018-12-26 08:07:24 +00:00
replyToMessageId,
allowSendingWithoutReply,
2018-12-26 08:07:24 +00:00
replyMarkup
)