SendInvoice and CreateInvoiceLink extends BotApiMethodMessage.
Since the class otApiMethodMessage implements the general behavior of a method deserializeResponse returning an object Message
This commit is contained in:
parent
c0ea9e1773
commit
e5d994f16d
@ -14,6 +14,7 @@ import lombok.Setter;
|
|||||||
import lombok.Singular;
|
import lombok.Singular;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
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.ApiResponse;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||||
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
|
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
|
||||||
@ -36,7 +37,7 @@ import java.util.List;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
public class CreateInvoiceLink extends BotApiMethod<Message> {
|
public class CreateInvoiceLink extends BotApiMethodMessage {
|
||||||
public static final String PATH = "createInvoiceLink";
|
public static final String PATH = "createInvoiceLink";
|
||||||
|
|
||||||
public static final String TITLE_FIELD = "title";
|
public static final String TITLE_FIELD = "title";
|
||||||
@ -135,21 +136,6 @@ public class CreateInvoiceLink extends BotApiMethod<Message> {
|
|||||||
return PATH;
|
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
|
@Override
|
||||||
public void validate() throws TelegramApiValidationException {
|
public void validate() throws TelegramApiValidationException {
|
||||||
if (Strings.isNullOrEmpty(title) || title.length() > 32) {
|
if (Strings.isNullOrEmpty(title) || title.length() > 32) {
|
||||||
|
@ -15,6 +15,7 @@ import lombok.Singular;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import lombok.experimental.Tolerate;
|
import lombok.experimental.Tolerate;
|
||||||
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
|
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.ApiResponse;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||||
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
|
import org.telegram.telegrambots.meta.api.objects.payments.LabeledPrice;
|
||||||
@ -38,7 +39,7 @@ import java.util.List;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
public class SendInvoice extends BotApiMethod<Message> {
|
public class SendInvoice extends BotApiMethodMessage {
|
||||||
public static final String PATH = "sendinvoice";
|
public static final String PATH = "sendinvoice";
|
||||||
|
|
||||||
private static final String CHATID_FIELD = "chat_id";
|
private static final String CHATID_FIELD = "chat_id";
|
||||||
@ -176,21 +177,6 @@ public class SendInvoice extends BotApiMethod<Message> {
|
|||||||
return PATH;
|
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
|
@Override
|
||||||
public void validate() throws TelegramApiValidationException {
|
public void validate() throws TelegramApiValidationException {
|
||||||
if (Strings.isNullOrEmpty(chatId)) {
|
if (Strings.isNullOrEmpty(chatId)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user