当前位置: 首页>>代码示例>>Java>>正文


Java Update.getMessage方法代码示例

本文整理汇总了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();
		}
	}
}
 
开发者ID:jesuino,项目名称:java-ml-projects,代码行数:24,代码来源:ClassifierBot.java

示例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);
            }
        }

    }
}
 
开发者ID:Java-Studio-Telegram-Group,项目名称:Coffee_AndyBot,代码行数:27,代码来源:CoffeeAndyBot.java

示例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();
	}
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:23,代码来源:TgBot.java

示例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());
        }
    }
}
 
开发者ID:junbaor,项目名称:telegram-bot,代码行数:19,代码来源:GetIdHandler.java

示例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();
			}
		}
		
	}
	
}
 
开发者ID:InsightLab,项目名称:telegram-bots,代码行数:29,代码来源:QualisBot.java

示例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);
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:13,代码来源:TelegramLongPollingCommandBot.java

示例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));
}
 
开发者ID:junbaor,项目名称:telegram-bot,代码行数:8,代码来源:EchoHandler.java


注:本文中的org.telegram.telegrambots.api.objects.Update.getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。