org.telegram.telegrambots.meta.api.methods.BotApiMethod Java Examples

The following examples show how to use org.telegram.telegrambots.meta.api.methods.BotApiMethod. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestApi.java    From TelegramBots with MIT License 6 votes vote down vote up
@POST
@Path("/{botPath}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateReceived(@PathParam("botPath") String botPath, Update update) {
    if (callbacks.containsKey(botPath)) {
        try {
            BotApiMethod response = callbacks.get(botPath).onWebhookUpdateReceived(update);
            if (response != null) {
                response.validate();
            }
            return Response.ok(response).build();
        } catch (TelegramApiValidationException e) {
            log.error(e.getLocalizedMessage(), e);
            return Response.serverError().build();
        }
    }

    return Response.status(Response.Status.NOT_FOUND).build();
}
 
Example #2
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getAnswerInlineQuery() {
    return new AnswerInlineQuery()
            .setInlineQueryId("id")
            .setPersonal(true)
            .setResults(getInlineQueryResultArticle(), getInlineQueryResultPhoto())
            .setCacheTime(100)
            .setNextOffset("3")
            .setSwitchPmParameter("PmParameter")
            .setSwitchPmText("pmText");
}
 
Example #3
Source File: WebHookExampleHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BotApiMethod onWebhookUpdateReceived(Update update) {
    if (update.hasMessage() && update.getMessage().hasText()) {
        SendMessage sendMessage = new SendMessage();
        sendMessage.setChatId(update.getMessage().getChatId().toString());
        sendMessage.setText("Well, all information looks like noise until you break the code.");
        return sendMessage;
    }
    return null;
}
 
Example #4
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getSendInvoice() {
    List<LabeledPrice> prices = new ArrayList<>();
    prices.add(new LabeledPrice("LABEL", 1000));

    return new SendInvoice()
            .setChatId(12345)
            .setTitle("Random title")
            .setDescription("Random description")
            .setPayload("Random Payload")
            .setProviderToken("Random provider token")
            .setStartParameter("STARTPARAM")
            .setCurrency("EUR")
            .setPrices(prices);
}
 
Example #5
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getSetGameScore() {
    return new SetGameScore()
            .setInlineMessageId("12345")
            .setDisableEditMessage(true)
            .setScore(12)
            .setUserId(98765);
}
 
Example #6
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getSendVenue() {
    return new SendVenue()
            .setChatId("12345")
            .setLatitude(12.5F)
            .setLongitude(21.5F)
            .setReplyToMessageId(53)
            .setTitle("Venue Title")
            .setAddress("Address")
            .setFoursquareId("FourId");
}
 
Example #7
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getSendLocation() {
    return new SendLocation()
            .setChatId("12345")
            .setLatitude(12.5F)
            .setLongitude(21.5F)
            .setReplyToMessageId(53);
}
 
Example #8
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getSendContact() {
    return new SendContact()
            .setChatId("12345")
            .setFirstName("First Name")
            .setLastName("Last Name")
            .setPhoneNumber("123456789")
            .setReplyMarkup(getKeyboardMarkup())
            .setReplyToMessageId(54);
}
 
Example #9
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getForwardMessage() {
    return new ForwardMessage(54L, 123L, 55)
            .setFromChatId("From")
            .setChatId("To")
            .setMessageId(15)
            .disableNotification();
}
 
Example #10
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getEditMessageText() {
    return new EditMessageText()
            .setChatId("ChatId")
            .setMessageId(1)
            .setText("Text")
            .setParseMode(ParseMode.MARKDOWN)
            .setReplyMarkup(getInlineKeyboardMarkup());
}
 
Example #11
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getEditMessageCaption() {
    return new EditMessageCaption()
            .setChatId("ChatId")
            .setMessageId(1)
            .setCaption("Caption")
            .setReplyMarkup(getInlineKeyboardMarkup());
}
 
Example #12
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
public static BotApiMethod getSendMessage() {
    return new SendMessage()
            .setChatId("@test")
            .setText("Hithere")
            .setReplyToMessageId(12)
            .setParseMode(ParseMode.HTML)
            .setReplyMarkup(new ForceReplyKeyboard());
}
 
Example #13
Source File: DefaultAbsSender.java    From TelegramBots with MIT License 5 votes vote down vote up
private <T extends Serializable, Method extends BotApiMethod<T>> String sendMethodRequest(Method method) throws TelegramApiValidationException, IOException {
    method.validate();
    String url = getBaseUrl() + method.getMethod();
    HttpPost httppost = configuredHttpPost(url);
    httppost.addHeader("charset", StandardCharsets.UTF_8.name());
    httppost.setEntity(new StringEntity(objectMapper.writeValueAsString(method), ContentType.APPLICATION_JSON));
    return sendHttpPostRequest(httppost);
}
 
