Merge pull request #1096 from timursergeevichname/update

SendInvoice and CreateInvoiceLink extends BotApiMethodMessage.
This commit is contained in:
Ruben Bermudez 2022-08-15 01:54:41 +01:00 committed by GitHub
commit f85c52aaf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 32 deletions

View File

@ -14,6 +14,7 @@ import lombok.Setter;
import lombok.Singular;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
@ -36,7 +37,7 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CreateInvoiceLink extends BotApiMethod<Message> {
public class CreateInvoiceLink extends BotApiMethodMessage {
public static final String PATH = "createInvoiceLink";
public static final String TITLE_FIELD = "title";
@ -135,21 +136,6 @@ public class CreateInvoiceLink extends BotApiMethod<Message> {
return PATH;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error sending invoice", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(title) || title.length() > 32) {

View File

@ -15,6 +15,7 @@ import lombok.Singular;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
@ -38,7 +39,7 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SendInvoice extends BotApiMethod<Message> {
public class SendInvoice extends BotApiMethodMessage {
public static final String PATH = "sendinvoice";
private static final String CHATID_FIELD = "chat_id";
@ -176,21 +177,6 @@ public class SendInvoice extends BotApiMethod<Message> {
return PATH;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error sending invoice", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (Strings.isNullOrEmpty(chatId)) {