TDLightTelegramBots/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updates/GetWebhookInfo.java
2020-11-03 01:32:26 +00:00

60 lines
1.9 KiB
Java

package org.telegram.telegrambots.meta.api.methods.updates;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.WebhookInfo;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
/**
* @author Ruben Bermudez
* @version 2.4
* Use this method to get current webhook status.
* Requires no parameters.
* On success, returns a WebhookInfo object.
* Will throw an error, if the bot is using getUpdates.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
@Builder
public class GetWebhookInfo extends BotApiMethod<WebhookInfo> {
public static final String PATH = "getwebhookinfo";
@Override
public String getMethod() {
return PATH;
}
@Override
public WebhookInfo deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<WebhookInfo> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<WebhookInfo>>() {
});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error getting webhook info", result);
}
} catch (IOException e2) {
throw new TelegramApiRequestException("Unable to deserialize response", e2);
}
}
@Override
public void validate() throws TelegramApiValidationException {
}
}