Java Code Examples for org.telegram.telegrambots.meta.api.methods.send.SendMessage#setReplyMarkup()

The following examples show how to use org.telegram.telegrambots.meta.api.methods.send.SendMessage#setReplyMarkup() . 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: FilesHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private void onLanguageReceived(Message message) throws InvalidObjectException, TelegramApiException {
    String[] parts = message.getText().split(Emoji.LEFT_RIGHT_ARROW.toString(), 2);
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.setChatId(message.getChatId());
    if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) {
        DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim());
        sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim()));
    } else {
        sendMessageRequest.setText(LocalisationService.getString("errorLanguage"));
    }
    sendMessageRequest.setReplyToMessageId(message.getMessageId());
    ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
    replyKeyboardRemove.setSelective(true);
    sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
    execute(sendMessageRequest);
    languageMessages.remove(message.getFrom().getId());
}
 
Example 2
Source File: FilesHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private void onDeleteCommandWithoutParameters(Message message, String language) throws InvalidObjectException, TelegramApiException {
    DatabaseManager.getInstance().addUserForFile(message.getFrom().getId(), DELETE_UPLOADED_STATUS);
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.setText(LocalisationService.getString("deleteUploadedFile", language));
    sendMessageRequest.setChatId(message.getChatId());
    HashMap<String, String> files = DatabaseManager.getInstance().getFilesByUser(message.getFrom().getId());
    ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
    if (files.size() > 0) {
        List<KeyboardRow> commands = new ArrayList<>();
        for (Map.Entry<String, String> entry : files.entrySet()) {
            KeyboardRow commandRow = new KeyboardRow();
            commandRow.add(Commands.deleteCommand + " " + entry.getKey() + " " + Emoji.LEFT_RIGHT_ARROW.toString()
                    + " " + entry.getValue());
            commands.add(commandRow);
        }
        replyKeyboardMarkup.setResizeKeyboard(true);
        replyKeyboardMarkup.setOneTimeKeyboard(true);
        replyKeyboardMarkup.setKeyboard(commands);
    }
    sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
    execute(sendMessageRequest);
}
 
Example 3
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private static SendMessage onCurrentWeatherCityReceived(Long chatId, Integer userId, Integer messageId, String text, String language) {
    Integer cityId = DatabaseManager.getInstance().getRecentWeatherIdByCity(userId, text);
    if (cityId != null) {
        String unitsSystem = DatabaseManager.getInstance().getUserWeatherOptions(userId)[1];
        String weather = WeatherService.getInstance().fetchWeatherCurrent(cityId.toString(), userId, language, unitsSystem);
        SendMessage sendMessageRequest = new SendMessage();
        sendMessageRequest.enableMarkdown(true);
        sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language));
        sendMessageRequest.setReplyToMessageId(messageId);
        sendMessageRequest.setText(weather);
        sendMessageRequest.setChatId(chatId.toString());
        DatabaseManager.getInstance().insertWeatherState(userId, chatId, MAINMENU);
        return sendMessageRequest;
    } else {
        return sendChooseOptionMessage(chatId, messageId, getRecentsKeyboard(userId, language), language);
    }
}
 
Example 4
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private static SendMessage onForecastChoosen(Message message, String language) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);

    ReplyKeyboardMarkup replyKeyboardMarkup = getRecentsKeyboard(message.getFrom().getId(), language);
    sendMessage.setReplyMarkup(replyKeyboardMarkup);
    sendMessage.setReplyToMessageId(message.getMessageId());
    sendMessage.setChatId(message.getChatId());
    if (replyKeyboardMarkup.getKeyboard().size() > 3) {
        sendMessage.setText(LocalisationService.getString("onForecastCommandFromHistory", language));
    } else {
        sendMessage.setText(LocalisationService.getString("onForecastCommandWithoutHistory", language));
    }

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), FORECASTWEATHER);
    return sendMessage;
}
 
Example 5
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private static SendMessage onAlertNewOptionSelected(Message message, String language) {
    SendMessage sendMessageRequest = null;
    if (message.hasText()) {
        if (message.getText().equals(getCancelCommand(language))) {
            SendMessage sendMessage = new SendMessage();
            sendMessage.enableMarkdown(true);
            sendMessage.setChatId(message.getChatId());
            sendMessage.setReplyToMessageId(message.getMessageId());
            sendMessage.setReplyMarkup(getAlertsKeyboard(language));
            sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language));
            DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERT);
            sendMessageRequest = sendMessage;
        } else {
            sendMessageRequest = onNewAlertCityReceived(message, language);
        }
    }
    return sendMessageRequest;
}
 
