tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendContact.kt

64 lines
1.9 KiB
Kotlin

package com.github.insanusmokrassar.TelegramBotAPI.requests.send
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.*
import kotlinx.serialization.*
@Serializable
data class SendContact(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(phoneNumberField)
val phoneNumber: String,
@SerialName(firstNameField)
val firstName: String,
@SerialName(lastNameField)
@Optional
val lastName: String? = null,
@SerialName(disableNotificationField)
@Optional
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
@Optional
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(replyMarkupField)
@Optional
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage>
{
constructor(
chatId: ChatIdentifier,
contact: Contact,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): this(
chatId,
contact.phoneNumber,
contact.firstName,
contact.lastName,
disableNotification,
replyToMessageId,
replyMarkup
)
override fun method(): String = "sendVenue"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
}
fun Contact.toRequest(
chatId: ChatIdentifier,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): SendContact = SendContact(
chatId,
this,
disableNotification,
replyToMessageId,
replyMarkup
)