Trio<Update, Ability, String[]> getAbility(Update update) { // Handle updates without messages // Passing through this function means that the global flags have passed Message msg = update.getMessage(); if (!update.hasMessage() || !msg.hasText()) return Trio.of(update, abilities.get(DEFAULT), new String[]{}); String[] tokens = msg.getText().split(" "); if (tokens[0].startsWith("/")) { String abilityToken = stripBotUsername(tokens[0].substring(1)).toLowerCase(); Ability ability = abilities.get(abilityToken); tokens = Arrays.copyOfRange(tokens, 1, tokens.length); return Trio.of(update, ability, tokens); } else { Ability ability = abilities.get(DEFAULT); return Trio.of(update, ability, tokens); } }
@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); }
@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); }
@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); } }
@Override public BotApiMethod onWebhookUpdateReceived(Update update) { if (update.hasMessage() && update.getMessage().hasText()) { SendMessage sendMessage = new SendMessage(); sendMessage.setChatId(update.getMessage().getChatId().toString()); sendMessage.setText("Well, all information looks like noise until you break the code."); return sendMessage; } return null; }
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); } } }
@Override public void onUpdateReceived(Update update) { try { if (update.hasMessage()) { try { handleFileUpdate(update); } catch (TelegramApiRequestException e) { if (e.getApiResponse().contains("Bot was blocked by the user")) { if (update.getMessage().getFrom() != null) { DatabaseManager.getInstance().deleteUserForFile(update.getMessage().getFrom().getId()); } } } catch (Exception e) { BotLogger.severe(LOGTAG, e); } } } catch (Exception e) { BotLogger.error(LOGTAG, e); } }
if(update.hasMessage()){ Message message = update.getMessage();
@Override public void onUpdateReceived(Update update) { try { if (update.hasInlineQuery()) { handleIncomingInlineQuery(update.getInlineQuery()); } else if (update.hasMessage() && update.getMessage().isUserMessage()) { try { execute(getHelpMessage(update.getMessage())); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } } } catch (Exception e) { BotLogger.error(LOGTAG, e); } }
@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); } } } }