Java Code Examples for org.telegram.telegrambots.meta.api.objects.Update#getMessage()
The following examples show how to use
org.telegram.telegrambots.meta.api.objects.Update#getMessage() .
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: 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 2
Source File: TelegramLongPollingSessionBot.java From TelegramBots with MIT License | 6 votes |
@Override public void onUpdateReceived(Update update) { Optional<Session> chatSession; Message message; if (update.hasMessage()) { message = update.getMessage(); } else if (update.hasCallbackQuery()) { message = update.getCallbackQuery().getMessage(); } else { chatSession = Optional.empty(); onUpdateReceived(update, chatSession); return; } chatIdConverter.setSessionId(message.getChatId()); chatSession = this.getSession(message); onUpdateReceived(update, chatSession); }
Example 3
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 4
Source File: TelegramBot.java From telegram-notifications-plugin with MIT License | 5 votes |
@Override public void processNonCommandUpdate(Update update) { if (update == null) { LOG.log(Level.WARNING, "Update is null"); return; } final String nonCommandMessage = CONFIG.getBotStrings() .get("message.noncommand"); final Message message = update.getMessage(); final Chat chat = message.getChat(); if (chat.isUserChat()) { sendMessage(chat.getId(), nonCommandMessage); return; } final String text = message.getText(); try { // Skip not direct messages in chats if (text.length() < 1 || text.charAt(0) != '@') return; final String[] tmp = text.split(" "); if (tmp.length < 2 || !CONFIG.getBotName().equals(tmp[0].substring(1, tmp[0].length()))) return; } catch (Exception e) { LOG.log(Level.SEVERE, "Something bad happened while message processing", e); return; } sendMessage(chat.getId(), nonCommandMessage); }
Example 5
Source File: TelegramLongPollingCommandBot.java From TelegramBots with MIT License | 5 votes |
@Override public final void onUpdateReceived(Update update) { if (update.hasMessage()) { Message message = update.getMessage(); if (message.isCommand() && !filter(message)) { if (!commandRegistry.executeCommand(this, message)) { //we have received a not registered command, handle it as invalid processInvalidCommandUpdate(update); } return; } } processNonCommandUpdate(update); }
Example 6
Source File: WeatherHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
@Override public void onUpdateReceived(Update update) { try { if (update.hasMessage()) { Message message = update.getMessage(); if (message.hasText() || message.hasLocation()) { handleIncomingMessage(message); } } } catch (Exception e) { BotLogger.error(LOGTAG, e); } }
Example 7
Source File: TransifexHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
private void handleUpdate(Update update) throws InvalidObjectException, TelegramApiException { if (update.hasMessage() && update.getMessage().hasText()) { Message message = update.getMessage(); if (BuildVars.ADMINS.contains(message.getFrom().getId())) { sendTransifexFile(message); } else { sendMovedToMessage(message); } } }
Example 8
Source File: DirectionsHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 4 votes |
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); } } } } } } }