本文整理汇总了Java中org.telegram.telegrambots.api.objects.Chat类的典型用法代码示例。如果您正苦于以下问题:Java Chat类的具体用法?Java Chat怎么用?Java Chat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chat类属于org.telegram.telegrambots.api.objects包,在下文中一共展示了Chat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupContext
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
public static void setupContext(Message message) {
User user = message.getFrom();
Chat chat = message.getChat();
Long chatId = chat.getId();
if (!tgUserContexts.containsKey(chatId)) {
TgContext value = new TgContext();
value.setUser(user);
value.setChat(chat);
tgUserContexts.put(chatId, value);
}
TgContext tgContext = tgUserContexts.get(chatId);
tgContextThreadLocal.set(tgContext);
}
示例2: onUpdateReceived
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.getMessage() != null) {
Long chatId = update.getMessage().getChatId();
String text = update.getMessage().getText();
if ("/start".equals(text)) {
send(chatId, "Hello, You can get an id for sending or forwarding messages");
}
send(chatId, "Your telegram id: " + chatId);
Chat forwardFromChat = update.getMessage().getForwardFromChat();
if (forwardFromChat != null) {
send(chatId, "Message source id: " + update.getMessage().getForwardFromChat().getId());
}
}
}
示例3: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@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.sendMessage(answer);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
示例4: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@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.sendMessage(answer);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
}
示例5: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@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 (BotCommand 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.sendMessage(helpMessage);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
示例6: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
StringBuilder helpMessageBuilder = new StringBuilder("<b>Help</b>\n");
helpMessageBuilder.append("These are the registered commands for this Bot:\n\n");
for (BotCommand 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.sendMessage(helpMessage);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
示例7: deserializeResponse
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public Chat deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Chat> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Chat>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error getting chat", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
示例8: assertPrivateChat
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
private void assertPrivateChat(Chat chat) {
Assert.assertNotNull(chat);
Assert.assertEquals(Long.valueOf(1111111), chat.getId());
Assert.assertTrue(chat.isUserChat());
Assert.assertEquals("Test Lastname", chat.getLastName());
Assert.assertEquals("Test Firstname", chat.getFirstName());
Assert.assertEquals("Testusername", chat.getUserName());
}
示例9: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@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.sendMessage(answer);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
示例10: getChat
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
public Chat getChat() {
return chat;
}
示例11: setChat
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
public void setChat(Chat chat) {
this.chat = chat;
this.chatId = chat.getId();
}
示例12: assertChannelChat
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
private void assertChannelChat(Chat chat) {
Assert.assertNotNull(chat);
Assert.assertEquals(Long.valueOf(-10000000000L), chat.getId());
Assert.assertTrue(chat.isChannelChat());
Assert.assertEquals("Test channel", chat.getTitle());
}
示例13: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public final void execute(AbsSender absSender, User user, Chat chat, String[] arguments) {
}
示例14: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
/**
* Execute the command
*
* @param absSender absSender to send messages over
* @param user the user who sent the command
* @param chat the chat, to be able to send replies
* @param arguments passed arguments
*/
public abstract void execute(AbsSender absSender, User user, Chat chat, String[] arguments);
示例15: execute
import org.telegram.telegrambots.api.objects.Chat; //导入依赖的package包/类
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] arguments) {
String userId = user.getId().toString();
SendMessage answer = new SendMessage();
answer.setChatId(chat.getId().toString());
LogManager.getLogger(this.getClass()).info("Request from user: " + String.valueOf(user.getId()));
if (arguments != null && arguments.length == 1) {
if (authSecret.equals(arguments[0])) {
answer.setText("user authenticated: " + user.getId());
List result = em.createQuery("select u from TelegramUser u where u.userId=:userId")
.setParameter("userId", userId).getResultList();
if (result == null || result.isEmpty()) {
em.getTransaction().begin();
TelegramUser telegramUser = new TelegramUser();
telegramUser.setUserId(userId);
telegramUser.setAuthenticated(true);
em.persist(telegramUser);
em.getTransaction().commit();
}
} else {
answer.setText("wrong credentials");
}
} else {
answer.setText("not authenticated");
}
try {
absSender.sendMessage(answer);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}