TelegramBots/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updates/LogOut.java

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.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
import java.io.IOException;
/**
* @author Ruben Bermudez
* @version 2.4
* Use this method to log out from the cloud Bot API server before launching the bot locally.
* You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates.
* After a successful call, you will not be able to log in again using the same token for 10 minutes.
* Returns True on success.
* Requires no parameters.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@AllArgsConstructor
@Builder
public class LogOut extends BotApiMethod<Boolean> {
public static final String PATH = "logOut";
@Override
public String getMethod() {
return PATH;
}
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>() {
});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error logging out", result);
}
} catch (IOException e2) {
throw new TelegramApiRequestException("Unable to deserialize response", e2);
}
}
@Override
public void validate() throws TelegramApiValidationException {
}
}