Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOT API v7.11 #401

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pengrad.telegrambot.model.request

data class CopyTextButton(
val text: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ data class InlineKeyboardButton @JvmOverloads constructor(
@get:JvmName("switchInlineQueryChosenChat") var switchInlineQueryChosenChat: SwitchInlineQueryChosenChat? = null,
@get:JvmName("callbackGame") var callbackGame: CallbackGame? = null,
var pay: Boolean? = null,
@get:JvmName("webApp") var webApp: WebAppInfo? = null
@get:JvmName("webApp") var webApp: WebAppInfo? = null,
@get:JvmName("copyText") var copyText: CopyTextButton? = null,
) {

fun url(url: String): InlineKeyboardButton {
Expand Down Expand Up @@ -65,6 +66,11 @@ data class InlineKeyboardButton @JvmOverloads constructor(
return this
}

fun copyText(copyText : CopyTextButton): InlineKeyboardButton {
this.copyText = copyText
return this
}

fun isPay(): Boolean {
return pay ?: false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pengrad.telegrambot.model.stars.partner;

import java.util.Objects;

public class TransactionPartnerTelegramApi extends TransactionPartner {

public final static String TYPE = "telegram_api";

private Integer request_count;

public TransactionPartnerTelegramApi() {
super(TYPE);
}

public Integer requestCount() {
return request_count;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TransactionPartnerTelegramApi)) return false;
if (!super.equals(o)) return false;
TransactionPartnerTelegramApi that = (TransactionPartnerTelegramApi) o;
return Objects.equals(request_count, that.request_count);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), request_count);
}

@Override
public String toString() {
return "TransactionPartnerTelegramApi{" +
"request_count=" + request_count +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public T protectContent(boolean protectContent) {
return add("protect_content", protectContent);
}

public T allowPaidBroadcast(boolean allowPaidBroadcast) {
return add("allow_paid_broadcast", allowPaidBroadcast);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public CopyMessage protectContent(boolean protectContent) {
return add("protect_content", protectContent);
}

public CopyMessage allowPaidBroadcast(boolean allowPaidBroadcast) {
return add("allow_paid_broadcast", allowPaidBroadcast);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ public SendPaidMedia replyMarkup(ForceReply replyMarkup) {
public SendPaidMedia payload(String payload) {
return add("payload", payload);
}

public SendPaidMedia allowPaidBroadcast(boolean allowPaidBroadcast) {
return add("allow_paid_broadcast", allowPaidBroadcast);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private BotUtils() {}
.registerTypeAdapter(BackgroundType.class, new BackgroundTypeAdapter())
.registerTypeAdapter(BackgroundFill.class, new BackgroundFillAdapter())
.registerTypeAdapter(RevenueWithdrawalState.class, new RevenueWithdrawalStateTypeAdapter())
.registerTypeAdapter(TransactionPartner.class, new TransactionPartnerTypeAdapter())
.registerTypeAdapter(TransactionPartner.class, TransactionPartnerTypeAdapter.INSTANCE)
.registerTypeAdapter(PaidMedia.class, new PaidMediaTypeAdapter())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.pengrad.telegrambot.utility.gson

import com.google.gson.*
import com.pengrad.telegrambot.model.stars.partner.*
import java.lang.reflect.Type

object TransactionPartnerTypeAdapter : JsonDeserializer<TransactionPartner> {

private val typeMapping = mapOf(
TransactionPartnerUser.TYPE to TransactionPartnerUser::class,
TransactionPartnerFragment.TYPE to TransactionPartnerFragment::class,
TransactionPartnerTelegramAds.TYPE to TransactionPartnerTelegramAds::class,
TransactionPartnerTelegramApi.TYPE to TransactionPartnerTelegramApi::class,
TransactionPartnerOther.TYPE to TransactionPartnerOther::class
)

@Throws(JsonParseException::class)
override fun deserialize(
element: JsonElement,
type: Type,
context: JsonDeserializationContext
): TransactionPartner {
val obj = element.asJsonObject
val discriminator = obj.getAsJsonPrimitive("type")?.asString ?: "unknown"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, Kotlin migration, such a beauty 😁


return typeMapping[discriminator]?.let {
context.deserialize(obj, it.java)
} ?: TransactionPartner(discriminator)
}

}