Skip to content

Commit 6e5103d

Browse files
committed
InlineQuery support
1 parent 4fd3a11 commit 6e5103d

File tree

15 files changed

+501
-7
lines changed

15 files changed

+501
-7
lines changed

src/main/java/com/pengrad/telegrambot/TelegramBot.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.pengrad.telegrambot;
22

3+
import com.google.gson.Gson;
34
import com.pengrad.telegrambot.impl.BotApi;
45
import com.pengrad.telegrambot.impl.FileApi;
56
import com.pengrad.telegrambot.model.File;
@@ -14,10 +15,12 @@ public class TelegramBot {
1415

1516
private final BotApi botApi;
1617
private final FileApi fileApi;
18+
private final Gson gson;
1719

1820
public TelegramBot(BotApi botApi, FileApi fileApi) {
1921
this.botApi = botApi;
2022
this.fileApi = fileApi;
23+
gson = new Gson();
2124
}
2225

2326
public String getFullFilePath(String fileId) {
@@ -151,4 +154,12 @@ public SetWebhookResponse setWebhook(String url, InputFileBytes certificate) {
151154
public GetFileResponse getFile(String fileId) {
152155
return botApi.getFile(fileId);
153156
}
157+
158+
public OkResponse answerInlineQuery(String inlineQueryId, InlineQueryResult... results) {
159+
return answerInlineQuery(inlineQueryId, results, null, null, null);
160+
}
161+
162+
public OkResponse answerInlineQuery(String inlineQueryId, InlineQueryResult[] results, Integer cacheTime, Boolean isPersonal, String nextOffset) {
163+
return botApi.answerInlineQuery(inlineQueryId, gson.toJson(results), cacheTime, isPersonal, nextOffset);
164+
}
154165
}

src/main/java/com/pengrad/telegrambot/impl/BotApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,13 @@ GetUpdatesResponse getUpdates(
250250

251251
@GET("/getFile")
252252
GetFileResponse getFile(@Query("file_id") String fileId);
253+
254+
@FormUrlEncoded
255+
@POST("/answerInlineQuery")
256+
OkResponse answerInlineQuery(
257+
@Field("inline_query_id") String inlineQueryId,
258+
@Field("results") String results,
259+
@Field("cache_time") Integer cacheTime,
260+
@Field("is_personal") Boolean isPersonal,
261+
@Field("next_offset") String nextOffset);
253262
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
/**
4+
* stas
5+
* 1/12/16.
6+
*/
7+
public class InlineQuery {
8+
9+
private String id;
10+
private User from;
11+
private String query;
12+
private String offset;
13+
14+
InlineQuery() {
15+
}
16+
17+
public String id() {
18+
return id;
19+
}
20+
21+
public User from() {
22+
return from;
23+
}
24+
25+
public String query() {
26+
return query;
27+
}
28+
29+
public String offset() {
30+
return offset;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (this == o) return true;
36+
if (o == null || getClass() != o.getClass()) return false;
37+
38+
InlineQuery that = (InlineQuery) o;
39+
40+
if (id != null ? !id.equals(that.id) : that.id != null) return false;
41+
if (from != null ? !from.equals(that.from) : that.from != null) return false;
42+
if (query != null ? !query.equals(that.query) : that.query != null) return false;
43+
return offset != null ? offset.equals(that.offset) : that.offset == null;
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
return id.hashCode();
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return "InlineQuery{" +
54+
"id='" + id + '\'' +
55+
", from=" + from +
56+
", query='" + query + '\'' +
57+
", offset='" + offset + '\'' +
58+
'}';
59+
}
60+
}

src/main/java/com/pengrad/telegrambot/model/Update.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class Update {
88

99
private Integer update_id;
1010
private Message message;
11+
private InlineQuery inline_query;
1112

1213
Update() {
1314
}
@@ -20,6 +21,10 @@ public Message message() {
2021
return message;
2122
}
2223

24+
public InlineQuery inlineQuery() {
25+
return inline_query;
26+
}
27+
2328
@Override
2429
public boolean equals(Object o) {
2530
if (this == o) return true;
@@ -28,7 +33,8 @@ public boolean equals(Object o) {
2833
Update update = (Update) o;
2934

3035
if (update_id != null ? !update_id.equals(update.update_id) : update.update_id != null) return false;
31-
return message != null ? message.equals(update.message) : update.message == null;
36+
if (message != null ? !message.equals(update.message) : update.message != null) return false;
37+
return inline_query != null ? inline_query.equals(update.inline_query) : update.inline_query == null;
3238
}
3339

3440
@Override
@@ -41,6 +47,7 @@ public String toString() {
4147
return "Update{" +
4248
"update_id=" + update_id +
4349
", message=" + message +
50+
", inline_query=" + inline_query +
4451
'}';
4552
}
4653
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.pengrad.telegrambot.model.request;
2+
3+
/**
4+
* stas
5+
* 1/12/16.
6+
*/
7+
public abstract class InlineQueryResult {
8+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.pengrad.telegrambot.model.request;
2+
3+
/**
4+
* stas
5+
* 1/12/16.
6+
*/
7+
public class InlineQueryResultArticle extends InlineQueryResult {
8+
9+
private String type;
10+
private String id;
11+
private String title;
12+
private String message_text;
13+
14+
private ParseMode parse_mode;
15+
private Boolean disable_web_page_preview;
16+
private String url;
17+
private Boolean hide_url;
18+
private String description;
19+
private String thumb_url;
20+
private Integer thumb_width;
21+
private Integer thumb_height;
22+
23+
public InlineQueryResultArticle(String id, String title, String messageText) {
24+
this.type = "article";
25+
this.id = id;
26+
this.title = title;
27+
this.message_text = messageText;
28+
}
29+
30+
public InlineQueryResultArticle parseMode(ParseMode parseMode) {
31+
this.parse_mode = parseMode;
32+
return this;
33+
}
34+
35+
public InlineQueryResultArticle disableWebPagePreview(Boolean disableWebPagePreview) {
36+
this.disable_web_page_preview = disableWebPagePreview;
37+
return this;
38+
}
39+
40+
public InlineQueryResultArticle url(String url) {
41+
this.url = url;
42+
return this;
43+
}
44+
45+
public InlineQueryResultArticle hideUrl(Boolean hideUrl) {
46+
this.hide_url = hideUrl;
47+
return this;
48+
}
49+
50+
public InlineQueryResultArticle description(String description) {
51+
this.description = description;
52+
return this;
53+
}
54+
55+
public InlineQueryResultArticle thumbUrl(String thumbUrl) {
56+
this.thumb_url = thumbUrl;
57+
return this;
58+
}
59+
60+
public InlineQueryResultArticle thumbWidth(Integer thumbWidth) {
61+
this.thumb_width = thumbWidth;
62+
return this;
63+
}
64+
65+
public InlineQueryResultArticle thumbHeight(Integer thumbHeight) {
66+
this.thumb_height = thumbHeight;
67+
return this;
68+
}
69+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.pengrad.telegrambot.model.request;
2+
3+
/**
4+
* stas
5+
* 1/12/16.
6+
*/
7+
public class InlineQueryResultGif extends InlineQueryResult {
8+
9+
private String type;
10+
private String id;
11+
private String gif_url;
12+
private String thumb_url;
13+
14+
private Integer gif_width;
15+
private Integer gif_height;
16+
private String title;
17+
private String caption;
18+
private String message_text;
19+
private ParseMode parse_mode;
20+
private Boolean disable_web_page_preview;
21+
22+
public InlineQueryResultGif(String id, String gifUrl, String thumbUrl) {
23+
this.type = "gif";
24+
this.id = id;
25+
this.gif_url = gifUrl;
26+
this.thumb_url = thumbUrl;
27+
}
28+
29+
public InlineQueryResultGif gifWidth(Integer gifWidth) {
30+
this.gif_width = gifWidth;
31+
return this;
32+
}
33+
34+
public InlineQueryResultGif gifHeight(Integer gifHeight) {
35+
this.gif_height = gifHeight;
36+
return this;
37+
}
38+
39+
public InlineQueryResultGif title(String title) {
40+
this.title = title;
41+
return this;
42+
}
43+
44+
public InlineQueryResultGif caption(String caption) {
45+
this.caption = caption;
46+
return this;
47+
}
48+
49+
public InlineQueryResultGif messageText(String messageText) {
50+
this.message_text = messageText;
51+
return this;
52+
}
53+
54+
public InlineQueryResultGif parseMode(ParseMode parseMode) {
55+
this.parse_mode = parseMode;
56+
return this;
57+
}
58+
59+
public InlineQueryResultGif disableWebPagePreview(Boolean disableWebPagePreview) {
60+
this.disable_web_page_preview = disableWebPagePreview;
61+
return this;
62+
}
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.pengrad.telegrambot.model.request;
2+
3+
/**
4+
* stas
5+
* 1/12/16.
6+
*/
7+
public class InlineQueryResultMpeg4Gif extends InlineQueryResult {
8+
9+
private String type;
10+
private String id;
11+
private String mpeg4_url;
12+
private String thumb_url;
13+
14+
private Integer mpeg4_width;
15+
private Integer mpeg4_height;
16+
private String title;
17+
private String caption;
18+
private String message_text;
19+
private ParseMode parse_mode;
20+
private Boolean disable_web_page_preview;
21+
22+
public InlineQueryResultMpeg4Gif(String id, String mpeg4Url, String thumbUrl) {
23+
this.type = "mpeg4_gif";
24+
this.id = id;
25+
this.mpeg4_url = mpeg4Url;
26+
this.thumb_url = thumbUrl;
27+
}
28+
29+
public InlineQueryResultMpeg4Gif mpeg4Width(Integer mpeg4Width) {
30+
this.mpeg4_width = mpeg4Width;
31+
return this;
32+
}
33+
34+
public InlineQueryResultMpeg4Gif mpeg4Height(Integer mpeg4Height) {
35+
this.mpeg4_height = mpeg4Height;
36+
return this;
37+
}
38+
39+
public InlineQueryResultMpeg4Gif title(String title) {
40+
this.title = title;
41+
return this;
42+
}
43+
44+
public InlineQueryResultMpeg4Gif caption(String caption) {
45+
this.caption = caption;
46+
return this;
47+
}
48+
49+
public InlineQueryResultMpeg4Gif messageText(String messageText) {
50+
this.message_text = messageText;
51+
return this;
52+
}
53+
54+
public InlineQueryResultMpeg4Gif parseMode(ParseMode parseMode) {
55+
this.parse_mode = parseMode;
56+
return this;
57+
}
58+
59+
public InlineQueryResultMpeg4Gif disableWebPagePreview(Boolean disableWebPagePreview) {
60+
this.disable_web_page_preview = disableWebPagePreview;
61+
return this;
62+
}
63+
}

0 commit comments

Comments
 (0)