本文整理汇总了Java中org.telegram.telegrambots.api.objects.Update.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Update.getMessage方法的具体用法?Java Update.getMessage怎么用?Java Update.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.telegram.telegrambots.api.objects.Update
的用法示例。
在下文中一共展示了Update.getMessage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasPhoto()) {
Message message = update.getMessage();
long chatId = message.getChatId();
// get the last photo - it seems to be the bigger one
List<PhotoSize> photos = message.getPhoto();
PhotoSize photo = photos.get(photos.size() - 1);
String id = photo.getFileId();
try {
GetFile getFile = new GetFile();
getFile.setFileId(id);
String filePath = getFile(getFile).getFileUrl(getBotToken());
// TODO: cache images?
logger.info("== DOWNLOADING IMAGE " + filePath);
URL url = new URL(filePath);
String caption = Classifier.classify(url.openStream());
logger.info("Caption for image " + filePath + ":\n" + caption);
sendPhotoMessage(chatId, id, caption);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
System.out.println(message);
List<User> newUsers = update.getMessage().getNewChatMembers();
if (newUsers != null) {
String welcomeMessage = "Bienvenido al grupo Java Studio: ";
for (User newUser : newUsers) {
String user = newUser.getUserName().equals("null") ? newUser.getFirstName()
: "@" + newUser.getUserName();
welcomeMessage += user + " ";
}
SendMessage welcomeSendMessage = new SendMessage()
.setChatId(message.getChatId())
.setText(welcomeMessage);
try {
sendMessage(welcomeSendMessage);
} catch (TelegramApiException ex) {
Logger.getLogger(CoffeeAndyBot.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
示例3: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public synchronized void onUpdateReceived(final Update update) {
if (update.hasMessage()) {
final Message message = update.getMessage();
Thread processThread = new Thread(() -> {
TgContextHolder.setupContext(message);
TgContext tgContext = TgContextHolder.currentContext();
synchronized (tgContext) {
try {
messageHandler.handleMessage(message, tgContext);
}catch (TgBotMessageHandleException e) {
send(tgContext.getChatId(), e.getMessage());
}
}
});
processThread.setName("TgRequest");
processThread.setDaemon(true);
processThread.start();
}
}
示例4: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的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());
}
}
}
示例5: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public void onUpdateReceived(Update update) {
if(update.hasMessage()) {
Message message = update.getMessage();
String[] command = message.getText().split(" ");
if(command[0].startsWith("/") && commandHash.containsKey(command[0])) {
commandHash.get(command[0]).run(update, this);
logger.write(update);
}
else {
SendMessage sm = new SendMessage();
sm.setChatId(update.getMessage().getChatId());
sm.setParseMode(ParseMode.HTML);
sm.setText("Comando Inválido. Digite <b>/ajuda</b> para a lista de comandos.");
try {
sendMessage(sm);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
示例6: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public final void onUpdateReceived(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.isCommand() && !filter(message)) {
if (commandRegistry.executeCommand(this, message)) {
return;
}
}
}
processNonCommandUpdate(update);
}
示例7: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.getMessage() == null) {
return;
}
executorService.submit(new EchoDownload(update));
}