Example #14
Source File: DefaultAbsSender.java    From TelegramBots with MIT License 5 votes vote down vote up
@Override
protected final <T extends Serializable, Method extends BotApiMethod<T>> T sendApiMethod(Method method) throws TelegramApiException {
    try {
        String responseContent = sendMethodRequest(method);
        return method.deserializeResponse(responseContent);
    } catch (IOException e) {
        throw new TelegramApiException("Unable to execute " + method.getMethod() + " method", e);
    }
}
 
Example #15
Source File: TelegramBot.java    From telegram-notifications-plugin with MIT License 5 votes vote down vote up
private <T extends Serializable, Method extends BotApiMethod<T>> T sendApiMethodWithProxy(
        Method method) throws TelegramApiException {
    try {
        String responseContent = sendMethodRequest(method);
        return method.deserializeResponse(responseContent);
    } catch (IOException e) {
        throw new TelegramApiException(
                String.format("Unable to execute %s method", method.getMethod()), e);
    }
}
 
Example #16
Source File: TelegramBot.java    From telegram-notifications-plugin with MIT License 5 votes vote down vote up
private <T extends Serializable, Method extends BotApiMethod<T>> String sendMethodRequest(
        Method method) throws TelegramApiValidationException, IOException {
    method.validate();
    String url = getBaseUrl() + method.getMethod();
    HttpPost httpPost = configuredHttpPost(url);
    httpPost.addHeader("charset", StandardCharsets.UTF_8.name());
    httpPost.setEntity(new StringEntity(
            objectMapper.writeValueAsString(method), ContentType.APPLICATION_JSON));
    return sendHttpPostRequest(httpPost);
}
 
Example #17
Source File: SilentSender.java    From TelegramBots with MIT License 5 votes vote down vote up
public <T extends Serializable, Method extends BotApiMethod<T>> Optional<T> execute(Method method) {
  try {
    return Optional.ofNullable(sender.execute(method));
  } catch (TelegramApiException e) {
    log.error("Could not execute bot API method", e);
    return Optional.empty();
  }
}
 
Example #18
Source File: AbsSender.java    From TelegramBots with MIT License 5 votes vote down vote up
public <T extends Serializable, Method extends BotApiMethod<T>, Callback extends SentCallback<T>> void executeAsync(Method method, Callback callback) throws TelegramApiException {
    if (method == null) {
        throw new TelegramApiException("Parameter method can not be null");
    }
    if (callback == null) {
        throw new TelegramApiException("Parameter callback can not be null");
    }
    sendApiMethodAsync(method, callback);
}
 
Example #19
Source File: SilentSender.java    From TelegramBots with MIT License 5 votes vote down vote up
public <T extends Serializable, Method extends BotApiMethod<T>, Callback extends SentCallback<T>> void
executeAsync(Method method, Callback callable) {
  try {
    sender.executeAsync(method, callable);
  } catch (TelegramApiException e) {
    log.error("Could not execute bot API method", e);
  }
}
 
Example #20
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getGetFile() {
    return new GetFile()
            .setFileId("FileId");
}
 
Example #21
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getChatMember() {
    return new GetChatMember()
            .setChatId("12345")
            .setUserId(98765);
}
 
Example #22
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getGetGameHighScores() {
    return new GetGameHighScores()
            .setChatId("12345")
            .setMessageId(67890)
            .setUserId(98765);
}
 
Example #23
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getGetMe() {
    return new GetMe();
}
 
Example #24
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getGetUserProfilePhotos() {
    return new GetUserProfilePhotos()
            .setUserId(98765)
            .setLimit(10)
            .setOffset(3);
}
 
Example #25
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getGetWebhookInfo() {
    return new GetWebhookInfo();
}
 
Example #26
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getKickChatMember() {
    return new KickChatMember()
            .setChatId("12345")
            .setUserId(98765);
}
 
Example #27
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getLeaveChat() {
    return new LeaveChat()
            .setChatId("12345");
}
 
Example #28
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getSendChatAction() {
    return new SendChatAction()
            .setChatId("12345")
            .setAction(ActionType.RECORDVIDEO);
}
 
Example #29
Source File: DefaultSender.java    From TelegramBots with MIT License 4 votes vote down vote up
@Override
public <T extends Serializable, Method extends BotApiMethod<T>> T execute(Method method) throws TelegramApiException {
  return bot.execute(method);
}
 
Example #30
Source File: BotApiMethodHelperFactory.java    From TelegramBots with MIT License 4 votes vote down vote up
public static BotApiMethod getSendGame() {
    return new SendGame()
            .setChatId("12345")
            .setGameShortName("MyGame");
}