diff --git a/CHANGELOG.md b/CHANGELOG.md index edb9298979..9c8621af44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ * Update all classes which must have `entities`/`caption_entities` fields * New request `CopyMessage` * New extension `List#makeString` for more comfortable work with new api with entities + * Support for Google Places identifiers for venues * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt index 6ee7716366..f3361259d1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt @@ -1,8 +1,15 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.FoursquareId +import dev.inmo.tgbotapi.types.FoursquareType +import dev.inmo.tgbotapi.types.GooglePlaceId +import dev.inmo.tgbotapi.types.GooglePlaceType + interface CommonVenueData : Titled { override val title: String val address: String - val foursquareId: String? - val foursquareType: String? // TODO:: Rewrite with enum or interface + val foursquareId: FoursquareId? + val foursquareType: FoursquareType? // TODO:: Rewrite with enum or interface + val googlePlaceId: GooglePlaceId? + val googlePlaceType: GooglePlaceType? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt index 63be242277..fe0c5f2825 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt @@ -25,7 +25,13 @@ data class SendVenue( @SerialName(addressField) val address: String, @SerialName(foursquareIdField) - val foursquareId: String? = null, + val foursquareId: FoursquareId? = null, + @SerialName(foursquareTypeField) + val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + val googlePlaceType: GooglePlaceType? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) @@ -47,16 +53,19 @@ data class SendVenue( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): this( - chatId, - venue.location.latitude, - venue.location.longitude, - venue.title, - venue.address, - venue.foursquareId, - disableNotification, - replyToMessageId, - allowSendingWithoutReply, - replyMarkup + chatId = chatId, + latitude = venue.location.latitude, + longitude = venue.location.longitude, + title = venue.title, + address = venue.address, + foursquareId = venue.foursquareId, + foursquareType = venue.foursquareType, + googlePlaceId = venue.googlePlaceId, + googlePlaceType = venue.googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) override fun method(): String = "sendVenue" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 5f17f8e6b8..af9fb30db5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -24,6 +24,8 @@ typealias FileUniqueId = String typealias DiceResult = Int typealias FoursquareId = String typealias FoursquareType = String +typealias GooglePlaceId = String +typealias GooglePlaceType = String typealias Seconds = Int typealias LongSeconds = Long @@ -126,6 +128,8 @@ const val showAlertField = "show_alert" const val cachedTimeField = "cached_time" const val foursquareIdField = "foursquare_id" const val foursquareTypeField = "foursquare_type" +const val googlePlaceIdField = "google_place_id" +const val googlePlaceTypeField = "google_place_type" const val untilDateField = "until_date" const val errorMessageField = "error_message" const val messageTextField = "message_text" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt index 30ec5796f2..e514afb1dd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt @@ -22,9 +22,13 @@ data class InlineQueryResultVenue( @SerialName(addressField) override val address: String, @SerialName(foursquareIdField) - override val foursquareId: String? = null, + override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: String? = null, + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null, @SerialName(thumbUrlField) override val thumbUrl: String? = null, @SerialName(thumbWidthField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt index f8be7df0c5..e744c10404 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt @@ -18,7 +18,11 @@ data class InputVenueMessageContent( @SerialName(addressField) override val address: String, @SerialName(foursquareIdField) - override val foursquareId: String? = null, + override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: String? = null + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null ) : Locationed, CommonVenueData, InputMessageContent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt index 6482709d5c..b27c18e1e7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt @@ -18,5 +18,9 @@ data class Venue( @SerialName(foursquareIdField) override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: FoursquareType? = null + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null ) : CommonVenueData, Locationed by location diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt index e23e7554e6..31cabb0734 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt @@ -3,6 +3,10 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendVenue import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.FoursquareId +import dev.inmo.tgbotapi.types.FoursquareType +import dev.inmo.tgbotapi.types.GooglePlaceId +import dev.inmo.tgbotapi.types.GooglePlaceType import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat @@ -16,14 +20,29 @@ suspend fun TelegramBot.sendVenue( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chatId, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) ) @@ -33,13 +52,28 @@ suspend fun TelegramBot.sendVenue( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chat.id, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -47,13 +81,28 @@ suspend fun TelegramBot.sendVenue( location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chatId, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chatId, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -61,13 +110,28 @@ suspend fun TelegramBot.sendVenue( location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chat.id, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -79,7 +143,12 @@ suspend fun TelegramBot.sendVenue( replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chatId, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) ) @@ -91,7 +160,12 @@ suspend fun TelegramBot.sendVenue( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId = chat.id, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( @@ -100,12 +174,27 @@ suspend inline fun TelegramBot.reply( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, latitude, longitude, title, address, foursquareId, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup + chat = to.chat, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( @@ -113,12 +202,27 @@ suspend inline fun TelegramBot.reply( location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, location, title, address, foursquareId, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup + chat = to.chat, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( @@ -128,5 +232,10 @@ suspend inline fun TelegramBot.reply( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, venue, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup + chat = to.chat, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt index 3651bb2581..66283981a9 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable val Venue.foursquare: Foursquare? - get() = foursquareId ?.let { + get() = foursquareId?.let { Foursquare(it, foursquareType) } @@ -16,7 +16,7 @@ fun Venue( title: String, address: String, foursquare: Foursquare -) = Venue(location, title, address, foursquare.id, foursquare.type) +) = Venue(location, title, address, foursquareId = foursquare.id, foursquareType = foursquare.type) @Serializable data class Foursquare( diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt new file mode 100644 index 0000000000..04ea6a6c62 --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt @@ -0,0 +1,27 @@ +package dev.inmo.tgbotapi.extensions.utils.extensions.venue + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation +import dev.inmo.tgbotapi.types.venue.Venue +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +val Venue.googlePlace: GooglePlace? + get() = googlePlaceId?.let { + GooglePlace(it, googlePlaceType) + } + +fun Venue( + location: StaticLocation, + title: String, + address: String, + googlePlace: GooglePlace +) = Venue(location, title, address, googlePlaceId = googlePlace.id, googlePlaceType = googlePlace.type) + +@Serializable +data class GooglePlace( + @SerialName(googlePlaceIdField) + val id: GooglePlaceId, + @SerialName(googlePlaceTypeField) + val type: GooglePlaceType? = null +)