Java Code Examples for org.telegram.telegrambots.meta.api.objects.User#getLastName()
The following examples show how to use
org.telegram.telegrambots.meta.api.objects.User#getLastName() .
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: 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 2
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 3
Source File: HelloCommand.java From TelegramBotsExample with GNU General Public License v3.0 | 5 votes |
@Override public void execute(AbsSender absSender, User user, Chat chat, String[] arguments) { if (!DatabaseManager.getInstance().getUserStateForCommandsBot(user.getId())) { return; } String userName = chat.getUserName(); if (userName == null || userName.isEmpty()) { userName = user.getFirstName() + " " + user.getLastName(); } StringBuilder messageTextBuilder = new StringBuilder("Hello ").append(userName); if (arguments != null && arguments.length > 0) { messageTextBuilder.append("\n"); messageTextBuilder.append("Thank you so much for your kind words:\n"); messageTextBuilder.append(String.join(" ", arguments)); } SendMessage answer = new SendMessage(); answer.setChatId(chat.getId().toString()); answer.setText(messageTextBuilder.toString()); try { absSender.execute(answer); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } }
Example 4
Source File: AbilityUtils.java From TelegramBots with MIT License | 3 votes |
/** * The short name is one of the following: * <ol> * <li>First name</li> * <li>Last name</li> * <li>Username</li> * </ol> * The method will try to return the first valid name in the specified order. * * @return the short name of the user */ public static String shortName(User user) { if (!isEmpty(user.getFirstName())) return user.getFirstName(); if (!isEmpty(user.getLastName())) return user.getLastName(); return user.getUserName(); }