Example 6
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private static SendMessage onForecastWeatherCityReceived(Long chatId, Integer userId, Integer messageId, String text, String language) {
    Integer cityId = DatabaseManager.getInstance().getRecentWeatherIdByCity(userId, text);
    if (cityId != null) {
        String unitsSystem = DatabaseManager.getInstance().getUserWeatherOptions(userId)[1];
        String weather = WeatherService.getInstance().fetchWeatherForecast(cityId.toString(), userId, language, unitsSystem);
        SendMessage sendMessageRequest = new SendMessage();
        sendMessageRequest.enableMarkdown(true);
        sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language));
        sendMessageRequest.setReplyToMessageId(messageId);
        sendMessageRequest.setText(weather);
        sendMessageRequest.setChatId(chatId.toString());

        DatabaseManager.getInstance().insertWeatherState(userId, chatId, MAINMENU);
        return sendMessageRequest;
    } else {
        return sendChooseOptionMessage(chatId, messageId, getRecentsKeyboard(userId, language), language);
    }
}
 
Example 7
Source File: DirectionsHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private void onLanguageSelected(Message message) throws InvalidObjectException {
    String[] parts = message.getText().split("-->", 2);
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.setChatId(message.getChatId());
    if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) {
        DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim());
        sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim()));
    } else {
        sendMessageRequest.setText(LocalisationService.getString("errorLanguage"));
    }
    sendMessageRequest.setReplyToMessageId(message.getMessageId());
    ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
    replyKeyboardRemove.setSelective(true);
    sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
    try {
        execute(sendMessageRequest);
        languageMessages.remove(message.getFrom().getId());
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
Example 8
Source File: DirectionsHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private void onSetLanguageCommand(Message message, String language) throws InvalidObjectException {
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.setChatId(message.getChatId());
    ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
    List<LocalisationService.Language> languages = LocalisationService.getSupportedLanguages();
    List<KeyboardRow> commands = new ArrayList<>();
    for (LocalisationService.Language languageItem : languages) {
        KeyboardRow commandRow = new KeyboardRow();
        commandRow.add(languageItem.getCode() + " --> " + languageItem.getName());
        commands.add(commandRow);
    }
    replyKeyboardMarkup.setResizeKeyboard(true);
    replyKeyboardMarkup.setOneTimeKeyboard(true);
    replyKeyboardMarkup.setKeyboard(commands);
    replyKeyboardMarkup.setSelective(true);
    sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
    sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language));
    try {
        execute(sendMessageRequest);
        languageMessages.add(message.getFrom().getId());
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
Example 9
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage sendHelpMessage(Long chatId, Integer messageId, ReplyKeyboardMarkup replyKeyboardMarkup, String language) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(chatId);
    sendMessage.setReplyToMessageId(messageId);
    if (replyKeyboardMarkup != null) {
        sendMessage.setReplyMarkup(replyKeyboardMarkup);
    }
    sendMessage.setText(getHelpMessage(language));
    return sendMessage;
}
 
Example 10
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onAlertDeleteCityOptionSelected(Message message, String language) {
    DatabaseManager.getInstance().deleteAlertCity(message.getFrom().getId(), message.getText());
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setReplyToMessageId(message.getMessageId());
    sendMessage.setChatId(message.getChatId());
    sendMessage.setReplyMarkup(getAlertsKeyboard(language));
    sendMessage.setText(LocalisationService.getString("alertDeleted", language));

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERT);
    return sendMessage;
}
 
Example 11
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onUnitsChosen(Integer userId, Long chatId, Integer messageId, String units, String language) {
    DatabaseManager.getInstance().putUserWeatherUnitsOption(userId, units);

    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.enableMarkdown(true);
    sendMessageRequest.setChatId(chatId.toString());
    sendMessageRequest.setText(LocalisationService.getString("unitsUpdated", language));
    sendMessageRequest.setReplyToMessageId(messageId);
    sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language));

    DatabaseManager.getInstance().insertWeatherState(userId, chatId, MAINMENU);
    return sendMessageRequest;
}
 
