private void onDestinationReceived(Message message, String language) { String origin = DatabaseManager.getInstance().getUserOrigin(message.getFrom().getId()); String destiny = message.getText(); List<String> directions = DirectionsService.getInstance().getDirections(origin, destiny, language); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setChatId(message.getChatId().toString()); ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide(); replyKeyboardHide.setSelective(true); sendMessageRequest.setReplayMarkup(replyKeyboardHide); sendMessageRequest.setReplayToMessageId(message.getMessageId()); Message sentMessage = null; for (String direction : directions) { sendMessageRequest.setText(direction); SenderHelper.SendApiMethodAsync( sendMessageRequest, TOKEN, new SentCallback<Message>() { @Override public void onResult(BotApiMethod<Message> method, JSONObject jsonObject) { Message sentMessage = method.deserializeResponse(jsonObject); if (sentMessage != null) { DatabaseManager.getInstance().deleteUserForDirections(message.getFrom().getId()); } } @Override public void onError(BotApiMethod<Message> method, JSONObject jsonObject) {} }); } }
private void onLanguageSelected(Message message) throws InvalidObjectException { String[] parts = message.getText().split("-->", 2); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setChatId(message.getChatId().toString()); if (LocalisationService.getInstance().getSupportedLanguages().containsKey(parts[0].trim())) { DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim()); sendMessageRequest.setText( LocalisationService.getInstance().getString("languageModified", parts[0].trim())); } else { sendMessageRequest.setText(LocalisationService.getInstance().getString("errorLanguage")); } sendMessageRequest.setReplayToMessageId(message.getMessageId()); ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide(); replyKeyboardHide.setHideKeyboard(true); replyKeyboardHide.setSelective(true); sendMessageRequest.setReplayMarkup(replyKeyboardHide); SenderHelper.SendApiMethod(sendMessageRequest, TOKEN); languageMessages.remove(message.getFrom().getId()); }