11package com .pengrad .telegrambot ;
22
3- import com .pengrad .telegrambot .model .ChatMember ;
4- import com .pengrad .telegrambot .model .InlineQuery ;
5- import com .pengrad .telegrambot .model .Message ;
6- import com .pengrad .telegrambot .model .Update ;
3+ import com .pengrad .telegrambot .model .*;
74import com .pengrad .telegrambot .model .request .InlineKeyboardButton ;
85import com .pengrad .telegrambot .model .request .InlineKeyboardMarkup ;
96import com .pengrad .telegrambot .model .request .InlineQueryResult ;
@@ -68,7 +65,7 @@ public void getMe() {
6865
6966 @ Test
7067 public void getUpdates () {
71- GetUpdatesResponse response = bot .execute (new GetUpdates ().offset (279823236 ).timeout (25 ));
68+ GetUpdatesResponse response = bot .execute (new GetUpdates ().offset (279823304 ).timeout (25 ));
7269 System .out .println (response );
7370 }
7471
@@ -96,10 +93,15 @@ public void answerInline() {
9693
9794 String inlineQueryId = lastInlineQuery .id ();
9895
99- InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup (new InlineKeyboardButton []{new InlineKeyboardButton ("inline ok" ).callbackData ("callback ok" ), new InlineKeyboardButton ("inline cancel" ).callbackData ("callback cancel" )});
96+ InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup (
97+ new InlineKeyboardButton []{
98+ new InlineKeyboardButton ("inline game" ).callbackGame ("pengrad_test_game" ),
99+ new InlineKeyboardButton ("inline ok" ).callbackData ("callback ok" )
100+
101+ });
102+
100103 InlineQueryResult r1 = new InlineQueryResultArticle ("1" , "title" , "message" ).replyMarkup (keyboardMarkup );
101- InlineQueryResult r2 = new InlineQueryResultArticle ("2" , "2 title" , "2 message" ).replyMarkup (keyboardMarkup );
102- bot .execute (new AnswerInlineQuery (inlineQueryId , r1 , r2 ));
104+ bot .execute (new AnswerInlineQuery (inlineQueryId , r1 ));
103105 }
104106
105107 private InlineQuery getLastInlineQuery () {
@@ -116,7 +118,26 @@ private InlineQuery getLastInlineQuery() {
116118
117119 @ Test
118120 public void answerCallback () {
119- bot .execute (new AnswerCallbackQuery ("220392309269028729" ).text ("answer callback" ));
121+ CallbackQuery callbackQuery = getLastCallbackQuery ();
122+ if (callbackQuery == null ) return ;
123+
124+ System .out .println (callbackQuery );
125+
126+ bot .execute (new AnswerCallbackQuery (callbackQuery .id ())
127+ .text ("answer callback" )
128+ .url ("https://telegram.me/pengrad_test_bot?start=callback" ));
129+ }
130+
131+ private CallbackQuery getLastCallbackQuery () {
132+ GetUpdatesResponse updatesResponse = bot .execute (new GetUpdates ());
133+ List <Update > updates = updatesResponse .updates ();
134+ Collections .reverse (updates );
135+ for (Update update : updates ) {
136+ if (update .callbackQuery () != null ) {
137+ return update .callbackQuery ();
138+ }
139+ }
140+ return null ;
120141 }
121142
122143 @ Test
0 commit comments