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


Java Update类代码示例

本文整理汇总了Java中org.telegram.telegrambots.api.objects.Update的典型用法代码示例。如果您正苦于以下问题:Java Update类的具体用法?Java Update怎么用?Java Update使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Update类属于org.telegram.telegrambots.api.objects包,在下文中一共展示了Update类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: TestEditMessageCaption

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
@Test
public void TestEditMessageCaption() {
    webhookBot.setReturnValue(BotApiMethodHelperFactory.getEditMessageCaption());

    Entity<Update> entity = Entity.json(getUpdate());
    BotApiMethod result =
            target("callback/testbot")
                    .request(MediaType.APPLICATION_JSON)
                    .post(entity, EditMessageCaption.class);

    assertEquals("{\"chat_id\":\"ChatId\",\"message_id\":1,\"caption\":\"Caption\"," +
            "\"reply_markup\":{\"@class\":\"org.telegram.telegrambots.api.objects.replykeyboard" +
            ".InlineKeyboardMarkup\",\"inline_keyboard\":[[{\"@class\":\"org.telegram." +
            "telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton\"," +
            "\"text\":\"Button1\",\"callback_data\":\"Callback\"}]]},\"method\":" +
            "\"editmessagecaption\"}", map(result));
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:18,代码来源:TestRestApi.java

示例2: onUpdateReceived

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
@Override
/*
 * 接收訊息時 運行此內容
 */
public void onUpdateReceived(Update update) {
  /*
   * 在命令欄顯示接收的消息 json格式
   */
  System.out.println(update.getMessage());
  try{
    /*
     * 設定發消息內容 封裝為一個新封包
     */
    SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
            .setChatId(update.getMessage().getChatId())
            .setReplyToMessageId(update.getMessage().getMessageId())
            .setText("Hellow World!");
    /*
     * 調用super class的sendMessage功能 把封包發出去
     */
    this.sendMessage(message);
  }catch(Exception ex){
    System.out.println("Error");
  }
}
 
开发者ID:slgphantom,项目名称:yearyearyear,代码行数:26,代码来源:TelegramBot.java

示例3: MessageHandle

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
public static void MessageHandle(TelegramBot tgb, Update msg){
	MessageHandle.msg = msg;
	MessageHandle.tgb = tgb;
	if(msg.hasMessage()){
		if(msg.getMessage().hasText()){
			switch(msg.getMessage().getText().toUpperCase()){
				case "IV":
					showIV();
					break;
				case "GAMEID":
					showGameId();
					break;
			}
		}
	}
}
 
开发者ID:slgphantom,项目名称:yearyearyear,代码行数:17,代码来源:MessageHandle.java

示例4: stringfyUpdate

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
private String stringfyUpdate(Update update){
	//data,id_usuario,username,tipo_busca,busca
	String s = "";
	
	s += update.getMessage().getDate()+",";
	s += update.getMessage().getFrom().getId()+",";
	s += update.getMessage().getFrom().getUserName()+",";
			
	if(update.getMessage().getText().contains("/conferencia")){
		s += "conference,";
		s += "\""+update.getMessage().getText().replace("/conferencia ", "")+"\""; 
	}
	else{
		s += "journal,";
		s += "\""+update.getMessage().getText().replace("/periodico ", "")+"\"";
	}
	
	s += "\n";
	
	return s;
}
 
开发者ID:InsightLab,项目名称:telegram-bots,代码行数:22,代码来源:FileLog.java

示例5: run

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
public void run(Update update, TelegramLongPollingBot bot) {

		SendMessage sm = new SendMessage();
		sm.setChatId(update.getMessage().getChatId());
		sm.setParseMode(ParseMode.HTML);
		
		String finalMessage = new String("<b>Verificador de Qualis - CAPES</b>\n");
		finalMessage = finalMessage.concat("\nUtilize os seguintes comandos para consulta\n");
		finalMessage = finalMessage.concat("\n<b>/conferencia</b> <i>sigla_conferencia</i> OU <i>nome_conferencia</i>");
		finalMessage = finalMessage.concat("\n<b>/periodico</b> <i>issn_periodico</i> OU <i>nome_periodico</i>");
		
		sm.setText(finalMessage);
		
		try {
			bot.sendMessage(sm);
		} catch (TelegramApiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
 
开发者ID:InsightLab,项目名称:telegram-bots,代码行数:22,代码来源:StartCommand.java

示例6: 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

示例7: 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

示例8: 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

示例9: answerQuestion

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
private void answerQuestion(Update update) {
	quizInterface.addPlayer(update.getCallbackQuery().getFrom().getId(),
			update.getCallbackQuery().getMessage().getChatId(), update.getCallbackQuery().getFrom().getUserName());
	int userId = update.getCallbackQuery().getFrom().getId();
	String query = update.getCallbackQuery().getData();
	String questionIdS = query.substring(0, query.indexOf('_'));
	String answerIdS = query.substring(query.indexOf('_') + 1);
	int questionId = Integer.parseInt(questionIdS);
	int answerId = Integer.parseInt(answerIdS);
	if (userAnswers == null) {
		userAnswers = new HashMap<>();
	}
	if (!userAnswers.containsKey(userId) || userAnswers.get(userId) != questionId) {
		quizInterface.enterAnswer(update.getCallbackQuery().getMessage().getChatId(),
				update.getCallbackQuery().getFrom().getId(), answerId);
		userAnswers.put(userId, questionId);
	}

}
 
开发者ID:argo2445,项目名称:QBot,代码行数:20,代码来源:QuizBot.java

示例10: startQuiz

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
private void startQuiz(Update update) {
	String msg = update.getMessage().getText();
	String rounds = "";
	try {
		rounds = msg.substring(msg.indexOf(' ') + 1);
		if (rounds.contains(" "))
			;
		rounds = rounds.substring(0, rounds.indexOf(' '));
	} catch (Exception e) {

	}
	int roundsInt = 10;
	try {
		roundsInt = Integer.parseInt(rounds);
	} catch (NumberFormatException ex) {

	}
	long chatId = update.getMessage().getChatId();
	quizInterface.createGame(chatId);
	quizInterface.addPlayer(update.getMessage().getFrom().getId(), chatId,
			update.getMessage().getFrom().getUserName());
	quizInterface.startGame(chatId, roundsInt);
	showNewQuestion(chatId);
}
 
开发者ID:argo2445,项目名称:QBot,代码行数:25,代码来源:QuizBot.java

示例11: updateReceived

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
@POST
@Path("/{botPath}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateReceived(@PathParam("botPath") String botPath, Update update) {
    if (callbacks.containsKey(botPath)) {
        try {
            BotApiMethod response = callbacks.get(botPath).onWebhookUpdateReceived(update);
            if (response != null) {
                response.validate();
            }
            return Response.ok(response).build();
        } catch (TelegramApiValidationException e) {
            BotLogger.severe("RESTAPI", e);
            return Response.serverError().build();
        }
    }

    return Response.status(Response.Status.NOT_FOUND).build();
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:21,代码来源:RestApi.java

示例12: TestEditMessageText

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
@Test
public void TestEditMessageText() {
    webhookBot.setReturnValue(BotApiMethodHelperFactory.getEditMessageText());

    Entity<Update> entity = Entity.json(getUpdate());
    BotApiMethod result =
            target("callback/testbot")
                    .request(MediaType.APPLICATION_JSON)
                    .post(entity, EditMessageText.class);

    assertEquals("{\"chat_id\":\"ChatId\",\"message_id\":1,\"text\":\"Text\"," +
            "\"parse_mode\":\"Markdown\",\"reply_markup\":{\"@class\":\"org.telegram." +
            "telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup\",\"" +
            "inline_keyboard\":[[{\"@class\":\"org.telegram.telegrambots.api.objects." +
            "replykeyboard.buttons.InlineKeyboardButton\",\"text\":\"Button1\",\"callback_data\"" +
            ":\"Callback\"}]]},\"method\":\"editmessagetext\"}", map(result));
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:18,代码来源:TestRestApi.java

示例13: TestSendInvoice

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
@Test
public void TestSendInvoice() {
    webhookBot.setReturnValue(BotApiMethodHelperFactory.getSendInvoice());

    Entity<Update> entity = Entity.json(getUpdate());
    BotApiMethod result =
            target("callback/testbot")
                    .request(MediaType.APPLICATION_JSON)
                    .post(entity, SendInvoice.class);

    assertEquals("{\"chat_id\":12345,\"title\":\"Random title\",\"description\":\"Random description\"" +
            ",\"payload\":\"Random Payload\",\"provider_token\":\"Random provider token\",\"start_parameter\":" +
            "\"STARTPARAM\",\"currency\":\"EUR\",\"prices\":[{\"@class\":" +
            "\"org.telegram.telegrambots.api.objects.payments.LabeledPrice\",\"label\":\"LABEL\"," +
            "\"amount\":1000}],\"method\":\"sendinvoice\"}", map(result));
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:17,代码来源:TestRestApi.java

示例14: 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

示例15: onUpdateReceived

import org.telegram.telegrambots.api.objects.Update; //导入依赖的package包/类
@Override
public void onUpdateReceived(Update arg0) {
	
	SendMessage msg=null;
	if(arg0.getMessage().isCommand())
		
		msg = createMessage(JlasniCommand(arg0.getMessage().getText()), arg0.getMessage().getChatId());
	else
		msg= createMessage("Error, no es un comando", arg0.getMessage().getChatId());
		
	try {
		execute(msg);
	}catch (TelegramApiException e) {
		// TODO: handle exception
		e.printStackTrace();
	}
	
	
}
 
开发者ID:zerasul,项目名称:lasnibot,代码行数:20,代码来源:JlasniBot.java


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