1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-29 13:38:43 +00:00

Merge pull request #198 from madhead/issues/190

Fix #190: Support for Google Places values in venue-related methods and types
This commit is contained in:
InsanusMokrassar 2020-11-06 11:23:29 +06:00 committed by GitHub
commit cf47cee36a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 204 additions and 35 deletions

View File

@ -66,6 +66,7 @@
* Update all classes which must have `entities`/`caption_entities` fields * Update all classes which must have `entities`/`caption_entities` fields
* New request `CopyMessage` * New request `CopyMessage`
* New extension `List<TextSource>#makeString` for more comfortable work with new api with entities * New extension `List<TextSource>#makeString` for more comfortable work with new api with entities
* Support for Google Places identifiers for venues
* `API`: * `API`:
* Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat`
* New extensions `TelegramBot#unpinAllChatMessages` * New extensions `TelegramBot#unpinAllChatMessages`

View File

@ -1,8 +1,15 @@
package dev.inmo.tgbotapi.CommonAbstracts 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 { interface CommonVenueData : Titled {
override val title: String override val title: String
val address: String val address: String
val foursquareId: String? val foursquareId: FoursquareId?
val foursquareType: String? // TODO:: Rewrite with enum or interface val foursquareType: FoursquareType? // TODO:: Rewrite with enum or interface
val googlePlaceId: GooglePlaceId?
val googlePlaceType: GooglePlaceType?
} }

View File

@ -25,7 +25,13 @@ data class SendVenue(
@SerialName(addressField) @SerialName(addressField)
val address: String, val address: String,
@SerialName(foursquareIdField) @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) @SerialName(disableNotificationField)
override val disableNotification: Boolean = false, override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField) @SerialName(replyToMessageIdField)
@ -47,16 +53,19 @@ data class SendVenue(
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): this( ): this(
chatId, chatId = chatId,
venue.location.latitude, latitude = venue.location.latitude,
venue.location.longitude, longitude = venue.location.longitude,
venue.title, title = venue.title,
venue.address, address = venue.address,
venue.foursquareId, foursquareId = venue.foursquareId,
disableNotification, foursquareType = venue.foursquareType,
replyToMessageId, googlePlaceId = venue.googlePlaceId,
allowSendingWithoutReply, googlePlaceType = venue.googlePlaceType,
replyMarkup disableNotification = disableNotification,
replyToMessageId = replyToMessageId,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
) )
override fun method(): String = "sendVenue" override fun method(): String = "sendVenue"

View File

@ -24,6 +24,8 @@ typealias FileUniqueId = String
typealias DiceResult = Int typealias DiceResult = Int
typealias FoursquareId = String typealias FoursquareId = String
typealias FoursquareType = String typealias FoursquareType = String
typealias GooglePlaceId = String
typealias GooglePlaceType = String
typealias Seconds = Int typealias Seconds = Int
typealias LongSeconds = Long typealias LongSeconds = Long
@ -126,6 +128,8 @@ const val showAlertField = "show_alert"
const val cachedTimeField = "cached_time" const val cachedTimeField = "cached_time"
const val foursquareIdField = "foursquare_id" const val foursquareIdField = "foursquare_id"
const val foursquareTypeField = "foursquare_type" const val foursquareTypeField = "foursquare_type"
const val googlePlaceIdField = "google_place_id"
const val googlePlaceTypeField = "google_place_type"
const val untilDateField = "until_date" const val untilDateField = "until_date"
const val errorMessageField = "error_message" const val errorMessageField = "error_message"
const val messageTextField = "message_text" const val messageTextField = "message_text"

View File

@ -22,9 +22,13 @@ data class InlineQueryResultVenue(
@SerialName(addressField) @SerialName(addressField)
override val address: String, override val address: String,
@SerialName(foursquareIdField) @SerialName(foursquareIdField)
override val foursquareId: String? = null, override val foursquareId: FoursquareId? = null,
@SerialName(foursquareTypeField) @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) @SerialName(thumbUrlField)
override val thumbUrl: String? = null, override val thumbUrl: String? = null,
@SerialName(thumbWidthField) @SerialName(thumbWidthField)

View File

