1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +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
* New request `CopyMessage`
* New extension `List<TextSource>#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`

View File

@ -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?
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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
)