com.pengrad.telegrambot.model.Update Java Examples

The following examples show how to use com.pengrad.telegrambot.model.Update. 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: UpdateTest.java    From java-telegram-bot-api with Apache License 2.0 6 votes vote down vote up
public static void check(List<Update> updates) {
    for (Update update : updates) {
        assertTrue(update.updateId() > 0);
        if (update.message() != null) MessageTest.checkMessage(update.message());
        if (update.editedMessage() != null) MessageTest.checkMessage(update.editedMessage());
        if (update.inlineQuery() != null) InlineQueryTest.checkQuery(update.inlineQuery());
        if (update.chosenInlineResult() != null) ChosenInlineResultTest.check(update.chosenInlineResult());
        if (update.channelPost() != null) MessageTest.checkMessage(update.channelPost());
        if (update.editedChannelPost() != null) MessageTest.checkMessage(update.editedChannelPost());
        if (update.callbackQuery() != null) assertNotNull(update.callbackQuery().id());
        if (update.shippingQuery() != null) assertNotNull(update.shippingQuery().id());
        if (update.preCheckoutQuery() != null) assertNotNull(update.preCheckoutQuery().id());
        if (update.poll() != null) assertNotNull(update.poll().id());
        if (update.pollAnswer() != null) assertNotNull((update.pollAnswer().pollId()));
    }
}
 
Example #2
Source File: BotController.java    From telegram-bot with Eclipse Public License 1.0 5 votes vote down vote up
@RequestMapping("/poll")
public void poll() {

	GetUpdates getUpdates = new GetUpdates().limit(100).offset(0).timeout(0);
	GetUpdatesResponse getUpdatesResponse = bot.execute(getUpdates);

	List<Update> updates = getUpdatesResponse.updates();
	updates.forEach(this::webhook);
}
 
Example #3
Source File: TelegramBotManager.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
private void addUpdatesListener(TelegramBot bot) {
  bot.setUpdatesListener(updates -> {
    for (Update update: updates) {
      Message message = update.message();
      Long chatId = message.chat().id();
      SendMessage msg = new SendMessage(chatId,
          "Hello! Your chat id is '" + chatId + "'.\n" +
              "If you want to receive notifications about Teamcity events " +
              "please add this chat id in your Teamcity settings");
      bot.execute(msg);
    }
    return UpdatesListener.CONFIRMED_UPDATES_ALL;
  });
}
 
Example #4
Source File: BotHandler.java    From java-telegram-bot-api with Apache License 2.0 5 votes vote down vote up
@Override
public Object handle(Request request, Response response) throws Exception {
    Update update = BotUtils.parseUpdate(request.body());
    Message message = update.message();

    if (isStartMessage(message) && onStart(message)) {
        return "ok";
    } else {
        onWebhookUpdate(update);
    }
    return "ok";
}
 
Example #5
Source File: ModelTest.java    From java-telegram-bot-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testEquals() throws IllegalAccessException, InstantiationException, NoSuchFieldException {
    Object callbackQuery = CallbackQuery.class.newInstance();
    Field f = CallbackQuery.class.getDeclaredField("id");
    f.setAccessible(true);
    f.set(callbackQuery, "2");

    Object message = Message.class.newInstance();
    f = Message.class.getDeclaredField("message_id");
    f.setAccessible(true);
    f.set(message, 11);

    Object update = Update.class.newInstance();
    f = Update.class.getDeclaredField("update_id");
    f.setAccessible(true);
    f.set(update, 1);

    for (Class c : classes) {
        EqualsVerifier.forClass(c)
                .usingGetClass()
                .withPrefabValues(Update.class, Update.class.newInstance(), update)
                .withPrefabValues(Message.class, Message.class.newInstance(), message)
                .withPrefabValues(CallbackQuery.class, CallbackQuery.class.newInstance(), callbackQuery)
                .suppress(Warning.STRICT_HASHCODE)
                .suppress(Warning.NONFINAL_FIELDS)
                .verify();
    }
}
 
Example #6
Source File: BotController.java    From telegram-bot with Eclipse Public License 1.0 4 votes vote down vote up
@RequestMapping(value = "/webhook", method = RequestMethod.POST)
public void webhook(@RequestBody Update update) {
	handler.handleUpdate(update);
}
 
Example #7
Source File: AqivnBot.java    From java-telegram-bot-api with Apache License 2.0 4 votes vote down vote up
@Override
void onWebhookUpdate(Update update) {
    bot.execute(new SendMessage(update.message().chat().id(), getAqi()).replyMarkup(simpleKeyboard()));
}
 
Example #8
Source File: GetUpdatesResponse.java    From java-telegram-bot-api with Apache License 2.0 4 votes vote down vote up
public List<Update> updates() {
    return result;
}
 
Example #9
Source File: BotUtils.java    From java-telegram-bot-api with Apache License 2.0 4 votes vote down vote up
public static Update parseUpdate(String update) {
    return gson.fromJson(update, Update.class);
}
 
Example #10
Source File: BotUtils.java    From java-telegram-bot-api with Apache License 2.0 4 votes vote down vote up
public static Update parseUpdate(Reader reader) {
    return gson.fromJson(reader, Update.class);
}
 
Example #11
Source File: UpdatesHandler.java    From java-telegram-bot-api with Apache License 2.0 4 votes vote down vote up
private int lastUpdateId(List<Update> updates) {
    return updates.get(updates.size() - 1).updateId();
}
 
Example #12
Source File: UpdateHandler.java    From telegram-bot with Eclipse Public License 1.0 votes vote down vote up
void handleUpdate(Update update); 
Example #13
Source File: BotHandler.java    From java-telegram-bot-api with Apache License 2.0 votes vote down vote up
abstract void onWebhookUpdate(Update update); 
Example #14
Source File: UpdatesListener.java    From java-telegram-bot-api with Apache License 2.0 votes vote down vote up
int process(List<Update> updates);