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

The following examples show how to use org.telegram.telegrambots.meta.api.methods.send.SendMessage#enableMarkdown() . 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: 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 2
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private static SendMessage onDeleteAlertCommand(Message message, String language) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);

    sendMessage.setChatId(message.getChatId());

    ReplyKeyboardMarkup replyKeyboardMarkup = getAlertsListKeyboard(message.getFrom().getId(), language);
    if (replyKeyboardMarkup != null) {
        sendMessage.setReplyMarkup(replyKeyboardMarkup);
        sendMessage.setText(LocalisationService.getString("chooseNewAlertCity", language));
        DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERTDELETE);
    } else {
        sendMessage.setReplyMarkup(getAlertsKeyboard(language));
        sendMessage.setText(LocalisationService.getString("noAlertList", language));
    }

    sendMessage.setReplyToMessageId(message.getMessageId());
    return sendMessage;
}
 
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 onNewAlertCityReceived(Message message, String language) {
    int userId = message.getFrom().getId();
    Integer cityId = DatabaseManager.getInstance().getRecentWeatherIdByCity(userId, message.getText());
    if (cityId != null) {
        DatabaseManager.getInstance().createNewWeatherAlert(userId, cityId, message.getText());
        SendMessage sendMessageRequest = new SendMessage();
        sendMessageRequest.enableMarkdown(true);
        sendMessageRequest.setReplyMarkup(getAlertsKeyboard(language));
        sendMessageRequest.setReplyToMessageId(message.getMessageId());
        sendMessageRequest.setText(getChooseNewAlertSetMessage(message.getText(), language));
        sendMessageRequest.setChatId(message.getChatId());

        DatabaseManager.getInstance().insertWeatherState(userId, message.getChatId(), ALERT);
        return sendMessageRequest;
    } else {
        return sendChooseOptionMessage(message.getChatId(), message.getMessageId(),
                getRecentsKeyboard(message.getFrom().getId(), language, false), language);
    }
}
 
Example 5
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private static SendMessage onCurrentChoosen(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("onCurrentCommandFromHistory", language));
    } else {
        sendMessage.setText(LocalisationService.getString("onCurrentCommandWithoutHistory", language));
    }

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), CURRENTWEATHER);
    return sendMessage;
}
 
Example 6
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 7
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onLanguageChosen(Integer userId, Long chatId, Integer messageId, String language) {
    String languageCode = LocalisationService.getLanguageCodeByName(language);
    DatabaseManager.getInstance().putUserWeatherLanguageOption(userId, languageCode);

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

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

    sendMessage.setReplyToMessageId(message.getMessageId());
    sendMessage.setChatId(message.getChatId());
    sendMessage.setReplyMarkup(getUnitsKeyboard(language));
    sendMessage.setText(getUnitsMessage(message.getFrom().getId(), language));

    DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), UNITS);
    return sendMessage;
}
 
Example 9
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onCurrentWeatherReceived(Long chatId, Integer userId, Integer messageId, String text, String language) {
    String unitsSystem = DatabaseManager.getInstance().getUserWeatherOptions(userId)[1];
    String weather = WeatherService.getInstance().fetchWeatherCurrent(text, 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;
}
 
Example 10
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 11
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onNewCurrentWeatherCommand(Long chatId, Integer userId, Integer messageId, String language) {
    ForceReplyKeyboard forceReplyKeyboard = getForceReply();

    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(chatId.toString());
    sendMessage.setReplyToMessageId(messageId);
    sendMessage.setReplyMarkup(forceReplyKeyboard);
    sendMessage.setText(LocalisationService.getString("onWeatherNewCommand", language));

    DatabaseManager.getInstance().insertWeatherState(userId, chatId, CURRENTNEWWEATHER);
    return sendMessage;
}
 
Example 12
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onBackAlertCommand(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 13
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onNewForecastWeatherCommand(Long chatId, Integer userId, Integer messageId, String language) {
    ForceReplyKeyboard forceReplyKeyboard = getForceReply();

    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(chatId.toString());
    sendMessage.setReplyToMessageId(messageId);
    sendMessage.setReplyMarkup(forceReplyKeyboard);
    sendMessage.setText(LocalisationService.getString("onWeatherNewCommand", language));

    DatabaseManager.getInstance().insertWeatherState(userId, chatId, FORECASTNEWWEATHER);
    return sendMessage;
}
 
Example 14
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private void sendHideKeyboard(Integer userId, Long chatId, Integer messageId) throws TelegramApiException {
    SendMessage sendMessage = new SendMessage();
    sendMessage.setChatId(chatId.toString());
    sendMessage.enableMarkdown(true);
    sendMessage.setReplyToMessageId(messageId);
    sendMessage.setText(Emoji.WAVING_HAND_SIGN.toString());

    ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
    replyKeyboardRemove.setSelective(true);
    sendMessage.setReplyMarkup(replyKeyboardRemove);

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

    DatabaseManager.getInstance().insertWeatherState(userId, chatId, MAINMENU);
    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 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 17
Source File: ChannelHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage getWrongUsernameMessage(Message message) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(message.getChatId());
    sendMessage.setReplyToMessageId(message.getMessageId());

    ForceReplyKeyboard forceReplyKeyboard = new ForceReplyKeyboard();
    forceReplyKeyboard.setSelective(true);
    sendMessage.setReplyMarkup(forceReplyKeyboard);

    sendMessage.setText(WRONG_CHANNEL_TEXT);
    sendMessage.enableMarkdown(true);
    return sendMessage;
}
 
Example 18
Source File: ChannelHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private void sendErrorMessage(Message message, String errorText) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(message.getChatId());
    sendMessage.setReplyToMessageId(message.getMessageId());

    sendMessage.setText(String.format(ERROR_MESSAGE_TEXT, message.getText().trim(), errorText.replace("\"", "\\\"")));
    sendMessage.enableMarkdown(true);

    try {
        execute(sendMessage);
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
Example 19
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onLocationForecastWeatherCommand(Long chatId, Integer userId, Integer messageId, String language) {
    ForceReplyKeyboard forceReplyKeyboard = getForceReply();

    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(chatId.toString());
    sendMessage.setReplyToMessageId(messageId);
    sendMessage.setReplyMarkup(forceReplyKeyboard);
    sendMessage.setText(LocalisationService.getString("onWeatherLocationCommand", language));

    DatabaseManager.getInstance().insertWeatherState(userId, chatId, FORECASTLOCATIONWEATHER);
    return sendMessage;
}
 
Example 20
Source File: SilentSender.java    From TelegramBots with MIT License 5 votes vote down vote up
private Optional<Message> doSendMessage(String txt, long groupId, boolean format) {
  SendMessage smsg = new SendMessage();
  smsg.setChatId(groupId);
  smsg.setText(txt);
  smsg.enableMarkdown(format);

  return execute(smsg);
}