Skip to content

Commit 9ae5a8e

Browse files
committed
Test get updates in endless loop
1 parent 09cc127 commit 9ae5a8e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.model.Chat;
4+
import com.pengrad.telegrambot.model.Message;
5+
import com.pengrad.telegrambot.model.Update;
6+
import com.pengrad.telegrambot.model.User;
7+
import com.pengrad.telegrambot.response.GetUpdatesResponse;
8+
9+
import java.io.FileInputStream;
10+
import java.io.IOException;
11+
import java.util.List;
12+
import java.util.Properties;
13+
14+
/**
15+
* stas
16+
* 3/31/16.
17+
*/
18+
public class TestLoopGetUpdates {
19+
20+
public static void main(String[] args) throws IOException {
21+
Properties properties = new Properties();
22+
properties.load(new FileInputStream("local.properties"));
23+
TelegramBot bot = TelegramBotAdapter.build(properties.getProperty("TEST_TOKEN"));
24+
25+
GetUpdatesResponse updatesResponse;
26+
int j = 0;
27+
while (true) {
28+
try {
29+
updatesResponse = bot.getUpdates(j, 100, 20);
30+
List<Update> updates = updatesResponse.updates();
31+
for (int z = 0; z < updates.size(); z++) {
32+
j = updates.get(z).updateId() + 1;
33+
Message message = updates.get(z).message();
34+
//
35+
Chat chat = message.chat();
36+
User user = message.from();
37+
//String mes=message.text();
38+
39+
// Base64.getEncoder().encodeToString(s.getBytes(StandardCharsets.UTF_8));
40+
if (message.text() != null) {
41+
System.out.println("New message: " + message.text() + " id: " + message.messageId() + " from " + chat);
42+
}
43+
44+
}
45+
} catch (Exception e) {
46+
e.printStackTrace();
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)