Example 12
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage sendChooseOptionMessage(Long chatId, Integer messageId,
                                            ReplyKeyboard replyKeyboard, String language) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(chatId.toString());
    sendMessage.setReplyToMessageId(messageId);
    sendMessage.setReplyMarkup(replyKeyboard);
    sendMessage.setText(LocalisationService.getString("chooseOption", language));

    return sendMessage;
}
 
Example 13
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onForecastWeatherLocationReceived(Message message, String language) {
    String unitsSystem = DatabaseManager.getInstance().getUserWeatherOptions(message.getFrom().getId())[1];
    String weather = WeatherService.getInstance().fetchWeatherForecastByLocation(message.getLocation().getLongitude(),
            message.getLocation().getLatitude(), message.getFrom().getId(), language, unitsSystem);
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.enableMarkdown(true);
    sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language));
    sendMessageRequest.setReplyToMessageId(message.getMessageId());
    sendMessageRequest.setText(weather);
    sendMessageRequest.setChatId(message.getChatId());

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), MAINMENU);
    return sendMessageRequest;
}
 
Example 14
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onSettingsChoosen(Message message, String language) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);

    ReplyKeyboardMarkup replyKeyboardMarkup = getSettingsKeyboard(language);
    sendMessage.setReplyMarkup(replyKeyboardMarkup);
    sendMessage.setReplyToMessageId(message.getMessageId());
    sendMessage.setChatId(message.getChatId());
    sendMessage.setText(getSettingsMessage(language));

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), SETTINGS);
    return sendMessage;
}
 
Example 15
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onNewAlertCommand(Message message, String language) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);

    sendMessage.setChatId(message.getChatId());
    sendMessage.setReplyMarkup(getRecentsKeyboard(message.getFrom().getId(), language, false));
    sendMessage.setText(LocalisationService.getString("chooseNewAlertCity", language));
    sendMessage.setReplyToMessageId(message.getMessageId());

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERTNEW);
    return sendMessage;
}
 
Example 16
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onCurrentWeatherLocationReceived(Message message, String language) {
    String unitsSystem = DatabaseManager.getInstance().getUserWeatherOptions(message.getFrom().getId())[1];
    String weather = WeatherService.getInstance().fetchWeatherCurrentByLocation(message.getLocation().getLongitude(),
            message.getLocation().getLatitude(), message.getFrom().getId(), language, unitsSystem);
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.enableMarkdown(true);
    sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language));
    sendMessageRequest.setReplyToMessageId(message.getMessageId());
    sendMessageRequest.setText(weather);
    sendMessageRequest.setChatId(message.getChatId());

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), MAINMENU);
    return sendMessageRequest;
}
 
Example 17
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onLanguageError(Long chatId, Integer messageId, String language) {
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.enableMarkdown(true);
    sendMessageRequest.setChatId(chatId.toString());
    sendMessageRequest.setReplyMarkup(getLanguagesKeyboard(language));
    sendMessageRequest.setText(LocalisationService.getString("errorLanguageNotFound", language));
    sendMessageRequest.setReplyToMessageId(messageId);

    return sendMessageRequest;
}
 
Example 18
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onLanguageCommand(Message message, String language) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);

    sendMessage.setReplyToMessageId(message.getMessageId());
    sendMessage.setChatId(message.getChatId());
    sendMessage.setReplyMarkup(getLanguagesKeyboard(language));
    sendMessage.setText(getLanguageMessage(language));

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), LANGUAGE);
    return sendMessage;
}
 
Example 19
Source File: SilentSender.java    From TelegramBots with MIT License 5 votes vote down vote up
public Optional<Message> forceReply(String message, long id) {
  SendMessage msg = new SendMessage();
  msg.setText(message);
  msg.setChatId(id);
  msg.setReplyMarkup(new ForceReplyKeyboard());

  return execute(msg);
}
 
Example 20
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onUnitsError(Long chatId, Integer messageId, String language) {
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.enableMarkdown(true);
    sendMessageRequest.setChatId(chatId.toString());
    sendMessageRequest.setReplyMarkup(getUnitsKeyboard(language));
    sendMessageRequest.setText(LocalisationService.getString("errorUnitsNotFound", language));
    sendMessageRequest.setReplyToMessageId(messageId);

    return sendMessageRequest;
}