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

The following examples show how to use org.telegram.telegrambots.meta.api.methods.send.SendMessage#setText() . 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 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 2
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 3
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 4
Source File: TransifexHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 6 votes vote down vote up
private void sendMovedToMessage(Message message) throws InvalidObjectException, TelegramApiException {
    String language = DatabaseManager.getInstance().getUserLanguage(message.getFrom().getId());
    SendMessage answer = new SendMessage();
    answer.setChatId(message.getChatId());
    answer.setReplyToMessageId(message.getMessageId());
    answer.setText(LocalisationService.getString("movedToLangBot", language));
    InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
    List<List<InlineKeyboardButton>> rows = new ArrayList<>();
    List<InlineKeyboardButton> row = new ArrayList<>();
    InlineKeyboardButton button = new InlineKeyboardButton();
    button.setText(LocalisationService.getString("checkLangBot", language));
    button.setUrl("https://telegram.me/langbot");
    row.add(button);
    rows.add(row);
    inlineKeyboardMarkup.setKeyboard(rows);
    answer.setReplyMarkup(inlineKeyboardMarkup);
    execute(answer);
}
 
Example 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onBackLanguageCommand(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 12
Source File: ChannelHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private void sendMessageToChannel(String username, Message message) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(username.trim());

    sendMessage.setText(CHANNEL_MESSAGE_TEXT);
    sendMessage.enableMarkdown(true);

    try {
        execute(sendMessage);
    } catch (TelegramApiException e) {
        sendErrorMessage(message, e.getMessage());
    }
}
 
Example 13
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 14
Source File: StatusCommand.java    From telegram-notifications-plugin with MIT License 5 votes vote down vote up
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
    Subscribers subscribers = Subscribers.getInstance();
    String toSend;

    Long id = chat.getId();

    boolean isSubscribed = subscribers.isSubscribed(id);

    if (isSubscribed) {
        boolean isApproved = subscribers.isApproved(id);

        if (CONFIG.getApprovalType() == UserApprover.ApprovalType.ALL) {
            toSend = botStrings.get("message.status.approved");
        } else {
            toSend = isApproved
                    ? botStrings.get("message.status.approved")
                    : botStrings.get("message.status.unapproved");
        }
    } else {
        toSend = botStrings.get("message.status.unsubscribed");
    }

    SendMessage answer = new SendMessage();
    answer.setChatId(chat.getId().toString());
    answer.setText(toSend);

    try {
        absSender.execute(answer);
    } catch (TelegramApiException e) {
        LOGGER.error(LOG_TAG, e);
    }
}
 
Example 15
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 16
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 17
Source File: TelegramBot.java    From telegram-notifications-plugin with MIT License 5 votes vote down vote up
public void sendMessage(Long chatId, String message) {
    final SendMessage sendMessageRequest = new SendMessage();

    sendMessageRequest.setChatId(chatId.toString());
    sendMessageRequest.setText(message);
    sendMessageRequest.enableMarkdown(true);

    try {
        execute(sendMessageRequest);
    } catch (TelegramApiException e) {
        LOG.log(Level.SEVERE, String.format(
                "TelegramBot: Error while sending message: %s%n%s", chatId, message), e);
    }
}
 
Example 18
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 19
Source File: WeatherHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 5 votes vote down vote up
private static SendMessage onBackUnitsCommand(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 20
Source File: DirectionsHandlers.java    From TelegramBotsExample with GNU General Public License v3.0 4 votes vote down vote up
private void handleDirections(Update update) throws InvalidObjectException {
    Message message = update.getMessage();
    if (message != null && message.hasText()) {
        if (languageMessages.contains(message.getFrom().getId())) {
            onLanguageSelected(message);
        } else {
            String language = DatabaseManager.getInstance().getUserLanguage(update.getMessage().getFrom().getId());
            if (message.getText().startsWith(Commands.setLanguageCommand)) {
                onSetLanguageCommand(message, language);
            } else if (message.getText().startsWith(Commands.startDirectionCommand)) {
                onStartdirectionsCommand(message, language);
            } else if ((message.getText().startsWith(Commands.help) ||
                    (message.getText().startsWith(Commands.startCommand) || !message.isGroupMessage())) &&
                    DatabaseManager.getInstance().getUserDestinationStatus(message.getFrom().getId()) == -1) {
                sendHelpMessage(message, language);
            } else if (!message.getText().startsWith("/")) {
                if (DatabaseManager.getInstance().getUserDestinationStatus(message.getFrom().getId()) == WATING_ORIGIN_STATUS &&
                        message.isReply() &&
                        DatabaseManager.getInstance().getUserDestinationMessageId(message.getFrom().getId()) == message.getReplyToMessage().getMessageId()) {
                    onOriginReceived(message, language);

                } else if (DatabaseManager.getInstance().getUserDestinationStatus(message.getFrom().getId()) == WATING_DESTINY_STATUS &&
                        message.isReply() &&
                        DatabaseManager.getInstance().getUserDestinationMessageId(message.getFrom().getId()) == message.getReplyToMessage().getMessageId()) {
                    onDestinationReceived(message, language);
                } else if (!message.isReply()) {
                    if (DatabaseManager.getInstance().getUserDestinationStatus(message.getFrom().getId()) == -1) {
                        sendHelpMessage(message, language);
                    } else {
                        SendMessage sendMessageRequest = new SendMessage();
                        sendMessageRequest.setText(LocalisationService.getString("youNeedReplyDirections", language));
                        sendMessageRequest.setChatId(message.getChatId());
                        try {
                            execute(sendMessageRequest);
                        } catch (TelegramApiException e) {
                            BotLogger.error(LOGTAG, e);
                        }
                    }
                }
            }
        }
    }
}