org.telegram.telegrambots.meta.api.methods.send.SendMessage Java Examples
The following examples show how to use
org.telegram.telegrambots.meta.api.methods.send.SendMessage.
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: UnsubCommand.java From telegram-notifications-plugin with MIT License | 7 votes |
@Override public void execute(AbsSender absSender, User user, Chat chat, String[] strings) { Subscribers subscribers = Subscribers.getInstance(); String ans; Long id = chat.getId(); boolean isSubscribed = subscribers.isSubscribed(id); if (isSubscribed) { subscribers.unsubscribe(id); ans = botStrings.get("message.unsub.success"); } else { ans = botStrings.get("message.unsub.alreadyunsub"); } SendMessage answer = new SendMessage(); answer.setChatId(chat.getId().toString()); answer.setText(ans); try { absSender.execute(answer); } catch (TelegramApiException e) { LOGGER.error(LOG_TAG, e); } }
Example #2
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private static SendMessage messageOnMainMenu(Message message, String language) { SendMessage sendMessageRequest; if (message.hasText()) { if (message.getText().equals(getCurrentCommand(language))) { sendMessageRequest = onCurrentChoosen(message, language); } else if (message.getText().equals(getForecastCommand(language))) { sendMessageRequest = onForecastChoosen(message, language); } else if (message.getText().equals(getSettingsCommand(language))) { sendMessageRequest = onSettingsChoosen(message, language); } else if (message.getText().equals(getRateCommand(language))) { sendMessageRequest = sendRateMessage(message.getChatId(), message.getMessageId(), null, language); } else { sendMessageRequest = sendChooseOptionMessage(message.getChatId(), message.getMessageId(), getMainMenuKeyboard(language), language); } } else { sendMessageRequest = sendChooseOptionMessage(message.getChatId(), message.getMessageId(), getMainMenuKeyboard(language), language); } return sendMessageRequest; }
Example #3
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #4
Source File: FilesHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private void onSetLanguageCommand(Message message, String language) throws InvalidObjectException, TelegramApiException { 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() + " " + Emoji.LEFT_RIGHT_ARROW.toString() + " " + 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)); execute(sendMessageRequest); languageMessages.add(message.getFrom().getId()); }
Example #5
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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: CommandsHandler.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
@Override public void processNonCommandUpdate(Update update) { if (update.hasMessage()) { Message message = update.getMessage(); if (!DatabaseManager.getInstance().getUserStateForCommandsBot(message.getFrom().getId())) { return; } if (message.hasText()) { SendMessage echoMessage = new SendMessage(); echoMessage.setChatId(message.getChatId()); echoMessage.setText("Hey heres your message:\n" + message.getText()); try { execute(echoMessage); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } } } }
Example #7
Source File: HelpCommand.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
@Override public void execute(AbsSender absSender, User user, Chat chat, String[] strings) { if (!DatabaseManager.getInstance().getUserStateForCommandsBot(user.getId())) { return; } StringBuilder helpMessageBuilder = new StringBuilder("<b>Help</b>\n"); helpMessageBuilder.append("These are the registered commands for this Bot:\n\n"); for (IBotCommand botCommand : commandRegistry.getRegisteredCommands()) { helpMessageBuilder.append(botCommand.toString()).append("\n\n"); } SendMessage helpMessage = new SendMessage(); helpMessage.setChatId(chat.getId().toString()); helpMessage.enableHtml(true); helpMessage.setText(helpMessageBuilder.toString()); try { absSender.execute(helpMessage); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } }
Example #8
Source File: StopCommand.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
@Override public void execute(AbsSender absSender, User user, Chat chat, String[] arguments) { DatabaseManager dbManager = DatabaseManager.getInstance(); if (dbManager.getUserStateForCommandsBot(user.getId())) { dbManager.setUserStateForCommandsBot(user.getId(), false); String userName = user.getFirstName() + " " + user.getLastName(); SendMessage answer = new SendMessage(); answer.setChatId(chat.getId().toString()); answer.setText("Good bye " + userName + "\n" + "Hope to see you soon!"); try { absSender.execute(answer); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } } }
Example #9
Source File: ExampleBot.java From telegram-spring-boot-starter-example with MIT License | 6 votes |
@Override public void onUpdateReceived(Update update) { if (update.hasMessage()) { Message message = update.getMessage(); SendMessage response = new SendMessage(); Long chatId = message.getChatId(); response.setChatId(chatId); String text = message.getText(); response.setText(text); try { execute(response); logger.info("Sent message \"{}\" to {}", text, chatId); } catch (TelegramApiException e) { logger.error("Failed to send message \"{}\" to {} due to error: {}", text, chatId, e.getMessage()); } } }
Example #10
Source File: StartCommand.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
@Override public void execute(AbsSender absSender, User user, Chat chat, String[] strings) { DatabaseManager databseManager = DatabaseManager.getInstance(); StringBuilder messageBuilder = new StringBuilder(); String userName = user.getFirstName() + " " + user.getLastName(); if (databseManager.getUserStateForCommandsBot(user.getId())) { messageBuilder.append("Hi ").append(userName).append("\n"); messageBuilder.append("i think we know each other already!"); } else { databseManager.setUserStateForCommandsBot(user.getId(), true); messageBuilder.append("Welcome ").append(userName).append("\n"); messageBuilder.append("this bot will demonstrate you the command feature of the Java TelegramBots API!"); } SendMessage answer = new SendMessage(); answer.setChatId(chat.getId().toString()); answer.setText(messageBuilder.toString()); try { absSender.execute(answer); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } }
Example #11
Source File: FilesHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #12
Source File: FilesHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private void onListCommand(Message message, String language) throws InvalidObjectException, TelegramApiException { HashMap<String, String> files = DatabaseManager.getInstance().getFilesByUser(message.getFrom().getId()); SendMessage sendMessageRequest = new SendMessage(); if (files.size() > 0) { String text = LocalisationService.getString("listOfFiles", language) + ":\n\n"; for (Map.Entry<String, String> entry : files.entrySet()) { text += LocalisationService.getString("uploadedFileURL", language) + entry.getKey() + " " + Emoji.LEFT_RIGHT_ARROW.toString() + " " + entry.getValue() + "\n"; } sendMessageRequest.setText(text); } else { sendMessageRequest.setText(LocalisationService.getString("noFiles", language)); } sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setReplyMarkup(new ReplyKeyboardRemove()); execute(sendMessageRequest); }
Example #13
Source File: ChannelHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private void sendHelpMessage(Long chatId, Integer messageId, ReplyKeyboardMarkup replyKeyboardMarkup) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); sendMessage.setChatId(chatId); sendMessage.setReplyToMessageId(messageId); if (replyKeyboardMarkup != null) { sendMessage.setReplyMarkup(replyKeyboardMarkup); } sendMessage.setText(HELP_TEXT); try { execute(sendMessage); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } }
Example #14
Source File: DirectionsHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #15
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private static SendMessage messageOnUnits(Message message, String language) { SendMessage sendMessageRequest = null; if (message.hasText()) { if (message.getText().trim().equals(getCancelCommand(language))) { sendMessageRequest = onBackUnitsCommand(message, language); } else if (message.getText().trim().equals(LocalisationService.getString("metricSystem", language))) { sendMessageRequest = onUnitsChosen(message.getFrom().getId(), message.getChatId(), message.getMessageId(), WeatherService.METRICSYSTEM, language); } else if (message.getText().trim().equals(LocalisationService.getString("imperialSystem", language))) { sendMessageRequest = onUnitsChosen(message.getFrom().getId(), message.getChatId(), message.getMessageId(), WeatherService.IMPERIALSYSTEM, language); } else { sendMessageRequest = onUnitsError(message.getChatId(), message.getMessageId(), language); } } return sendMessageRequest; }
Example #16
Source File: FilesHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #17
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #18
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private static SendMessage onAlertOptionSelected(Message message, String language) { SendMessage sendMessageRequest = null; if (message.hasText()) { if (message.getText().equals(getNewCommand(language))) { sendMessageRequest = onNewAlertCommand(message, language); } else if (message.getText().equals(getDeleteCommand(language))) { sendMessageRequest = onDeleteAlertCommand(message, language); } else if (message.getText().equals(getListCommand(language))) { sendMessageRequest = onListAlertCommand(message, language); } else if (message.getText().equals(getBackCommand(language))) { sendMessageRequest = onBackAlertCommand(message, language); } else { sendMessageRequest = sendChooseOptionMessage(message.getChatId(), message.getMessageId(), getAlertsKeyboard(language), language); } } return sendMessageRequest; }
Example #19
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #20
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #21
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #22
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private static SendMessage messageOnCurrentWeather(Message message, String language, int state) { SendMessage sendMessageRequest = null; switch(state) { case CURRENTWEATHER: sendMessageRequest = onCurrentWeather(message, language); break; case CURRENTNEWWEATHER: sendMessageRequest = onCurrentNewWeather(message, language); break; case CURRENTLOCATIONWEATHER: sendMessageRequest = onCurrentWeatherLocation(message, language); break; } return sendMessageRequest; }
Example #23
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private static SendMessage onCurrentWeather(Message message, String language) { SendMessage sendMessageRequest = null; if (message.hasText()) { if (message.getText().startsWith(getNewCommand(language))) { sendMessageRequest = onNewCurrentWeatherCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(), language); } else if (message.getText().startsWith(getLocationCommand(language))) { sendMessageRequest = onLocationCurrentWeatherCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(), language); } else if (message.getText().startsWith(getCancelCommand(language))) { sendMessageRequest = onCancelCommand(message.getChatId(), message.getFrom().getId(), message.getMessageId(), getMainMenuKeyboard(language), language); } else { sendMessageRequest = onCurrentWeatherCityReceived(message.getChatId(), message.getFrom().getId(), message.getMessageId(), message.getText(), language); } } return sendMessageRequest; }
Example #24
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #25
Source File: DirectionsHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
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 #26
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
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 #27
Source File: FilesHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
private void onUploadCommand(Message message, String language) throws InvalidObjectException, TelegramApiException { DatabaseManager.getInstance().addUserForFile(message.getFrom().getId(), INITIAL_UPLOAD_STATUS); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("sendFileToUpload", language)); sendMessageRequest.setChatId(message.getChatId()); execute(sendMessageRequest); }
Example #28
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
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 #29
Source File: FilesHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
private void onDeleteCommandWithParameters(Message message, String language, String part) throws InvalidObjectException, TelegramApiException { String[] innerParts = part.split(Emoji.LEFT_RIGHT_ARROW.toString(), 2); boolean removed = DatabaseManager.getInstance().deleteFile(innerParts[0].trim()); SendMessage sendMessageRequest = new SendMessage(); if (removed) { sendMessageRequest.setText(LocalisationService.getString("fileDeleted", language)); } else { sendMessageRequest.setText(LocalisationService.getString("wrongFileId", language)); } sendMessageRequest.setChatId(message.getChatId()); execute(sendMessageRequest); DatabaseManager.getInstance().deleteUserForFile(message.getFrom().getId()); }
Example #30
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
private static SendMessage onForecastNewWeather(Message message, String language) { if (message.isReply()) { return onForecastWeatherReceived(message.getChatId(), message.getFrom().getId(), message.getMessageId(), message.getText(), language); } else { return sendMessageDefault(message, language); } }