@ -18,7 +18,11 @@ data class InputVenueMessageContent(
@SerialName(addressField) @SerialName(addressField)
override val address: String, override val address: String,
@SerialName(foursquareIdField) @SerialName(foursquareIdField)
override val foursquareId: String? = null, override val foursquareId: FoursquareId? = null,
@SerialName(foursquareTypeField) @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 ) : Locationed, CommonVenueData, InputMessageContent

View File

@ -18,5 +18,9 @@ data class Venue(
@SerialName(foursquareIdField) @SerialName(foursquareIdField)
override val foursquareId: FoursquareId? = null, override val foursquareId: FoursquareId? = null,
@SerialName(foursquareTypeField) @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 ) : CommonVenueData, Locationed by location

View File

@ -3,6 +3,10 @@ package dev.inmo.tgbotapi.extensions.api.send
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.send.SendVenue import dev.inmo.tgbotapi.requests.send.SendVenue
import dev.inmo.tgbotapi.types.ChatIdentifier 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.MessageIdentifier
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
@ -16,14 +20,29 @@ suspend fun TelegramBot.sendVenue(
longitude: Double, longitude: Double,
title: String, title: String,
address: String, address: String,
foursquareId: String? = null, foursquareId: FoursquareId? = null,
foursquareType: FoursquareType? = null,
googlePlaceId: GooglePlaceId? = null,
googlePlaceType: GooglePlaceType? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = execute( ) = execute(
SendVenue( 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, longitude: Double,
title: String, title: String,
address: String, address: String,
foursquareId: String? = null, foursquareId: FoursquareId? = null,
foursquareType: FoursquareType? = null,
googlePlaceId: GooglePlaceId? = null,
googlePlaceType: GooglePlaceType? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVenue( ) = 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( suspend fun TelegramBot.sendVenue(
@ -47,13 +81,28 @@ suspend fun TelegramBot.sendVenue(
location: StaticLocation, location: StaticLocation,
title: String, title: String,
address: String, address: String,
foursquareId: String? = null, foursquareId: FoursquareId? = null,
foursquareType: FoursquareType? = null,
googlePlaceId: GooglePlaceId? = null,
googlePlaceType: GooglePlaceType? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVenue( ) = 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( suspend fun TelegramBot.sendVenue(
@ -61,13 +110,28 @@ suspend fun TelegramBot.sendVenue(
location: StaticLocation, location: StaticLocation,
title: String, title: String,
address: String, address: String,
foursquareId: String? = null, foursquareId: FoursquareId? = null,
foursquareType: FoursquareType? = null,
googlePlaceId: GooglePlaceId? = null,
googlePlaceType: GooglePlaceType? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVenue( ) = 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( suspend fun TelegramBot.sendVenue(
@ -79,7 +143,12 @@ suspend fun TelegramBot.sendVenue(
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = execute( ) = execute(
SendVenue( 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, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVenue( ) = 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( suspend inline fun TelegramBot.reply(
@ -100,12 +174,27 @@ suspend inline fun TelegramBot.reply(
longitude: Double, longitude: Double,
title: String, title: String,
address: String, address: String,
foursquareId: String? = null, foursquareId: FoursquareId? = null,
foursquareType: FoursquareType? = null,
googlePlaceId: GooglePlaceId? = null,
googlePlaceType: GooglePlaceType? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVenue( ) = 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( suspend inline fun TelegramBot.reply(
@ -113,12 +202,27 @@ suspend inline fun TelegramBot.reply(
location: StaticLocation, location: StaticLocation,
title: String, title: String,
address: String, address: String,
foursquareId: String? = null, foursquareId: FoursquareId? = null,
foursquareType: FoursquareType? = null,
googlePlaceId: GooglePlaceId? = null,
googlePlaceType: GooglePlaceType? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVenue( ) = 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( suspend inline fun TelegramBot.reply(
@ -128,5 +232,10 @@ suspend inline fun TelegramBot.reply(
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendVenue( ) = sendVenue(
to.chat, venue, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup chat = to.chat,
venue = venue,
disableNotification = disableNotification,
replyToMessageId = to.messageId,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
) )

View File

@ -16,7 +16,7 @@ fun Venue(
title: String, title: String,
address: String, address: String,
foursquare: Foursquare foursquare: Foursquare
) = Venue(location, title, address, foursquare.id, foursquare.type) ) = Venue(location, title, address, foursquareId = foursquare.id, foursquareType = foursquare.type)
@Serializable @Serializable
data class Foursquare( data class Foursquare(

View File

@ -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
)