├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src ├── main └── java │ └── de │ └── raysha │ └── lib │ └── telegram │ └── bot │ └── api │ ├── BotAPI.java │ ├── RequestExecutor.java │ ├── TelegramBot.java │ ├── UnirestRequestExecutor.java │ ├── exception │ ├── BotApiException.java │ └── BotException.java │ └── model │ ├── Audio.java │ ├── Chat.java │ ├── ChatId.java │ ├── Contact.java │ ├── Document.java │ ├── File.java │ ├── ForceReply.java │ ├── InlineQuery.java │ ├── InlineQueryResult.java │ ├── InlineQueryResultArticle.java │ ├── InlineQueryResultGif.java │ ├── InlineQueryResultMpeg4Gif.java │ ├── InlineQueryResultPhoto.java │ ├── InlineQueryResultVideo.java │ ├── Location.java │ ├── Message.java │ ├── PhotoSize.java │ ├── ReplyKeyboardHide.java │ ├── ReplyKeyboardMarkup.java │ ├── Sticker.java │ ├── Update.java │ ├── User.java │ ├── UserProfilePhotos.java │ ├── Video.java │ └── Voice.java └── test ├── java └── de │ └── raysha │ └── lib │ └── telegram │ └── bot │ └── api │ └── TelegramBotTest.java └── resources ├── test-audio.mp3 ├── test-doc.txt ├── test-pic.jpg ├── test-sticker.webp ├── test-vid.mp4 ├── test-voice.ogg └── test.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 rainu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # telegram-bot-api 2 | This is an api-project for the telegram bot (HTTPS) api. For additional informations see the official [telegram bot api documentation](https://core.telegram.org/bots/api). 3 | 4 | Usage 5 | ----- 6 | 7 | ```java 8 | import de.raysha.lib.telegram.bot.api.BotAPI; 9 | import de.raysha.lib.telegram.bot.api.TelegramBot; 10 | import de.raysha.lib.telegram.bot.api.model.User; 11 | 12 | ... 13 | 14 | final String botToken = "11111-aaaabbbbbccccddddeeeeffff"; 15 | final BotAPI telegramBot = new TelegramBot(botToken); 16 | 17 | try{ 18 | User user = telegramBot.getMe(); 19 | }catch(BotException e){ 20 | System.err.println("Could not get me!"); 21 | } 22 | 23 | ``` 24 | 25 | License 26 | ------- 27 | 28 | This Bot-API is distributed under the [MIT-License](http://www.opensource.org/licenses/mit-license.php). 29 | 30 | Maven Usage 31 | -------- 32 | 33 | If you want to add ___telegram-bot-api___ to your maven project, you can add the following dependency in your __pom.xml__: 34 | 35 | ```xml 36 | 37 | de.raysha.lib.telegram 38 | bot-api 39 | 2.1 40 | 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.sonatype.oss 7 | oss-parent 8 | 9 9 | 10 | 11 | de.raysha.lib.telegram 12 | bot-api 13 | 2.2-SNAPSHOT 14 | 15 | telegram-bot-api 16 | 17 | This is an java library for the Telegram-Bot-API. 18 | The Bot-API is an HTTP-based interface created for 19 | developers keen on building bots for Telegram. 20 | 21 | 22 | https://github.com/rainu/telegram-bot-api 23 | 24 | 25 | 26 | MIT License 27 | http://www.opensource.org/licenses/mit-license.php 28 | repo 29 | 30 | 31 | 32 | 33 | scm:git:git://github.com/rainu/telegram-bot-api.git 34 | scm:git:ssh://git@github.com/rainu/telegram-bot-api.git 35 | http://github.com/rainu/telegram-bot-api 36 | 37 | 38 | 39 | github 40 | https://github.com/rainu/telegram-bot-api/issues 41 | 42 | 43 | 44 | 45 | rainu 46 | Rainu 47 | rainu@raysha.de 48 | 49 | Developer 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-compiler-plugin 59 | 3.1 60 | 61 | 1.6 62 | 1.6 63 | UTF-8 64 | 65 | 66 | 67 | org.apache.maven.plugins 68 | maven-javadoc-plugin 69 | 2.9.1 70 | 71 | 1.6 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-source-plugin 77 | 2.3 78 | 79 | 80 | attach-sources 81 | 82 | jar-no-fork 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | junit 93 | junit 94 | 4.12 95 | test 96 | 97 | 98 | com.mashape.unirest 99 | unirest-java 100 | 1.4.5 101 | 102 | 103 | org.codehaus.jackson 104 | jackson-mapper-asl 105 | 1.9.13 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/BotAPI.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api; 2 | 3 | import de.raysha.lib.telegram.bot.api.exception.BotException; 4 | import de.raysha.lib.telegram.bot.api.model.Audio; 5 | import de.raysha.lib.telegram.bot.api.model.ChatId; 6 | import de.raysha.lib.telegram.bot.api.model.Document; 7 | import de.raysha.lib.telegram.bot.api.model.ForceReply; 8 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResult; 9 | import de.raysha.lib.telegram.bot.api.model.Message; 10 | import de.raysha.lib.telegram.bot.api.model.ReplyKeyboardHide; 11 | import de.raysha.lib.telegram.bot.api.model.ReplyKeyboardMarkup; 12 | import de.raysha.lib.telegram.bot.api.model.Update; 13 | import de.raysha.lib.telegram.bot.api.model.User; 14 | import de.raysha.lib.telegram.bot.api.model.UserProfilePhotos; 15 | 16 | import java.io.File; 17 | import java.util.List; 18 | 19 | /** 20 | * The BotAPI is an HTTP-based interface created for developers keen on building bots for Telegram. 21 | */ 22 | public interface BotAPI { 23 | 24 | /** 25 | * A simple method for testing your bot's auth token. Requires no parameters. 26 | * Returns basic information about the bot in form of a {@link User} object. 27 | * 28 | * @return User 29 | */ 30 | public User getMe() throws BotException; 31 | 32 | /** 33 | * Use this method to receive incoming updates using long polling (wiki). 34 | * An Array of {@link Update} objects is returned. 35 | *

36 | * Notes 37 | * 41 | * 42 | * @param offset Identifier of the first update to be returned. 43 | * Must be greater by one than the highest among the identifiers 44 | * of previously received updates. By default, updates starting 45 | * with the earliest unconfirmed update are returned. An update 46 | * is considered confirmed as soon as getUpdates is called 47 | * with an offset higher than its update_id. 48 | * @param limit Limits the number of updates to be retrieved. 49 | * Values between 1—100 are accepted. Defaults to 100 50 | * @param timeout Timeout in seconds for long polling. 51 | * Defaults to 0, i.e. usual short polling 52 | */ 53 | public List getUpdates(Integer offset, Integer limit, Integer timeout) throws BotException; 54 | 55 | /** 56 | * Use this method to send text messages. On success, the sent {@link Message} is returned. 57 | * 58 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 59 | * @param text Text of the message to be sent 60 | * @return 61 | * @throws BotException 62 | */ 63 | public Message sendMessage(ChatId chatId, String text) throws BotException; 64 | 65 | public static enum ParseMode { 66 | Markdown 67 | } 68 | 69 | /** 70 | * Use this method to send text messages. On success, the sent {@link Message} is returned. 71 | * 72 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 73 | * @param text Text of the message to be sent 74 | * @param parseMode Send Markdown, if you want Telegram apps to show 75 | * bold, italic and inline URLs 76 | * in your bot's message. 77 | * For the moment, only Telegram for Android supports this. 78 | * @param disableWebPagePreview Disables link previews for links in this message 79 | * @param replyToMessageId If the message is a reply, ID of the original message 80 | * @param replyMarkup Can be 81 | * {@link ReplyKeyboardMarkup} or 82 | * {@link ReplyKeyboardHide} or 83 | * {@link ForceReply}. 84 | * Additional interface options. A JSON-serialized object for a 85 | * custom reply keyboard, 86 | * instructions to hide keyboard or to force a reply from the user. 87 | * @return 88 | * @throws BotException 89 | */ 90 | public Message sendMessage(ChatId chatId, String text, ParseMode parseMode, Boolean disableWebPagePreview, Integer replyToMessageId, Object replyMarkup) throws BotException; 91 | 92 | /** 93 | * Use this method to forward messages of any kind. On success, the sent {@link Message} is returned. 94 | * 95 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 96 | * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) 97 | * @param messageId Unique message identifier 98 | * @return 99 | */ 100 | public Message forwardMessage(ChatId chatId, ChatId fromChatId, Integer messageId) throws BotException; 101 | 102 | /** 103 | * Use this method to send photos. On success, the sent {@link Message} is returned. 104 | * 105 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 106 | * @param photo A file_id as String to resend a photo that is already on the Telegram servers 107 | * @return 108 | */ 109 | public Message sendPhoto(ChatId chatId, String photo) throws BotException; 110 | 111 | /** 112 | * Use this method to send photos. On success, the sent {@link Message} is returned. 113 | * 114 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 115 | * @param photo Photo to send. 116 | * @return 117 | */ 118 | public Message sendPhoto(ChatId chatId, File photo) throws BotException; 119 | 120 | /** 121 | * Use this method to send photos. On success, the sent {@link Message} is returned. 122 | * 123 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 124 | * @param photo Photo to send. You can either pass a file_id as String to resend a photo that is already on the 125 | * Telegram servers, or upload a new photo using multipart/form-data. 126 | * @param caption Photo caption (may also be used when resending photos by file_id). 127 | * @param replyToMessageId If the message is a reply, ID of the original message 128 | * @param replyMarkup Additional interface options. A JSON-serialized object for a custom reply keyboard, 129 | * instructions to hide keyboard or to force a reply from the user. 130 | * @return 131 | */ 132 | public Message sendPhoto(ChatId chatId, Object photo, String caption, Integer replyToMessageId, Object replyMarkup) throws BotException; 133 | 134 | /** 135 | * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 136 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). 137 | * On success, the sent {@link Message} is returned. Bots can currently send audio files of up to 50 MB in size, 138 | * this limit may be changed in the future. 139 | *
140 | * For backward compatibility, when the fields title and performer are both empty and the mime-type of the 141 | * file to be sent is not audio/mpeg, the file will be sent as a playable voice message. For this to work, 142 | * the audio must be in an .ogg file encoded with OPUS. This behavior will be phased out in the future. 143 | * For sending voice messages, use the sendVoice method instead. 144 | * 145 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 146 | * @param audio Audio file to send. Upload a new audio file using multipart/form-data. 147 | * @return 148 | */ 149 | public Message sendAudio(ChatId chatId, File audio) throws BotException; 150 | 151 | /** 152 | * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 153 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). 154 | * On success, the sent {@link Message} is returned. Bots can currently send audio files of up to 50 MB in size, 155 | * this limit may be changed in the future. 156 | * 157 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 158 | * @param audio A file_id as String to resend an audio that is already on the Telegram servers. 159 | * @return 160 | */ 161 | public Message sendAudio(ChatId chatId, String audio) throws BotException; 162 | 163 | /** 164 | * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 165 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). 166 | * On success, the sent {@link Message} is returned. Bots can currently send audio files of up to 50 MB in size, 167 | * this limit may be changed in the future. 168 | * 169 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 170 | * @param audio Audio file to send. You can either pass a file_id as String to resend an audio that is already 171 | * on the Telegram servers, or upload a new audio file using multipart/form-data. 172 | * @param duration Duration of the audio in seconds 173 | * @param performer Performer 174 | * @param title Track name 175 | * @param replyToMessageId If the message is a reply, ID of the original message 176 | * @param replyMarkup Additional interface options. A JSON-serialized object for a custom reply keyboard, 177 | * instructions to hide keyboard or to force a reply from the user. 178 | * @return 179 | */ 180 | public Message sendAudio(ChatId chatId, Object audio, Integer duration, String performer, String title, Integer replyToMessageId, Object replyMarkup) throws BotException; 181 | 182 | /** 183 | * Use this method to send general files. On success, the sent {@link Message} is returned. 184 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. 185 | * 186 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 187 | * @param document File to send. Upload a new file using multipart/form-data. 188 | * @return 189 | */ 190 | public Message sendDocument(ChatId chatId, File document) throws BotException; 191 | 192 | /** 193 | * Use this method to send general files. On success, the sent {@link Message} is returned. 194 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. 195 | * 196 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 197 | * @param document A file_id as String to resend a file that is already on the Telegram servers. 198 | * @return 199 | */ 200 | public Message sendDocument(ChatId chatId, String document) throws BotException; 201 | 202 | /** 203 | * Use this method to send general files. On success, the sent {@link Message} is returned. 204 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. 205 | * 206 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 207 | * @param document File to send. You can either pass a file_id as String to resend a file that is 208 | * already on the Telegram servers, or upload a new file using multipart/form-data. 209 | * @param replyToMessageId If the message is a reply, ID of the original message 210 | * @param replyMarkup Additional interface options. A JSON-serialized object for a custom reply keyboard, 211 | * instructions to hide keyboard or to force a reply from the user. 212 | * @return 213 | */ 214 | public Message sendDocument(ChatId chatId, Object document, Integer replyToMessageId, Object replyMarkup) throws BotException; 215 | 216 | /** 217 | * Use this method to send .webp stickers. On success, the sent {@link Message} is returned. 218 | * 219 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 220 | * @param sticker Sticker to send. Upload a new sticker using multipart/form-data. 221 | * @return 222 | */ 223 | public Message sendSticker(ChatId chatId, File sticker) throws BotException; 224 | 225 | /** 226 | * Use this method to send .webp stickers. On success, the sent {@link Message} is returned. 227 | * 228 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 229 | * @param sticker A file_id as String to resend a sticker that is already on the Telegram servers. 230 | * @return 231 | */ 232 | public Message sendSticker(ChatId chatId, String sticker) throws BotException; 233 | 234 | 235 | /** 236 | * Use this method to send .webp stickers. On success, the sent {@link Message} is returned. 237 | * 238 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 239 | * @param sticker Sticker to send. You can either pass a file_id as String to resend a sticker that is already 240 | * on the Telegram servers, or upload a new sticker using multipart/form-data. 241 | * @param replyToMessageId If the message is a reply, ID of the original message 242 | * @param replyMarkup Additional interface options. A JSON-serialized object for a custom reply keyboard, 243 | * instructions to hide keyboard or to force a reply from the user. 244 | * @return 245 | */ 246 | public Message sendSticker(ChatId chatId, Object sticker, Integer replyToMessageId, Object replyMarkup) throws BotException; 247 | 248 | /** 249 | * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). 250 | * On success, the sent {@link Message} is returned. Bots can currently send video files of up to 50 MB in size, 251 | * this limit may be changed in the future. 252 | * 253 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 254 | * @param video Video to send. Upload a new video file using multipart/form-data. 255 | * @return 256 | */ 257 | public Message sendVideo(ChatId chatId, File video) throws BotException; 258 | 259 | /** 260 | * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). 261 | * On success, the sent {@link Message} is returned. Bots can currently send video files of up to 50 MB in size, 262 | * this limit may be changed in the future. 263 | * 264 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 265 | * @param video A file_id as String to resend a video that is already on the Telegram servers. 266 | * @return 267 | */ 268 | public Message sendVideo(ChatId chatId, String video) throws BotException; 269 | 270 | /** 271 | * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). 272 | * On success, the sent {@link Message} is returned. Bots can currently send video files of up to 50 MB in size, 273 | * this limit may be changed in the future. 274 | * 275 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 276 | * @param video Video to send. You can either pass a file_id as String to resend a video that is already on 277 | * the Telegram servers, or upload a new video file using multipart/form-data. 278 | * @param duration Duration of sent video in seconds 279 | * @param caption Video caption (may also be used when resending videos by file_id). 280 | * @param replyToMessageId If the message is a reply, ID of the original message 281 | * @param replyMarkup Additional interface options. A JSON-serialized object for a custom reply keyboard, 282 | * instructions to hide keyboard or to force a reply from the user. 283 | * @return 284 | */ 285 | public Message sendVideo(ChatId chatId, Object video, Integer duration, String caption, Integer replyToMessageId, Object replyMarkup) throws BotException; 286 | 287 | /** 288 | * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 289 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as {@link Audio} or {@link Document}). 290 | * On success, the sent {@link Message} is returned. Bots can currently send voice messages of up to 50 MB in size, 291 | * this limit may be changed in the future. 292 | * 293 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 294 | * @param video Audio file to send. You can either pass a file_id as String to resend an audio that is already on the 295 | * Telegram servers, or upload a new audio file using multipart/form-data. 296 | * @return 297 | * @throws BotException 298 | */ 299 | public Message sendVoice(ChatId chatId, File video) throws BotException; 300 | 301 | /** 302 | * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 303 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as {@link Audio} or {@link Document}). 304 | * On success, the sent {@link Message} is returned. Bots can currently send voice messages of up to 50 MB in size, 305 | * this limit may be changed in the future. 306 | * 307 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 308 | * @param video Audio file to send. You can either pass a file_id as String to resend an audio that is already on the 309 | * Telegram servers, or upload a new audio file using multipart/form-data. 310 | * @return 311 | * @throws BotException 312 | */ 313 | public Message sendVoice(ChatId chatId, String video) throws BotException; 314 | 315 | /** 316 | * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 317 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as {@link Audio} or {@link Document}). 318 | * On success, the sent {@link Message} is returned. Bots can currently send voice messages of up to 50 MB in size, 319 | * this limit may be changed in the future. 320 | * 321 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 322 | * @param video Audio file to send. You can either pass a file_id as String to resend an audio that is already on the 323 | * Telegram servers, or upload a new audio file using multipart/form-data. 324 | * @param duration Duration of sent audio in seconds 325 | * @param replyToMessageId If the message is a reply, ID of the original message 326 | * @param replyMarkup Additional interface options. A JSON-serialized object for a custom reply keyboard, 327 | * instructions to hide keyboard or to force a reply from the user. 328 | * @return 329 | * @throws BotException 330 | */ 331 | public Message sendVoice(ChatId chatId, Object video, Integer duration, Integer replyToMessageId, Object replyMarkup) throws BotException; 332 | 333 | /** 334 | * Use this method to send point on the map. On success, the sent {@link Message} is returned. 335 | * 336 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 337 | * @param latitude Latitude of location 338 | * @param longitude Longitude of location 339 | * @return 340 | */ 341 | public Message sendLocation(ChatId chatId, Float latitude, Float longitude) throws BotException; 342 | 343 | 344 | /** 345 | * Use this method to send point on the map. On success, the sent {@link Message} is returned. 346 | * 347 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 348 | * @param latitude Latitude of location 349 | * @param longitude Longitude of location 350 | * @param replyToMessageId If the message is a reply, ID of the original message 351 | * @param replyMarkup Additional interface options. A JSON-serialized object for a custom reply keyboard, 352 | * instructions to hide keyboard or to force a reply from the user. 353 | * @return 354 | */ 355 | public Message sendLocation(ChatId chatId, Float latitude, Float longitude, Integer replyToMessageId, Object replyMarkup) throws BotException; 356 | 357 | /** 358 | * Use this method when you need to tell the user that something is happening on the bot's side. 359 | * The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). 360 | *

361 | * Example: The ImageBot needs some time to process a request and upload the image. 362 | * Instead of sending a text message along the lines of “Retrieving image, please wait…”, 363 | * the bot may use sendChatAction with action = upload_photo. 364 | * The user will see a “sending photo” status for the bot. 365 | * 366 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 367 | * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: 368 | * typing for text messages, upload_photo for photos, record_video or upload_video for videos, 369 | * record_audio or upload_audio for audio files, upload_document for general files, 370 | * find_location for location data. 371 | */ 372 | public Boolean sendChatAction(ChatId chatId, String action) throws BotException; 373 | 374 | /** 375 | * This enum contains all possible chat actions. 376 | */ 377 | public static enum ChatAction { 378 | typing, upload_photo, record_video, upload_video, record_audio, 379 | upload_audio, upload_document, find_location; 380 | } 381 | 382 | /** 383 | * Use this method when you need to tell the user that something is happening on the bot's side. 384 | * The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). 385 | *

386 | * Example: The ImageBot needs some time to process a request and upload the image. 387 | * Instead of sending a text message along the lines of “Retrieving image, please wait…”, 388 | * the bot may use sendChatAction with action = upload_photo. 389 | * The user will see a “sending photo” status for the bot. 390 | * 391 | * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) 392 | * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: 393 | * typing for text messages, upload_photo for photos, record_video or upload_video for videos, 394 | * record_audio or upload_audio for audio files, upload_document for general files, 395 | * find_location for location data. 396 | */ 397 | public Boolean sendChatAction(ChatId chatId, ChatAction action) throws BotException; 398 | 399 | /** 400 | * Use this method to get a list of profile pictures for a user. Returns a {@link UserProfilePhotos} object. 401 | * 402 | * @param userId Unique identifier of the target user 403 | * @return 404 | */ 405 | public UserProfilePhotos getUserProfilePhotos(Integer userId) throws BotException; 406 | 407 | 408 | /** 409 | * Use this method to get a list of profile pictures for a user. Returns a {@link UserProfilePhotos} object. 410 | * 411 | * @param userId Unique identifier of the target user 412 | * @param offset Sequential number of the first photo to be returned. By default, all photos are returned. 413 | * @param limit Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. 414 | * @return 415 | */ 416 | public UserProfilePhotos getUserProfilePhotos(Integer userId, Integer offset, Integer limit) throws BotException; 417 | 418 | /** 419 | * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an 420 | * update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. 421 | * In case of an unsuccessful request, we will give up after a reasonable amount of attempts. 422 | *
423 | * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, 424 | * e.g. https://www.example.com/<token>. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. 425 | *

426 | * Notes 427 | * 432 | * 433 | * @param url HTTPS url to send updates to. Use an empty string to remove webhook integration 434 | * @return 435 | */ 436 | public Boolean setWebhook(String url) throws BotException; 437 | 438 | /** 439 | * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an 440 | * update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. 441 | * In case of an unsuccessful request, we will give up after a reasonable amount of attempts. 442 | *
443 | * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, 444 | * e.g. https://www.example.com/<token>. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. 445 | *

446 | * Notes 447 | * 452 | * 453 | * @param url HTTPS url to send updates to. Use an empty string to remove webhook integration 454 | * @param certificate Upload your public key certificate so that the root certificate in use can be checked. 455 | * See our self-signed guide for details. 456 | * @return 457 | */ 458 | public Boolean setWebhook(String url, File certificate) throws BotException; 459 | 460 | /** 461 | * Use this method to get basic info about a file and prepare it for downloading. 462 | * For the moment, bots can download files of up to 20MB in size. On success, a {@link de.raysha.lib.telegram.bot.api.model.File} object is returned. 463 | * The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, 464 | * where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. 465 | * When the link expires, a new one can be requested by calling getFile again. 466 | * 467 | * @param fileId File identifier to get info about 468 | * @return 469 | */ 470 | public de.raysha.lib.telegram.bot.api.model.File getFile(String fileId) throws BotException; 471 | 472 | /** 473 | * Use this method to send answers to an inline query. On success, True is returned. 474 | * No more than 50 results per query are allowed. 475 | * 476 | * @param inlineQueryId Unique identifier for the answered query 477 | * @param results A JSON-serialized array of results for the inline query 478 | * @return 479 | */ 480 | public Boolean answerInlineQuery(String inlineQueryId, List results) throws BotException; 481 | 482 | /** 483 | * Use this method to send answers to an inline query. On success, True is returned. 484 | * No more than 50 results per query are allowed. 485 | * 486 | * @param inlineQueryId Unique identifier for the answered query 487 | * @param results A JSON-serialized array of results for the inline query 488 | * @param cacheTime The maximum amount of time in seconds that the result of the inline query may be cached on 489 | * the server. Defaults to 300. 490 | * @param isPersonal Pass True, if results may be cached on the server side only for the user that sent 491 | * the query. By default, results may be returned to any user who sends the same query 492 | * @param nextOffset Pass the offset that a client should send in the next query with the same text to receive 493 | * more results. Pass an empty string if there are no more results or if you don‘t support 494 | * pagination. Offset length can’t exceed 64 bytes. 495 | * @return 496 | */ 497 | public Boolean answerInlineQuery(String inlineQueryId, List results, Integer cacheTime, 498 | Boolean isPersonal, String nextOffset) throws BotException; 499 | } 500 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/RequestExecutor.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api; 2 | 3 | import de.raysha.lib.telegram.bot.api.exception.BotException; 4 | 5 | import java.io.File; 6 | import java.util.Map; 7 | 8 | /** 9 | * Executes requests to Telegram Bot API 10 | */ 11 | public interface RequestExecutor { 12 | 13 | /** 14 | * Make GET request to the API 15 | * 16 | * @param action API method name (/bot%TOKEN%/%ACTION%) 17 | * @param parameters query parameters 18 | * @return value of 'result' field 19 | * @throws BotException on internal exception (IO, invalid response, etc 20 | */ 21 | String get(String action, Map parameters) throws BotException; 22 | 23 | /** 24 | * Make POST request to the API 25 | * 26 | * @param action API method name (/bot%TOKEN%/%ACTION%) 27 | * @param parameters query parameters 28 | * @return value of 'result' field 29 | * @throws BotException on internal exception (IO, invalid response, etc 30 | */ 31 | String post(String action, Map parameters) throws BotException; 32 | 33 | /** 34 | * Make POST request to the API, with a file 35 | * 36 | * @param action API method name (/bot%TOKEN%/%ACTION%) 37 | * @param parameters query parameters 38 | * @param fileName a parameter name for the file ('photo', 'sticker', etc) 39 | * @param file file to upload 40 | * @return value of 'result' field 41 | * @throws BotException on internal exception (IO, invalid response, etc 42 | */ 43 | String post(String action, Map parameters, String fileName, File file) throws BotException; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/TelegramBot.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api; 2 | 3 | import de.raysha.lib.telegram.bot.api.exception.BotException; 4 | import de.raysha.lib.telegram.bot.api.model.ChatId; 5 | import de.raysha.lib.telegram.bot.api.model.ForceReply; 6 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResult; 7 | import de.raysha.lib.telegram.bot.api.model.Message; 8 | import de.raysha.lib.telegram.bot.api.model.ReplyKeyboardHide; 9 | import de.raysha.lib.telegram.bot.api.model.ReplyKeyboardMarkup; 10 | import de.raysha.lib.telegram.bot.api.model.Update; 11 | import de.raysha.lib.telegram.bot.api.model.User; 12 | import de.raysha.lib.telegram.bot.api.model.UserProfilePhotos; 13 | import org.codehaus.jackson.map.ObjectMapper; 14 | 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | public class TelegramBot implements BotAPI { 22 | private final ObjectMapper mapper = new ObjectMapper(); 23 | private final RequestExecutor requestExecutor; 24 | 25 | public TelegramBot(String token) { 26 | this(new UnirestRequestExecutor("https://api.telegram.org/bot" + token + "/")); 27 | } 28 | 29 | public TelegramBot(RequestExecutor requestExecutor) { 30 | this.requestExecutor = requestExecutor; 31 | } 32 | 33 | @Override 34 | public User getMe() throws BotException { 35 | final String resultBody = requestExecutor.get("getMe", null); 36 | 37 | try { 38 | return mapper.readValue(resultBody, User.class); 39 | } catch (IOException e) { 40 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 41 | } 42 | } 43 | 44 | @Override 45 | public List getUpdates(Integer offset, Integer limit, Integer timeout) throws BotException { 46 | final Map parameters = new HashMap(); 47 | if(offset != null) parameters.put("offset", offset); 48 | if(limit != null) parameters.put("limit", limit); 49 | if(timeout != null) parameters.put("timeout", timeout); 50 | 51 | final String resultBody = requestExecutor.get("getUpdates", parameters); 52 | 53 | try { 54 | return mapper.readValue(resultBody, 55 | mapper.getTypeFactory().constructCollectionType(List.class, Update.class)); 56 | } catch (IOException e) { 57 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 58 | } 59 | } 60 | 61 | @Override 62 | public Message sendMessage(ChatId chatId, String text) throws BotException { 63 | return sendMessage(chatId, text, null, null, null, null); 64 | } 65 | 66 | 67 | @Override 68 | public Message sendMessage(ChatId chatId, String text, ParseMode parseMode, 69 | Boolean disableWebPagePreview, Integer replyToMessageId, Object replyMarkup) throws BotException { 70 | 71 | checkReply(replyMarkup); 72 | 73 | final Map parameters = new HashMap(); 74 | parameters.put("chat_id", chatId.getId()); 75 | parameters.put("text", text); 76 | if(parseMode != null) parameters.put("parse_mode", parseMode.name()); 77 | if(disableWebPagePreview != null) parameters.put("disable_web_page_preview", disableWebPagePreview); 78 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 79 | if(replyMarkup != null) { 80 | try { 81 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 82 | } catch (IOException e) { 83 | throw new BotException("Could not serialize reply markup!", e); 84 | } 85 | } 86 | 87 | final String resultBody = requestExecutor.post("sendMessage", parameters); 88 | 89 | try { 90 | return mapper.readValue(resultBody, Message.class); 91 | } catch (IOException e) { 92 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 93 | } 94 | } 95 | 96 | private void checkReply(Object replyMarkup) { 97 | if(replyMarkup != null){ 98 | if(!( replyMarkup instanceof ReplyKeyboardHide || 99 | replyMarkup instanceof ReplyKeyboardMarkup || 100 | replyMarkup instanceof ForceReply)){ 101 | 102 | throw new IllegalStateException("The replyMarkup must be on of the following classes: " + 103 | ReplyKeyboardHide.class.getName() + ", " + 104 | ReplyKeyboardMarkup.class.getName() + ", " + 105 | ForceReply.class.getName()); 106 | } 107 | } 108 | } 109 | 110 | @Override 111 | public Message forwardMessage(ChatId chatId, ChatId fromChatId, Integer messageId) throws BotException { 112 | final Map parameters = new HashMap(); 113 | parameters.put("chat_id", chatId.getId()); 114 | parameters.put("from_chat_id", fromChatId.getId()); 115 | parameters.put("message_id", messageId); 116 | 117 | final String resultBody = requestExecutor.get("forwardMessage", parameters); 118 | 119 | try { 120 | return mapper.readValue(resultBody, Message.class); 121 | } catch (IOException e) { 122 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 123 | } 124 | } 125 | 126 | @Override 127 | public Message sendPhoto(ChatId chatId, String photo) throws BotException { 128 | return sendPhoto(chatId, photo, null, null, null); 129 | } 130 | 131 | @Override 132 | public Message sendPhoto(ChatId chatId, File photo) throws BotException { 133 | return sendPhoto(chatId, photo, null, null, null); 134 | } 135 | 136 | @Override 137 | public Message sendPhoto(ChatId chatId, Object photo, String caption, Integer replyToMessageId, Object replyMarkup) throws BotException { 138 | checkReply(replyMarkup); 139 | 140 | final Map parameters = new HashMap(); 141 | parameters.put("chat_id", chatId.getId()); 142 | 143 | if(caption != null) parameters.put("caption", caption); 144 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 145 | 146 | if(replyMarkup != null) { 147 | try { 148 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 149 | } catch (IOException e) { 150 | throw new BotException("Could not serialize reply markup!", e); 151 | } 152 | } 153 | 154 | final String resultBody; 155 | 156 | if(photo instanceof String) { 157 | parameters.put("photo", photo); 158 | 159 | resultBody = requestExecutor.post("sendPhoto", parameters); 160 | }else if(photo instanceof File){ 161 | resultBody = requestExecutor.post("sendPhoto", parameters, "photo", (File) photo); 162 | 163 | }else{ 164 | throw new IllegalArgumentException("The photo must be a string or a file!"); 165 | } 166 | 167 | try { 168 | return mapper.readValue(resultBody, Message.class); 169 | } catch (IOException e) { 170 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 171 | } 172 | } 173 | 174 | @Override 175 | public Message sendAudio(ChatId chatId, File audio) throws BotException { 176 | return sendAudio(chatId, audio, null, null, null, null, null); 177 | } 178 | 179 | @Override 180 | public Message sendAudio(ChatId chatId, String audio) throws BotException { 181 | return sendAudio(chatId, audio, null, null, null, null, null); 182 | } 183 | 184 | public Message sendAudio(ChatId chatId, Object audio, Integer duration, 185 | String performer, String title, Integer replyToMessageId, 186 | Object replyMarkup) throws BotException { 187 | checkReply(replyMarkup); 188 | 189 | final Map parameters = new HashMap(); 190 | parameters.put("chat_id", chatId.getId()); 191 | 192 | if(duration != null) parameters.put("duration", duration); 193 | if(performer != null) parameters.put("performer", performer); 194 | if(title != null) parameters.put("title", title); 195 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 196 | 197 | if(replyMarkup != null) { 198 | try { 199 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 200 | } catch (IOException e) { 201 | throw new BotException("Could not serialize reply markup!", e); 202 | } 203 | } 204 | 205 | final String resultBody; 206 | 207 | if(audio instanceof String) { 208 | parameters.put("audio", audio); 209 | 210 | resultBody = requestExecutor.post("sendAudio", parameters); 211 | }else if(audio instanceof File){ 212 | resultBody = requestExecutor.post("sendAudio", parameters, "audio", (File) audio); 213 | 214 | }else{ 215 | throw new IllegalArgumentException("The audio must be a string or a file!"); 216 | } 217 | 218 | try { 219 | return mapper.readValue(resultBody, Message.class); 220 | } catch (IOException e) { 221 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 222 | } 223 | } 224 | 225 | public Message sendDocument(ChatId chatId, File document) throws BotException { 226 | return sendDocument(chatId, document, null, null); 227 | } 228 | 229 | @Override 230 | public Message sendDocument(ChatId chatId, String document) throws BotException { 231 | return sendDocument(chatId, document, null, null); 232 | } 233 | 234 | @Override 235 | public Message sendDocument(ChatId chatId, Object document, Integer replyToMessageId, Object replyMarkup) throws BotException { 236 | checkReply(replyMarkup); 237 | 238 | final Map parameters = new HashMap(); 239 | parameters.put("chat_id", chatId.getId()); 240 | 241 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 242 | 243 | if(replyMarkup != null) { 244 | try { 245 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 246 | } catch (IOException e) { 247 | throw new BotException("Could not serialize reply markup!", e); 248 | } 249 | } 250 | 251 | final String resultBody; 252 | 253 | if(document instanceof String) { 254 | parameters.put("document", document); 255 | 256 | resultBody = requestExecutor.post("sendDocument", parameters); 257 | }else if(document instanceof File){ 258 | resultBody = requestExecutor.post("sendDocument", parameters, "document", (File) document); 259 | 260 | }else{ 261 | throw new IllegalArgumentException("The document must be a string or a file!"); 262 | } 263 | 264 | try { 265 | return mapper.readValue(resultBody, Message.class); 266 | } catch (IOException e) { 267 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 268 | } 269 | } 270 | 271 | @Override 272 | public Message sendSticker(ChatId chatId, File sticker) throws BotException { 273 | return sendSticker(chatId, sticker, null, null); 274 | } 275 | 276 | @Override 277 | public Message sendSticker(ChatId chatId, String sticker) throws BotException { 278 | return sendSticker(chatId, sticker, null, null); 279 | } 280 | 281 | @Override 282 | public Message sendSticker(ChatId chatId, Object sticker, Integer replyToMessageId, Object replyMarkup) throws BotException { 283 | checkReply(replyMarkup); 284 | 285 | final Map parameters = new HashMap(); 286 | parameters.put("chat_id", chatId.getId()); 287 | 288 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 289 | 290 | if(replyMarkup != null) { 291 | try { 292 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 293 | } catch (IOException e) { 294 | throw new BotException("Could not serialize reply markup!", e); 295 | } 296 | } 297 | 298 | final String resultBody; 299 | 300 | if(sticker instanceof String) { 301 | parameters.put("sticker", sticker); 302 | 303 | resultBody = requestExecutor.post("sendSticker", parameters); 304 | }else if(sticker instanceof File){ 305 | resultBody = requestExecutor.post("sendSticker", parameters, "sticker", (File) sticker); 306 | 307 | }else{ 308 | throw new IllegalArgumentException("The sticker must be a string or a file!"); 309 | } 310 | 311 | try { 312 | return mapper.readValue(resultBody, Message.class); 313 | } catch (IOException e) { 314 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 315 | } 316 | } 317 | 318 | @Override 319 | public Message sendVoice(ChatId chatId, File voice) throws BotException { 320 | return sendVoice(chatId, voice, null, null, null); 321 | } 322 | 323 | @Override 324 | public Message sendVoice(ChatId chatId, String voice) throws BotException { 325 | return sendVoice(chatId, voice, null, null, null); 326 | } 327 | 328 | @Override 329 | public Message sendVoice(ChatId chatId, Object voice, Integer duration, Integer replyToMessageId, Object replyMarkup) throws BotException { 330 | checkReply(replyMarkup); 331 | 332 | final Map parameters = new HashMap(); 333 | parameters.put("chat_id", chatId.getId()); 334 | 335 | if(duration != null) parameters.put("duration", duration); 336 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 337 | 338 | if(replyMarkup != null) { 339 | try { 340 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 341 | } catch (IOException e) { 342 | throw new BotException("Could not serialize reply markup!", e); 343 | } 344 | } 345 | 346 | final String resultBody; 347 | 348 | if(voice instanceof String) { 349 | parameters.put("voice", voice); 350 | 351 | resultBody = requestExecutor.post("sendVoice", parameters); 352 | }else if(voice instanceof File){ 353 | resultBody = requestExecutor.post("sendVoice", parameters, "voice", (File) voice); 354 | 355 | }else{ 356 | throw new IllegalArgumentException("The voice must be a string or a file!"); 357 | } 358 | 359 | try { 360 | return mapper.readValue(resultBody, Message.class); 361 | } catch (IOException e) { 362 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 363 | } 364 | } 365 | 366 | @Override 367 | public Message sendVideo(ChatId chatId, File video) throws BotException { 368 | return sendVideo(chatId, video, null, null, null, null); 369 | } 370 | 371 | @Override 372 | public Message sendVideo(ChatId chatId, String video) throws BotException { 373 | return sendVideo(chatId, video, null, null, null, null); 374 | } 375 | 376 | public Message sendVideo(ChatId chatId, Object video, Integer duration, String caption, Integer replyToMessageId, Object replyMarkup) throws BotException { 377 | checkReply(replyMarkup); 378 | 379 | final Map parameters = new HashMap(); 380 | parameters.put("chat_id", chatId.getId()); 381 | 382 | if(duration != null) parameters.put("duration", duration); 383 | if(caption != null) parameters.put("caption", caption); 384 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 385 | 386 | if(replyMarkup != null) { 387 | try { 388 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 389 | } catch (IOException e) { 390 | throw new BotException("Could not serialize reply markup!", e); 391 | } 392 | } 393 | 394 | final String resultBody; 395 | 396 | if(video instanceof String) { 397 | parameters.put("video", video); 398 | 399 | resultBody = requestExecutor.post("sendVideo", parameters); 400 | }else if(video instanceof File){ 401 | resultBody = requestExecutor.post("sendVideo", parameters, "video", (File) video); 402 | 403 | }else{ 404 | throw new IllegalArgumentException("The video must be a string or a file!"); 405 | } 406 | 407 | try { 408 | return mapper.readValue(resultBody, Message.class); 409 | } catch (IOException e) { 410 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 411 | } 412 | } 413 | 414 | @Override 415 | public Message sendLocation(ChatId chatId, Float latitude, Float longitude) throws BotException { 416 | return sendLocation(chatId, latitude, longitude, null, null); 417 | } 418 | 419 | @Override 420 | public Message sendLocation(ChatId chatId, Float latitude, Float longitude, Integer replyToMessageId, Object replyMarkup) throws BotException { 421 | checkReply(replyMarkup); 422 | 423 | final Map parameters = new HashMap(); 424 | parameters.put("chat_id", chatId.getId()); 425 | parameters.put("latitude", latitude); 426 | parameters.put("longitude", longitude); 427 | if(replyToMessageId != null) parameters.put("reply_to_message_id", replyToMessageId); 428 | if(replyMarkup != null) { 429 | try { 430 | parameters.put("reply_markup", mapper.writeValueAsString(replyMarkup)); 431 | } catch (IOException e) { 432 | throw new BotException("Could not serialize reply markup!", e); 433 | } 434 | } 435 | 436 | final String resultBody = requestExecutor.post("sendLocation", parameters); 437 | 438 | try { 439 | return mapper.readValue(resultBody, Message.class); 440 | } catch (IOException e) { 441 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 442 | } 443 | } 444 | 445 | @Override 446 | public Boolean sendChatAction(ChatId chatId, ChatAction action) throws BotException { 447 | return sendChatAction(chatId, action.name()); 448 | } 449 | 450 | @Override 451 | public UserProfilePhotos getUserProfilePhotos(Integer userId) throws BotException { 452 | return getUserProfilePhotos(userId, null, null); 453 | } 454 | 455 | @Override 456 | public UserProfilePhotos getUserProfilePhotos(Integer userId, Integer offset, Integer limit) throws BotException { 457 | final Map parameters = new HashMap(); 458 | parameters.put("user_id", userId); 459 | if(offset != null) parameters.put("offset", offset); 460 | if(limit != null) parameters.put("limit", limit); 461 | 462 | final String resultBody = requestExecutor.get("getUserProfilePhotos", parameters); 463 | 464 | try { 465 | return mapper.readValue(resultBody, UserProfilePhotos.class); 466 | } catch (IOException e) { 467 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 468 | } 469 | } 470 | 471 | @Override 472 | public Boolean sendChatAction(ChatId chatId, String action) throws BotException { 473 | final Map parameters = new HashMap(); 474 | parameters.put("chat_id", chatId.getId()); 475 | parameters.put("action", action); 476 | 477 | final String resultBody = requestExecutor.get("sendChatAction", parameters); 478 | 479 | return "True".equalsIgnoreCase(resultBody); 480 | } 481 | 482 | @Override 483 | public Boolean setWebhook(String url) throws BotException { 484 | return setWebhook(url, null); 485 | } 486 | 487 | @Override 488 | public Boolean setWebhook(String url, File certificate) throws BotException { 489 | final Map parameters = new HashMap(); 490 | 491 | if(url != null) parameters.put("url", url); 492 | 493 | final String resultBody; 494 | 495 | if(certificate == null) { 496 | resultBody = requestExecutor.get("setWebhook", parameters); 497 | }else{ 498 | resultBody = requestExecutor.post("setWebhook", parameters, "certificate", certificate); 499 | } 500 | 501 | return "True".equalsIgnoreCase(resultBody); 502 | } 503 | 504 | @Override 505 | public de.raysha.lib.telegram.bot.api.model.File getFile(String fileId) throws BotException { 506 | final Map parameters = new HashMap(); 507 | parameters.put("file_id", fileId); 508 | 509 | final String resultBody = requestExecutor.get("getFile", parameters); 510 | 511 | try { 512 | return mapper.readValue(resultBody, de.raysha.lib.telegram.bot.api.model.File.class); 513 | } catch (IOException e) { 514 | throw new BotException("Could not deserialize response! ResultBody:\n" + resultBody, e); 515 | } 516 | } 517 | 518 | @Override 519 | public Boolean answerInlineQuery(String inlineQueryId, List results) throws BotException { 520 | return answerInlineQuery(inlineQueryId, results, null, null, null); 521 | } 522 | 523 | @Override 524 | public Boolean answerInlineQuery(String inlineQueryId, List results, Integer cacheTime, 525 | Boolean isPersonal, String nextOffset) throws BotException { 526 | 527 | final Map parameters = new HashMap(); 528 | parameters.put("inline_query_id", inlineQueryId); 529 | 530 | try { 531 | parameters.put("results", mapper.writeValueAsString(results)); 532 | } catch (IOException e) { 533 | throw new BotException("Error occurs while serializing the list of results!", e); 534 | } 535 | 536 | if(cacheTime != null) parameters.put("cache_time", cacheTime); 537 | if(isPersonal != null) parameters.put("is_personal", isPersonal); 538 | if(nextOffset != null) parameters.put("next_offset", nextOffset); 539 | 540 | final String resultBody = requestExecutor.get("answerInlineQuery", parameters); 541 | 542 | return "True".equalsIgnoreCase(resultBody); 543 | } 544 | } 545 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/UnirestRequestExecutor.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api; 2 | 3 | import com.mashape.unirest.http.Unirest; 4 | import com.mashape.unirest.http.exceptions.UnirestException; 5 | import com.mashape.unirest.request.BaseRequest; 6 | import de.raysha.lib.telegram.bot.api.exception.BotApiException; 7 | import de.raysha.lib.telegram.bot.api.exception.BotException; 8 | import org.json.JSONObject; 9 | 10 | import java.io.File; 11 | import java.util.Map; 12 | 13 | /** 14 | * Uses Unirest lib for making http requests 15 | */ 16 | public class UnirestRequestExecutor implements RequestExecutor { 17 | 18 | private final String baseUrl; 19 | 20 | public UnirestRequestExecutor(String baseUrl) { 21 | this.baseUrl = baseUrl; 22 | } 23 | 24 | @Override 25 | public String get(String action, Map parameters) throws BotException { 26 | return sendAndHandleRequest( 27 | Unirest.get(baseUrl + action) 28 | .queryString(parameters)); 29 | } 30 | 31 | @Override 32 | public String post(String action, Map parameters) throws BotException { 33 | return sendAndHandleRequest( 34 | Unirest.post(baseUrl + action) 35 | .fields(parameters)); 36 | } 37 | 38 | @Override 39 | public String post(String action, Map parameters, String fileName, File file) throws BotException { 40 | return sendAndHandleRequest( 41 | Unirest.post(baseUrl + action) 42 | .queryString(parameters) 43 | .field(fileName, file)); 44 | } 45 | 46 | private String sendAndHandleRequest(BaseRequest request) throws BotException { 47 | JSONObject jsonResult; 48 | try { 49 | jsonResult = request 50 | .asJson().getBody().getObject(); 51 | } catch (UnirestException e) { 52 | throw new BotException("Could not get a response.", e); 53 | } 54 | 55 | if(jsonResult.get("ok").equals(false)){ 56 | throw new BotApiException( 57 | jsonResult.optInt("error_code", -1), 58 | jsonResult.optString("error_type"), 59 | jsonResult.optString("description")); 60 | } 61 | 62 | return jsonResult.get("result").toString(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/exception/BotApiException.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.exception; 2 | 3 | /** 4 | * Error returned by Telegram Bot API. 5 | * 6 | * See https://core.telegram.org/api/errors 7 | */ 8 | public class BotApiException extends BotException { 9 | 10 | /** 11 | * Similar to HTTP status. Contains information on the type of error that occurred: for example, 12 | * a data input error, privacy error, or server error. 13 | */ 14 | private int errorCode; 15 | 16 | /** 17 | * A string literal in the form of /[A-Z_0-9]+/, which summarizes the problem. For example, AUTH_KEY_UNREGISTERED. 18 | * 19 | * Optional, could be null 20 | */ 21 | private String errorType; 22 | 23 | /** 24 | * May contain more detailed information on the error and how to resolve it, for example: authorization required, 25 | * use auth.* methods. Please note that the description text is subject to change, one should avoid tying 26 | * application logic to these messages. 27 | * 28 | * Optional, could be null 29 | */ 30 | private String description; 31 | 32 | public BotApiException(int errorCode, String errorType, String description, Throwable cause) { 33 | super(cause); 34 | this.errorCode = errorCode; 35 | this.errorType = errorType; 36 | this.description = description; 37 | } 38 | 39 | public BotApiException(int errorCode, String errorType, String description) { 40 | super(); 41 | this.errorCode = errorCode; 42 | this.errorType = errorType; 43 | this.description = description; 44 | } 45 | 46 | public int getErrorCode() { 47 | return errorCode; 48 | } 49 | 50 | public String getErrorType() { 51 | return errorType; 52 | } 53 | 54 | public String getDescription() { 55 | return description; 56 | } 57 | 58 | @Override 59 | public String getMessage() { 60 | StringBuilder buf = new StringBuilder(); 61 | buf.append(errorCode); 62 | if (errorType != null) { 63 | buf.append(' ').append(errorType); 64 | } 65 | if (description != null) { 66 | buf.append(" '").append(description).append('\''); 67 | } 68 | return buf.toString(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/exception/BotException.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.exception; 2 | 3 | public class BotException extends Exception { 4 | 5 | public BotException() { 6 | } 7 | 8 | public BotException(String message) { 9 | super(message); 10 | } 11 | 12 | public BotException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | 16 | public BotException(Throwable cause) { 17 | super(cause); 18 | } 19 | 20 | public BotException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 21 | super(message, cause, enableSuppression, writableStackTrace); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Audio.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents an audio file (voice note). 7 | */ 8 | public class Audio { 9 | 10 | /** 11 | * Unique identifier for this file 12 | */ 13 | private String file_id; 14 | 15 | /** 16 | * Duration of the audio in seconds as defined by sender 17 | */ 18 | private Integer duration; 19 | 20 | /** 21 | * Optional. Performer of the audio as defined by sender or by audio tags 22 | */ 23 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 24 | private String performer; 25 | 26 | /** 27 | * Optional. Title of the audio as defined by sender or by audio tags 28 | */ 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | private String title; 31 | 32 | /** 33 | * Optional. MIME type of the file as defined by sender 34 | */ 35 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 36 | private String mime_type; 37 | 38 | /** 39 | * Optional. File size 40 | */ 41 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 42 | private Integer file_size; 43 | 44 | public String getFile_id() { 45 | return file_id; 46 | } 47 | 48 | public void setFile_id(String file_id) { 49 | this.file_id = file_id; 50 | } 51 | 52 | public Integer getDuration() { 53 | return duration; 54 | } 55 | 56 | public void setDuration(Integer duration) { 57 | this.duration = duration; 58 | } 59 | 60 | public String getPerformer() { 61 | return performer; 62 | } 63 | 64 | public void setPerformer(String performer) { 65 | this.performer = performer; 66 | } 67 | 68 | public String getTitle() { 69 | return title; 70 | } 71 | 72 | public void setTitle(String title) { 73 | this.title = title; 74 | } 75 | 76 | public String getMime_type() { 77 | return mime_type; 78 | } 79 | 80 | public void setMime_type(String mime_type) { 81 | this.mime_type = mime_type; 82 | } 83 | 84 | public Integer getFile_size() { 85 | return file_size; 86 | } 87 | 88 | public void setFile_size(Integer file_size) { 89 | this.file_size = file_size; 90 | } 91 | 92 | @Override 93 | public String toString() { 94 | return "Audio{" + 95 | "file_id='" + file_id + '\'' + 96 | ", duration=" + duration + 97 | ", performer='" + performer + '\'' + 98 | ", title='" + title + '\'' + 99 | ", mime_type='" + mime_type + '\'' + 100 | ", file_size=" + file_size + 101 | '}'; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Chat.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents a chat. 7 | */ 8 | public class Chat { 9 | 10 | /** 11 | * Unique identifier for this chat, not exceeding 1e13 by absolute value 12 | */ 13 | private Integer id; 14 | 15 | /** 16 | * Type of chat, can be either "private", "group", "supergroup" or "channel" 17 | */ 18 | private String type; 19 | 20 | /** 21 | * Optional. Title, for channels and group chats 22 | */ 23 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 24 | private String title; 25 | 26 | /** 27 | * Optional. Username, for private chats and channels if available 28 | */ 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | private String username; 31 | 32 | /** 33 | * Optional. First name of the other party in a private chat 34 | */ 35 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 36 | private String first_name; 37 | 38 | /** 39 | * Optional. Last name of the other party in a private chat 40 | */ 41 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 42 | private String last_name; 43 | 44 | public Integer getId() { 45 | return id; 46 | } 47 | 48 | public void setId(Integer id) { 49 | this.id = id; 50 | } 51 | 52 | public String getType() { 53 | return type; 54 | } 55 | 56 | public void setType(String type) { 57 | this.type = type; 58 | } 59 | 60 | public String getTitle() { 61 | return title; 62 | } 63 | 64 | public void setTitle(String title) { 65 | this.title = title; 66 | } 67 | 68 | public String getUsername() { 69 | return username; 70 | } 71 | 72 | public void setUsername(String username) { 73 | this.username = username; 74 | } 75 | 76 | public String getFirst_name() { 77 | return first_name; 78 | } 79 | 80 | public void setFirst_name(String first_name) { 81 | this.first_name = first_name; 82 | } 83 | 84 | public String getLast_name() { 85 | return last_name; 86 | } 87 | 88 | public void setLast_name(String last_name) { 89 | this.last_name = last_name; 90 | } 91 | 92 | @Override 93 | public String toString() { 94 | return "Chat{" + 95 | "id=" + id + 96 | ", type='" + type + '\'' + 97 | ", title='" + title + '\'' + 98 | ", username='" + username + '\'' + 99 | ", first_name='" + first_name + '\'' + 100 | ", last_name='" + last_name + '\'' + 101 | '}'; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/ChatId.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | /** 4 | * This object represents a chat. A chatId contains a String or an Integer as Identifier. 5 | */ 6 | public class ChatId { 7 | private String sId; 8 | private Integer iId; 9 | 10 | public ChatId(Object id) { 11 | checkId(id); 12 | 13 | if(id instanceof String){ 14 | this.sId = (String)id; 15 | }else if(id instanceof Integer){ 16 | this.iId = (Integer)id; 17 | }else{ 18 | throw new IllegalArgumentException("The id must be either a String or a Intger!"); 19 | } 20 | } 21 | 22 | public ChatId(String id) { 23 | checkId(id); 24 | 25 | this.sId = id; 26 | this.iId = null; 27 | } 28 | 29 | public ChatId(Integer id) { 30 | checkId(id); 31 | 32 | this.iId = id; 33 | this.sId = null; 34 | } 35 | 36 | private void checkId(Object id) { 37 | if(id == null) throw new IllegalArgumentException("The id must not be null!"); 38 | } 39 | 40 | public Object getId(){ 41 | if(sId != null) return sId; 42 | return iId; 43 | } 44 | 45 | public String getsId() { 46 | return sId; 47 | } 48 | 49 | public Integer getiId() { 50 | return iId; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "" + getId(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Contact.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents a phone contact. 7 | */ 8 | public class Contact { 9 | /** 10 | * Contact's phone number 11 | */ 12 | private String phone_number; 13 | 14 | /** 15 | * Contact's first name 16 | */ 17 | private String first_name; 18 | 19 | /** 20 | * Optional. Contact's last name 21 | */ 22 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 23 | private String last_name; 24 | 25 | /** 26 | * Optional. Contact's user identifier in Telegram 27 | */ 28 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 29 | private String user_id; 30 | 31 | public String getPhone_number() { 32 | return phone_number; 33 | } 34 | 35 | public void setPhone_number(String phone_number) { 36 | this.phone_number = phone_number; 37 | } 38 | 39 | public String getFirst_name() { 40 | return first_name; 41 | } 42 | 43 | public void setFirst_name(String first_name) { 44 | this.first_name = first_name; 45 | } 46 | 47 | public String getLast_name() { 48 | return last_name; 49 | } 50 | 51 | public void setLast_name(String last_name) { 52 | this.last_name = last_name; 53 | } 54 | 55 | public String getUser_id() { 56 | return user_id; 57 | } 58 | 59 | public void setUser_id(String user_id) { 60 | this.user_id = user_id; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "Contact{" + 66 | "phone_number='" + phone_number + '\'' + 67 | ", first_name='" + first_name + '\'' + 68 | ", last_name='" + last_name + '\'' + 69 | ", user_id='" + user_id + '\'' + 70 | '}'; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Document.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents a general file (as opposed to photos and audio files). 7 | */ 8 | public class Document { 9 | /** 10 | * Unique file identifier 11 | */ 12 | private String file_id; 13 | 14 | /** 15 | * Document thumbnail as defined by sender 16 | */ 17 | private PhotoSize thumb; 18 | 19 | /** 20 | * Optional. Original filename as defined by sender 21 | */ 22 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 23 | private String file_name; 24 | 25 | /** 26 | * Optional. MIME type of the file as defined by sender 27 | */ 28 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 29 | private String mime_type; 30 | 31 | /** 32 | * Optional. File size 33 | */ 34 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 35 | private Integer file_size; 36 | 37 | public String getFile_id() { 38 | return file_id; 39 | } 40 | 41 | public void setFile_id(String file_id) { 42 | this.file_id = file_id; 43 | } 44 | 45 | public PhotoSize getThumb() { 46 | return thumb; 47 | } 48 | 49 | public void setThumb(PhotoSize thumb) { 50 | this.thumb = thumb; 51 | } 52 | 53 | public String getFile_name() { 54 | return file_name; 55 | } 56 | 57 | public void setFile_name(String file_name) { 58 | this.file_name = file_name; 59 | } 60 | 61 | public String getMime_type() { 62 | return mime_type; 63 | } 64 | 65 | public void setMime_type(String mime_type) { 66 | this.mime_type = mime_type; 67 | } 68 | 69 | public Integer getFile_size() { 70 | return file_size; 71 | } 72 | 73 | public void setFile_size(Integer file_size) { 74 | this.file_size = file_size; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "Document{" + 80 | "file_id='" + file_id + '\'' + 81 | ", thumb=" + thumb + 82 | ", file_name='" + file_name + '\'' + 83 | ", mime_type='" + mime_type + '\'' + 84 | ", file_size=" + file_size + 85 | '}'; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/File.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import de.raysha.lib.telegram.bot.api.BotAPI; 4 | import org.codehaus.jackson.map.annotate.JsonSerialize; 5 | 6 | import java.net.MalformedURLException; 7 | import java.net.URL; 8 | 9 | /** 10 | * This object represents a file ready to be downloaded. 11 | * The file can be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>. 12 | * It is guaranteed that the link will be valid for at least 1 hour. When the link expires, 13 | * a new one can be requested by calling {@link BotAPI#getFile}. 14 | */ 15 | public class File { 16 | /** 17 | * Unique identifier for this file 18 | */ 19 | private String file_id; 20 | 21 | /** 22 | * Optional. File size, if known 23 | */ 24 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 25 | private Integer file_size; 26 | 27 | /** 28 | * Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file. 29 | */ 30 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 31 | private String file_path; 32 | 33 | public String getFile_id() { 34 | return file_id; 35 | } 36 | 37 | public void setFile_id(String file_id) { 38 | this.file_id = file_id; 39 | } 40 | 41 | public Integer getFile_size() { 42 | return file_size; 43 | } 44 | 45 | public void setFile_size(Integer file_size) { 46 | this.file_size = file_size; 47 | } 48 | 49 | public String getFile_path() { 50 | return file_path; 51 | } 52 | 53 | public void setFile_path(String file_path) { 54 | this.file_path = file_path; 55 | } 56 | 57 | public URL getDownloadUrl(String botToken){ 58 | try { 59 | return new URL("https://api.telegram.org/file/bot" + botToken + "/" + getFile_path()); 60 | } catch (MalformedURLException e) { 61 | throw new IllegalStateException("Could not create URL. This should never happen!"); 62 | } 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "File{" + 68 | "file_id='" + file_id + '\'' + 69 | ", file_size=" + file_size + 70 | ", file_path='" + file_path + '\'' + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/ForceReply.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * Upon receiving a message with this object, Telegram clients will display a reply interface to the user 7 | * (act as if the user has selected the bot's message and tapped 'Reply'). This can be extremely useful if 8 | * you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode. 9 | * 10 | * Example: A poll bot for groups runs in privacy mode (only receives commands, replies to its messages and mentions). 11 | * There could be two ways to create a new poll: 12 | * 13 | * Explain the user how to send a command with parameters (e.g. /newpoll question answer1 answer2). 14 | * May be appealing for hardcore users but lacks modern day polish. 15 | * Guide the user through a step-by-step process. 'Please send me your question', 'Cool, now let's add the first 16 | * answer option', 'Great. Keep adding answer options, then send /done when you're ready'. 17 | * 18 | * The last option is definitely more attractive. And if you use ForceReply in your bot's questions, 19 | * it will receive the user's answers even if it only receives replies, 20 | * commands and mentions -- without any extra work for the user. 21 | */ 22 | public class ForceReply { 23 | /** 24 | * Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply' 25 | */ 26 | private Boolean force_reply; 27 | 28 | /** 29 | * Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are 30 | * @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), 31 | * sender of the original message. 32 | */ 33 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 34 | private Boolean selective; 35 | 36 | public Boolean getForce_reply() { 37 | return force_reply; 38 | } 39 | 40 | public void setForce_reply(Boolean force_reply) { 41 | this.force_reply = force_reply; 42 | } 43 | 44 | public Boolean getSelective() { 45 | return selective; 46 | } 47 | 48 | public void setSelective(Boolean selective) { 49 | this.selective = selective; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "ForceReply{" + 55 | "force_reply=" + force_reply + 56 | ", selective=" + selective + 57 | '}'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/InlineQuery.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | /** 4 | * This object represents an incoming inline query. 5 | * When the user sends an empty query, your bot could return some default or trending results. 6 | */ 7 | public class InlineQuery { 8 | 9 | /** 10 | * Unique identifier for this query 11 | */ 12 | private String id; 13 | 14 | /** 15 | * Sender 16 | */ 17 | private User from; 18 | 19 | /** 20 | * Text of the query 21 | */ 22 | private String query; 23 | 24 | /** 25 | * Offset of the results to be returned, can be controlled by the bot 26 | */ 27 | private String offset; 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public void setId(String id) { 34 | this.id = id; 35 | } 36 | 37 | public User getFrom() { 38 | return from; 39 | } 40 | 41 | public void setFrom(User from) { 42 | this.from = from; 43 | } 44 | 45 | public String getQuery() { 46 | return query; 47 | } 48 | 49 | public void setQuery(String query) { 50 | this.query = query; 51 | } 52 | 53 | public String getOffset() { 54 | return offset; 55 | } 56 | 57 | public void setOffset(String offset) { 58 | this.offset = offset; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "InlineQuery{" + 64 | "id='" + id + '\'' + 65 | ", from=" + from + 66 | ", query='" + query + '\'' + 67 | ", offset='" + offset + '\'' + 68 | '}'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/InlineQueryResult.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import java.util.UUID; 4 | 5 | /** 6 | * This object represents one result of an inline query. 7 | * Telegram clients currently support results of the following 5 types: 8 | *
    9 | *
  • {@link InlineQueryResultArticle}
  • 10 | *
  • {@link InlineQueryResultPhoto}
  • 11 | *
  • {@link InlineQueryResultGif}
  • 12 | *
  • {@link InlineQueryResultMpeg4Gif}
  • 13 | *
  • {@link InlineQueryResultVideo}
  • 14 | *
15 | */ 16 | public abstract class InlineQueryResult { 17 | 18 | /** 19 | * Type of the result 20 | */ 21 | protected final String type; 22 | 23 | /** 24 | * Unique identifier for this result, 1-64 Bytes 25 | */ 26 | protected String id; 27 | 28 | public InlineQueryResult(String type) { 29 | this.type = type; 30 | this.id = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", ""); 31 | } 32 | 33 | public String getType() { 34 | return type; 35 | } 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String id) { 42 | this.id = id; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "InlineQueryResult{" + 48 | "type='" + type + '\'' + 49 | ", id='" + id + '\'' + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/InlineQueryResultArticle.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * Represents a link to an article or web page. 7 | */ 8 | public class InlineQueryResultArticle extends InlineQueryResult { 9 | 10 | /** 11 | * Title of the result 12 | */ 13 | private String title; 14 | 15 | /** 16 | * Text of the message to be sent 17 | */ 18 | private String message_text; 19 | 20 | /** 21 | * Optional. Send “Markdown”, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. 22 | */ 23 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 24 | private String parse_mode; 25 | 26 | /** 27 | * Optional. Disables link previews for links in the sent message 28 | */ 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | private Boolean disable_web_page_preview; 31 | 32 | /** 33 | * Optional. URL of the result 34 | */ 35 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 36 | private String url; 37 | 38 | /** 39 | * Optional. Pass True, if you don't want the URL to be shown in the message 40 | */ 41 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 42 | private Boolean hide_url; 43 | 44 | /** 45 | * Optional. Short description of the result 46 | */ 47 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 48 | private String description; 49 | 50 | /** 51 | * Optional. Url of the thumbnail for the result 52 | */ 53 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 54 | private String thumb_url; 55 | 56 | /** 57 | * Optional. Thumbnail width 58 | */ 59 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 60 | private Integer thumb_width; 61 | 62 | /** 63 | * Optional. Thumbnail height 64 | */ 65 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 66 | private Integer thumb_height; 67 | 68 | public InlineQueryResultArticle() { 69 | super("article"); 70 | } 71 | 72 | /** 73 | * 74 | * @param title Title of the result 75 | * @param message_text Text of the message to be sent 76 | */ 77 | public InlineQueryResultArticle(String title, String message_text) { 78 | this(); 79 | this.title = title; 80 | this.message_text = message_text; 81 | } 82 | 83 | /** 84 | * 85 | * @param title Title of the result 86 | * @param message_text Text of the message to be sent 87 | * @param parse_mode Optional. Send “Markdown”, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. 88 | * @param disable_web_page_preview Optional. Disables link previews for links in the sent message 89 | * @param url Optional. URL of the result 90 | * @param hide_url Optional. Pass True, if you don't want the URL to be shown in the message 91 | * @param description Optional. Short description of the result 92 | * @param thumb_url Optional. Url of the thumbnail for the result 93 | * @param thumb_width Optional. Thumbnail width 94 | * @param thumb_height Optional. Thumbnail height 95 | */ 96 | public InlineQueryResultArticle(String title, String message_text, String parse_mode, 97 | Boolean disable_web_page_preview, String url, Boolean hide_url, String description, 98 | String thumb_url, Integer thumb_width, Integer thumb_height) { 99 | this(); 100 | this.title = title; 101 | this.message_text = message_text; 102 | this.parse_mode = parse_mode; 103 | this.disable_web_page_preview = disable_web_page_preview; 104 | this.url = url; 105 | this.hide_url = hide_url; 106 | this.description = description; 107 | this.thumb_url = thumb_url; 108 | this.thumb_width = thumb_width; 109 | this.thumb_height = thumb_height; 110 | } 111 | 112 | public String getTitle() { 113 | return title; 114 | } 115 | 116 | public void setTitle(String title) { 117 | this.title = title; 118 | } 119 | 120 | public String getMessage_text() { 121 | return message_text; 122 | } 123 | 124 | public void setMessage_text(String message_text) { 125 | this.message_text = message_text; 126 | } 127 | 128 | public String getParse_mode() { 129 | return parse_mode; 130 | } 131 | 132 | public void setParse_mode(String parse_mode) { 133 | this.parse_mode = parse_mode; 134 | } 135 | 136 | public Boolean getDisable_web_page_preview() { 137 | return disable_web_page_preview; 138 | } 139 | 140 | public void setDisable_web_page_preview(Boolean disable_web_page_preview) { 141 | this.disable_web_page_preview = disable_web_page_preview; 142 | } 143 | 144 | public String getUrl() { 145 | return url; 146 | } 147 | 148 | public void setUrl(String url) { 149 | this.url = url; 150 | } 151 | 152 | public Boolean getHide_url() { 153 | return hide_url; 154 | } 155 | 156 | public void setHide_url(Boolean hide_url) { 157 | this.hide_url = hide_url; 158 | } 159 | 160 | public String getDescription() { 161 | return description; 162 | } 163 | 164 | public void setDescription(String description) { 165 | this.description = description; 166 | } 167 | 168 | public String getThumb_url() { 169 | return thumb_url; 170 | } 171 | 172 | public void setThumb_url(String thumb_url) { 173 | this.thumb_url = thumb_url; 174 | } 175 | 176 | public Integer getThumb_width() { 177 | return thumb_width; 178 | } 179 | 180 | public void setThumb_width(Integer thumb_width) { 181 | this.thumb_width = thumb_width; 182 | } 183 | 184 | public Integer getThumb_height() { 185 | return thumb_height; 186 | } 187 | 188 | public void setThumb_height(Integer thumb_height) { 189 | this.thumb_height = thumb_height; 190 | } 191 | 192 | @Override 193 | public String toString() { 194 | return "InlineQueryResultArticle{" + 195 | "title='" + title + '\'' + 196 | ", message_text='" + message_text + '\'' + 197 | ", parse_mode='" + parse_mode + '\'' + 198 | ", disable_web_page_preview=" + disable_web_page_preview + 199 | ", url='" + url + '\'' + 200 | ", hide_url=" + hide_url + 201 | ", description='" + description + '\'' + 202 | ", thumb_url='" + thumb_url + '\'' + 203 | ", thumb_width=" + thumb_width + 204 | ", thumb_height=" + thumb_height + 205 | "} " + super.toString(); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/InlineQueryResultGif.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional 7 | * caption. Alternatively, you can provide message_text to send it instead of the animation. 8 | */ 9 | public class InlineQueryResultGif extends InlineQueryResult { 10 | 11 | /** 12 | * A valid URL for the GIF file. File size must not exceed 1MB 13 | */ 14 | private String gif_url; 15 | 16 | /** 17 | * Optional. Width of the GIF 18 | */ 19 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 20 | private Integer gif_width; 21 | 22 | /** 23 | * Optional. Height of the GIF 24 | */ 25 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 26 | private Integer gif_height; 27 | 28 | /** 29 | * URL of the static thumbnail for the result (jpeg or gif) 30 | */ 31 | private String thumb_url; 32 | 33 | /** 34 | * Optional. Title for the result 35 | */ 36 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 37 | private String title; 38 | 39 | /** 40 | * Optional. Caption of the GIF file to be sent, 0-200 characters 41 | */ 42 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 43 | private String caption; 44 | 45 | /** 46 | * Optional. Text of a message to be sent instead of the animation, 1-512 characters 47 | */ 48 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 49 | private String message_text; 50 | 51 | /** 52 | * Optional. Send “Markdown”, if you want Telegram apps to show 53 | * bold, italic and inline URLs in your bot's message. 54 | */ 55 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 56 | private String parse_mode; 57 | 58 | /** 59 | * Optional. Disables link previews for links in the sent message 60 | */ 61 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 62 | private Boolean disable_web_page_preview; 63 | 64 | public InlineQueryResultGif() { 65 | super("gif"); 66 | } 67 | 68 | /** 69 | * 70 | * @param gif_url A valid URL for the GIF file. File size must not exceed 1MB 71 | * @param thumb_url URL of the static thumbnail for the result (jpeg or gif) 72 | */ 73 | public InlineQueryResultGif(String gif_url, String thumb_url) { 74 | this(); 75 | this.gif_url = gif_url; 76 | this.thumb_url = thumb_url; 77 | } 78 | 79 | /** 80 | * 81 | * @param gif_url A valid URL for the GIF file. File size must not exceed 1MB 82 | * @param thumb_url URL of the static thumbnail for the result (jpeg or gif) 83 | * @param gif_width Optional. Width of the GIF 84 | * @param gif_height Optional. Height of the GIF 85 | * @param title Optional. Title for the result 86 | * @param caption Optional. Caption of the GIF file to be sent, 0-200 characters 87 | * @param message_text Optional. Text of a message to be sent instead of the animation, 1-512 characters 88 | * @param parse_mode Optional. Send “Markdown”, if you want Telegram apps to show 89 | * bold, italic and inline URLs 90 | * in your bot's message. 91 | * @param disable_web_page_preview Optional. Disables link previews for links in the sent message 92 | */ 93 | public InlineQueryResultGif(String gif_url, String thumb_url, Integer gif_width, Integer gif_height, String title, 94 | String caption, String message_text, String parse_mode, Boolean disable_web_page_preview) { 95 | this(); 96 | this.gif_url = gif_url; 97 | this.gif_width = gif_width; 98 | this.gif_height = gif_height; 99 | this.thumb_url = thumb_url; 100 | this.title = title; 101 | this.caption = caption; 102 | this.message_text = message_text; 103 | this.parse_mode = parse_mode; 104 | this.disable_web_page_preview = disable_web_page_preview; 105 | } 106 | 107 | public String getGif_url() { 108 | return gif_url; 109 | } 110 | 111 | public void setGif_url(String gif_url) { 112 | this.gif_url = gif_url; 113 | } 114 | 115 | public Integer getGif_width() { 116 | return gif_width; 117 | } 118 | 119 | public void setGif_width(Integer gif_width) { 120 | this.gif_width = gif_width; 121 | } 122 | 123 | public Integer getGif_height() { 124 | return gif_height; 125 | } 126 | 127 | public void setGif_height(Integer gif_height) { 128 | this.gif_height = gif_height; 129 | } 130 | 131 | public String getThumb_url() { 132 | return thumb_url; 133 | } 134 | 135 | public void setThumb_url(String thumb_url) { 136 | this.thumb_url = thumb_url; 137 | } 138 | 139 | public String getTitle() { 140 | return title; 141 | } 142 | 143 | public void setTitle(String title) { 144 | this.title = title; 145 | } 146 | 147 | public String getCaption() { 148 | return caption; 149 | } 150 | 151 | public void setCaption(String caption) { 152 | this.caption = caption; 153 | } 154 | 155 | public String getMessage_text() { 156 | return message_text; 157 | } 158 | 159 | public void setMessage_text(String message_text) { 160 | this.message_text = message_text; 161 | } 162 | 163 | public String getParse_mode() { 164 | return parse_mode; 165 | } 166 | 167 | public void setParse_mode(String parse_mode) { 168 | this.parse_mode = parse_mode; 169 | } 170 | 171 | public Boolean getDisable_web_page_preview() { 172 | return disable_web_page_preview; 173 | } 174 | 175 | public void setDisable_web_page_preview(Boolean disable_web_page_preview) { 176 | this.disable_web_page_preview = disable_web_page_preview; 177 | } 178 | 179 | @Override 180 | public String toString() { 181 | return "InlineQueryResultGif{" + 182 | "gif_url='" + gif_url + '\'' + 183 | ", gif_width=" + gif_width + 184 | ", gif_height=" + gif_height + 185 | ", thumb_url='" + thumb_url + '\'' + 186 | ", title='" + title + '\'' + 187 | ", caption='" + caption + '\'' + 188 | ", message_text='" + message_text + '\'' + 189 | ", parse_mode='" + parse_mode + '\'' + 190 | ", disable_web_page_preview=" + disable_web_page_preview + 191 | "} " + super.toString(); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/InlineQueryResultMpeg4Gif.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, 7 | * this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, 8 | * you can provide message_text to send it instead of the animation. 9 | */ 10 | public class InlineQueryResultMpeg4Gif extends InlineQueryResult { 11 | 12 | /** 13 | * A valid URL for the MP4 file. File size must not exceed 1MB 14 | */ 15 | private String mpeg4_url; 16 | 17 | /** 18 | * Optional. Video width 19 | */ 20 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 21 | private Integer mpeg4_width; 22 | 23 | /** 24 | * Optional. Video height 25 | */ 26 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 27 | private Integer mpeg4_height; 28 | 29 | /** 30 | * URL of the static thumbnail (jpeg or gif) for the result 31 | */ 32 | private String thumb_url; 33 | 34 | /** 35 | * Optional. Title for the result 36 | */ 37 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 38 | private String title; 39 | 40 | /** 41 | * Optional. Caption of the MPEG-4 file to be sent, 0-200 characters 42 | */ 43 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 44 | private String caption; 45 | 46 | /** 47 | * Optional. Text of a message to be sent instead of the animation, 1-512 characters 48 | */ 49 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 50 | private String message_text; 51 | 52 | /** 53 | * Optional. Send “Markdown”, if you want Telegram apps to show 54 | * bold, italic and inline URLs in your bot's message. 55 | */ 56 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 57 | private String parse_mode; 58 | 59 | /** 60 | * Optional. Disables link previews for links in the sent message 61 | */ 62 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 63 | private Boolean disable_web_page_preview; 64 | 65 | public InlineQueryResultMpeg4Gif() { 66 | super("mpeg4_gif"); 67 | } 68 | 69 | /** 70 | * 71 | * @param mpeg4_url A valid URL for the MP4 file. File size must not exceed 1MB 72 | * @param thumb_url URL of the static thumbnail (jpeg or gif) for the result 73 | */ 74 | public InlineQueryResultMpeg4Gif(String mpeg4_url, String thumb_url) { 75 | this(); 76 | this.mpeg4_url = mpeg4_url; 77 | this.thumb_url = thumb_url; 78 | } 79 | 80 | /** 81 | * 82 | * @param mpeg4_url A valid URL for the MP4 file. File size must not exceed 1MB 83 | * @param thumb_url URL of the static thumbnail (jpeg or gif) for the result 84 | * @param mpeg4_width Optional. Video width 85 | * @param mpeg4_height Optional. Video height 86 | * @param title Optional. Title for the result 87 | * @param caption Optional. Caption of the MPEG-4 file to be sent, 0-200 characters 88 | * @param message_text Optional. Text of a message to be sent instead of the animation, 1-512 characters 89 | * @param parse_mode Optional. Send “Markdown”, if you want Telegram apps to show 90 | * bold, italic and inline URLs 91 | * in your bot's message. 92 | * @param disable_web_page_preview Optional. Disables link previews for links in the sent message 93 | */ 94 | public InlineQueryResultMpeg4Gif(String mpeg4_url, String thumb_url, Integer mpeg4_width, Integer mpeg4_height, 95 | String title, String caption, String message_text, String parse_mode, 96 | Boolean disable_web_page_preview) { 97 | this(); 98 | this.mpeg4_url = mpeg4_url; 99 | this.mpeg4_width = mpeg4_width; 100 | this.mpeg4_height = mpeg4_height; 101 | this.thumb_url = thumb_url; 102 | this.title = title; 103 | this.caption = caption; 104 | this.message_text = message_text; 105 | this.parse_mode = parse_mode; 106 | this.disable_web_page_preview = disable_web_page_preview; 107 | } 108 | 109 | public String getMpeg4_url() { 110 | return mpeg4_url; 111 | } 112 | 113 | public void setMpeg4_url(String mpeg4_url) { 114 | this.mpeg4_url = mpeg4_url; 115 | } 116 | 117 | public Integer getMpeg4_width() { 118 | return mpeg4_width; 119 | } 120 | 121 | public void setMpeg4_width(Integer mpeg4_width) { 122 | this.mpeg4_width = mpeg4_width; 123 | } 124 | 125 | public Integer getMpeg4_height() { 126 | return mpeg4_height; 127 | } 128 | 129 | public void setMpeg4_height(Integer mpeg4_height) { 130 | this.mpeg4_height = mpeg4_height; 131 | } 132 | 133 | public String getThumb_url() { 134 | return thumb_url; 135 | } 136 | 137 | public void setThumb_url(String thumb_url) { 138 | this.thumb_url = thumb_url; 139 | } 140 | 141 | public String getTitle() { 142 | return title; 143 | } 144 | 145 | public void setTitle(String title) { 146 | this.title = title; 147 | } 148 | 149 | public String getCaption() { 150 | return caption; 151 | } 152 | 153 | public void setCaption(String caption) { 154 | this.caption = caption; 155 | } 156 | 157 | public String getMessage_text() { 158 | return message_text; 159 | } 160 | 161 | public void setMessage_text(String message_text) { 162 | this.message_text = message_text; 163 | } 164 | 165 | public String getParse_mode() { 166 | return parse_mode; 167 | } 168 | 169 | public void setParse_mode(String parse_mode) { 170 | this.parse_mode = parse_mode; 171 | } 172 | 173 | public Boolean getDisable_web_page_preview() { 174 | return disable_web_page_preview; 175 | } 176 | 177 | public void setDisable_web_page_preview(Boolean disable_web_page_preview) { 178 | this.disable_web_page_preview = disable_web_page_preview; 179 | } 180 | 181 | @Override 182 | public String toString() { 183 | return "InlineQueryResultMpeg4Gif{" + 184 | "mpeg4_url='" + mpeg4_url + '\'' + 185 | ", mpeg4_width=" + mpeg4_width + 186 | ", mpeg4_height=" + mpeg4_height + 187 | ", thumb_url='" + thumb_url + '\'' + 188 | ", title='" + title + '\'' + 189 | ", caption='" + caption + '\'' + 190 | ", message_text='" + message_text + '\'' + 191 | ", parse_mode='" + parse_mode + '\'' + 192 | ", disable_web_page_preview=" + disable_web_page_preview + 193 | "} " + super.toString(); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/InlineQueryResultPhoto.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * Represents a link to a photo. 7 | * By default, this photo will be sent by the user with optional caption. 8 | * Alternatively, you can provide message_text to send it instead of photo. 9 | */ 10 | public class InlineQueryResultPhoto extends InlineQueryResult { 11 | 12 | /** 13 | * A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB 14 | */ 15 | private String photo_url; 16 | 17 | /** 18 | * Optional. Width of the photo 19 | */ 20 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 21 | private Integer photo_width; 22 | 23 | /** 24 | * Optional. Height of the photo 25 | */ 26 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 27 | private Integer photo_height; 28 | 29 | /** 30 | * URL of the thumbnail for the photo 31 | */ 32 | private String thumb_url; 33 | 34 | /** 35 | * Optional. Title for the result 36 | */ 37 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 38 | private String title; 39 | 40 | /** 41 | * Optional. Short description of the result 42 | */ 43 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 44 | private String description; 45 | 46 | /** 47 | * Optional. Caption of the photo to be sent, 0-200 characters 48 | */ 49 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 50 | private String caption; 51 | 52 | /** 53 | * Optional. Text of a message to be sent instead of the photo, 1-512 characters 54 | */ 55 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 56 | private String message_text; 57 | 58 | /** 59 | * Optional. Send “Markdown”, if you want Telegram apps to show 60 | * bold, italic and inline URLs 61 | * in your bot's message. 62 | */ 63 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 64 | private String parse_mode; 65 | 66 | public InlineQueryResultPhoto() { 67 | super("photo"); 68 | } 69 | 70 | /** 71 | * 72 | * @param photo_url A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB 73 | * @param thumb_url URL of the thumbnail for the photo 74 | */ 75 | public InlineQueryResultPhoto(String photo_url, String thumb_url) { 76 | this(); 77 | this.photo_url = photo_url; 78 | this.thumb_url = thumb_url; 79 | } 80 | 81 | /** 82 | * 83 | * @param photo_url A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB 84 | * @param thumb_url URL of the thumbnail for the photo 85 | * @param photo_width Optional. Width of the photo 86 | * @param photo_height Optional. Height of the photo 87 | * @param title Optional. Title for the result 88 | * @param description Optional. Short description of the result 89 | * @param caption Optional. Caption of the photo to be sent, 0-200 characters 90 | * @param message_text Optional. Text of a message to be sent instead of the photo, 1-512 characters 91 | * @param parse_mode Optional. Send “Markdown”, if you want Telegram apps to show 92 | * bold, italic and inline URLs 93 | * in your bot's message. 94 | */ 95 | public InlineQueryResultPhoto(String photo_url, String thumb_url, Integer photo_width, Integer photo_height, 96 | String title, String description, String caption, String message_text, 97 | String parse_mode) { 98 | this(); 99 | this.photo_url = photo_url; 100 | this.photo_width = photo_width; 101 | this.photo_height = photo_height; 102 | this.thumb_url = thumb_url; 103 | this.title = title; 104 | this.description = description; 105 | this.caption = caption; 106 | this.message_text = message_text; 107 | this.parse_mode = parse_mode; 108 | } 109 | 110 | public String getPhoto_url() { 111 | return photo_url; 112 | } 113 | 114 | public void setPhoto_url(String photo_url) { 115 | this.photo_url = photo_url; 116 | } 117 | 118 | public Integer getPhoto_width() { 119 | return photo_width; 120 | } 121 | 122 | public void setPhoto_width(Integer photo_width) { 123 | this.photo_width = photo_width; 124 | } 125 | 126 | public Integer getPhoto_height() { 127 | return photo_height; 128 | } 129 | 130 | public void setPhoto_height(Integer photo_height) { 131 | this.photo_height = photo_height; 132 | } 133 | 134 | public String getThumb_url() { 135 | return thumb_url; 136 | } 137 | 138 | public void setThumb_url(String thumb_url) { 139 | this.thumb_url = thumb_url; 140 | } 141 | 142 | public String getTitle() { 143 | return title; 144 | } 145 | 146 | public void setTitle(String title) { 147 | this.title = title; 148 | } 149 | 150 | public String getDescription() { 151 | return description; 152 | } 153 | 154 | public void setDescription(String description) { 155 | this.description = description; 156 | } 157 | 158 | public String getCaption() { 159 | return caption; 160 | } 161 | 162 | public void setCaption(String caption) { 163 | this.caption = caption; 164 | } 165 | 166 | public String getMessage_text() { 167 | return message_text; 168 | } 169 | 170 | public void setMessage_text(String message_text) { 171 | this.message_text = message_text; 172 | } 173 | 174 | public String getParse_mode() { 175 | return parse_mode; 176 | } 177 | 178 | public void setParse_mode(String parse_mode) { 179 | this.parse_mode = parse_mode; 180 | } 181 | 182 | @Override 183 | public String toString() { 184 | return "InlineQueryResultPhoto{" + 185 | "photo_url='" + photo_url + '\'' + 186 | ", photo_width=" + photo_width + 187 | ", photo_height=" + photo_height + 188 | ", thumb_url='" + thumb_url + '\'' + 189 | ", title='" + title + '\'' + 190 | ", description='" + description + '\'' + 191 | ", caption='" + caption + '\'' + 192 | ", message_text='" + message_text + '\'' + 193 | ", parse_mode='" + parse_mode + '\'' + 194 | "} " + super.toString(); 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/InlineQueryResultVideo.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * Represents link to a page containing an embedded video player or a video file. 7 | */ 8 | public class InlineQueryResultVideo extends InlineQueryResult { 9 | 10 | /** 11 | * A valid URL for the embedded video player or video file 12 | */ 13 | private String video_url; 14 | 15 | /** 16 | * Mime type of the content of video url, “text/html” or “video/mp4” 17 | */ 18 | private String mime_type; 19 | 20 | /** 21 | * Text of the message to be sent with the video, 1-512 characters 22 | */ 23 | private String message_text; 24 | 25 | /** 26 | * Optional. Send “Markdown”, if you want Telegram apps to show 27 | * bold, italic and inline URLs in your bot's message. 28 | */ 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | private String parse_mode; 31 | 32 | /** 33 | * Optional. Disables link previews for links in the sent message 34 | */ 35 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 36 | private Boolean disable_web_page_preview; 37 | 38 | /** 39 | * Optional. Video width 40 | */ 41 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 42 | private Integer video_width; 43 | 44 | /** 45 | * Optional. Video height 46 | */ 47 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 48 | private Integer video_height; 49 | 50 | /** 51 | * Optional. Video duration in seconds 52 | */ 53 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 54 | private Integer video_duration; 55 | 56 | /** 57 | * URL of the thumbnail (jpeg only) for the video 58 | */ 59 | private String thumb_url; 60 | 61 | /** 62 | * Title for the result 63 | */ 64 | private String title; 65 | 66 | /** 67 | * Optional. Short description of the result 68 | */ 69 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 70 | private String description; 71 | 72 | public InlineQueryResultVideo() { 73 | super("video"); 74 | } 75 | 76 | /** 77 | * 78 | * @param video_url A valid URL for the embedded video player or video file 79 | * @param mime_type Mime type of the content of video url, “text/html” or “video/mp4” 80 | * @param message_text Text of the message to be sent with the video, 1-512 characters 81 | * @param thumb_url URL of the thumbnail (jpeg only) for the video 82 | * @param title Title for the result 83 | */ 84 | public InlineQueryResultVideo(String video_url, String mime_type, String message_text, String thumb_url, String title) { 85 | this(); 86 | this.video_url = video_url; 87 | this.mime_type = mime_type; 88 | this.message_text = message_text; 89 | this.thumb_url = thumb_url; 90 | this.title = title; 91 | } 92 | 93 | /** 94 | * 95 | * @param video_url A valid URL for the embedded video player or video file 96 | * @param mime_type Mime type of the content of video url, “text/html” or “video/mp4” 97 | * @param message_text Text of the message to be sent with the video, 1-512 characters 98 | * @param parse_mode Optional. Send “Markdown”, if you want Telegram apps to show 99 | * bold, italic and inline URLs 100 | * in your bot's message. 101 | * @param disable_web_page_preview Optional. Disables link previews for links in the sent message 102 | * @param video_width Optional. Video width 103 | * @param video_height Optional. Video height 104 | * @param video_duration Optional. Video duration in seconds 105 | * @param thumb_url URL of the thumbnail (jpeg only) for the video 106 | * @param title Title for the result 107 | * @param description Optional. Short description of the result 108 | */ 109 | public InlineQueryResultVideo(String video_url, String mime_type, String message_text, String parse_mode, 110 | Boolean disable_web_page_preview, Integer video_width, Integer video_height, 111 | Integer video_duration, String thumb_url, String title, String description) { 112 | this(); 113 | this.video_url = video_url; 114 | this.mime_type = mime_type; 115 | this.message_text = message_text; 116 | this.parse_mode = parse_mode; 117 | this.disable_web_page_preview = disable_web_page_preview; 118 | this.video_width = video_width; 119 | this.video_height = video_height; 120 | this.video_duration = video_duration; 121 | this.thumb_url = thumb_url; 122 | this.title = title; 123 | this.description = description; 124 | } 125 | 126 | public String getVideo_url() { 127 | return video_url; 128 | } 129 | 130 | public void setVideo_url(String video_url) { 131 | this.video_url = video_url; 132 | } 133 | 134 | public String getMime_type() { 135 | return mime_type; 136 | } 137 | 138 | public void setMime_type(String mime_type) { 139 | this.mime_type = mime_type; 140 | } 141 | 142 | public String getMessage_text() { 143 | return message_text; 144 | } 145 | 146 | public void setMessage_text(String message_text) { 147 | this.message_text = message_text; 148 | } 149 | 150 | public String getParse_mode() { 151 | return parse_mode; 152 | } 153 | 154 | public void setParse_mode(String parse_mode) { 155 | this.parse_mode = parse_mode; 156 | } 157 | 158 | public Boolean getDisable_web_page_preview() { 159 | return disable_web_page_preview; 160 | } 161 | 162 | public void setDisable_web_page_preview(Boolean disable_web_page_preview) { 163 | this.disable_web_page_preview = disable_web_page_preview; 164 | } 165 | 166 | public Integer getVideo_width() { 167 | return video_width; 168 | } 169 | 170 | public void setVideo_width(Integer video_width) { 171 | this.video_width = video_width; 172 | } 173 | 174 | public Integer getVideo_height() { 175 | return video_height; 176 | } 177 | 178 | public void setVideo_height(Integer video_height) { 179 | this.video_height = video_height; 180 | } 181 | 182 | public Integer getVideo_duration() { 183 | return video_duration; 184 | } 185 | 186 | public void setVideo_duration(Integer video_duration) { 187 | this.video_duration = video_duration; 188 | } 189 | 190 | public String getThumb_url() { 191 | return thumb_url; 192 | } 193 | 194 | public void setThumb_url(String thumb_url) { 195 | this.thumb_url = thumb_url; 196 | } 197 | 198 | public String getTitle() { 199 | return title; 200 | } 201 | 202 | public void setTitle(String title) { 203 | this.title = title; 204 | } 205 | 206 | public String getDescription() { 207 | return description; 208 | } 209 | 210 | public void setDescription(String description) { 211 | this.description = description; 212 | } 213 | 214 | @Override 215 | public String toString() { 216 | return "InlineQueryResultVideo{" + 217 | "video_url='" + video_url + '\'' + 218 | ", mime_type='" + mime_type + '\'' + 219 | ", message_text='" + message_text + '\'' + 220 | ", parse_mode='" + parse_mode + '\'' + 221 | ", disable_web_page_preview=" + disable_web_page_preview + 222 | ", video_width=" + video_width + 223 | ", video_height=" + video_height + 224 | ", video_duration=" + video_duration + 225 | ", thumb_url='" + thumb_url + '\'' + 226 | ", title='" + title + '\'' + 227 | ", description='" + description + '\'' + 228 | "} " + super.toString(); 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Location.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | /** 4 | * This object represents a point on the map. 5 | */ 6 | public class Location { 7 | /** 8 | * Longitude as defined by sender 9 | */ 10 | private Float longitude; 11 | 12 | /** 13 | * Latitude as defined by sender 14 | */ 15 | private Float latitude; 16 | 17 | public Float getLongitude() { 18 | return longitude; 19 | } 20 | 21 | public void setLongitude(Float longitude) { 22 | this.longitude = longitude; 23 | } 24 | 25 | public Float getLatitude() { 26 | return latitude; 27 | } 28 | 29 | public void setLatitude(Float latitude) { 30 | this.latitude = latitude; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Location{" + 36 | "longitude=" + longitude + 37 | ", latitude=" + latitude + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Message.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * This object represents a message. 9 | */ 10 | public class Message { 11 | /** 12 | * Unique message identifier 13 | */ 14 | private Integer message_id; 15 | 16 | /** 17 | * Sender 18 | */ 19 | private User from; 20 | 21 | /** 22 | * Date the message was sent in Unix time 23 | */ 24 | private Integer date; 25 | 26 | /** 27 | * Conversation the message belongs to 28 | */ 29 | private Chat chat; 30 | 31 | /** 32 | * Optional. For forwarded messages, sender of the original message 33 | */ 34 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 35 | private User forward_from; 36 | 37 | /** 38 | * Optional. For forwarded messages, date the original message was sent in Unix time 39 | */ 40 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 41 | private Integer forward_date; 42 | 43 | /** 44 | * Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. 45 | */ 46 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 47 | private Message reply_to_message; 48 | 49 | /** 50 | * Optional. For text messages, the actual UTF-8 text of the message 51 | */ 52 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 53 | private String text; 54 | 55 | /** 56 | * Optional. Message is an audio file, information about the file 57 | */ 58 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 59 | private Audio audio; 60 | 61 | /** 62 | * Optional. Message is a general file, information about the file 63 | */ 64 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 65 | private Document document; 66 | 67 | /** 68 | * Optional. Message is a photo, available sizes of the photo 69 | */ 70 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 71 | private List photo; 72 | 73 | /** 74 | * Optional. Message is a sticker, information about the sticker 75 | */ 76 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 77 | private Sticker sticker; 78 | 79 | /** 80 | * Optional. Message is a video, information about the video 81 | */ 82 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 83 | private Video video; 84 | 85 | /** 86 | * Optional. Message is a voice message, information about the file 87 | */ 88 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 89 | private Voice voice; 90 | 91 | /** 92 | * Optional. Caption for the photo or video 93 | */ 94 | private String caption; 95 | 96 | /** 97 | * Optional. Message is a shared contact, information about the contact 98 | */ 99 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 100 | private Contact contact; 101 | 102 | /** 103 | * Optional. Message is a shared location, information about the location 104 | */ 105 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 106 | private Location location; 107 | 108 | /** 109 | * Optional. A new member was added to the group, information about them (this member may be bot itself) 110 | */ 111 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 112 | private User new_chat_participant; 113 | 114 | /** 115 | * Optional. A member was removed from the group, information about them (this member may be bot itself) 116 | */ 117 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 118 | private User left_chat_participant; 119 | 120 | /** 121 | * Optional. A group title was changed to this value 122 | */ 123 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 124 | private String new_chat_title; 125 | 126 | /** 127 | * Optional. A group photo was change to this value 128 | */ 129 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 130 | private List new_chat_photo; 131 | 132 | /** 133 | * Optional. Informs that the group photo was deleted 134 | */ 135 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 136 | private Boolean delete_chat_photo; 137 | 138 | /** 139 | * Optional. Informs that the group has been created 140 | */ 141 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 142 | private Boolean group_chat_created; 143 | 144 | /** 145 | * Optional. Service message: the supergroup has been created 146 | */ 147 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 148 | private Boolean supergroup_chat_created; 149 | 150 | /** 151 | * Optional. Service message: the channel has been created 152 | */ 153 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 154 | private Boolean channel_chat_created; 155 | 156 | /** 157 | * Optional. The group has been migrated to a supergroup with the specified identifier, not exceeding 1e13 by absolute value 158 | */ 159 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 160 | private Integer migrate_to_chat_id; 161 | 162 | /** 163 | * Optional. The supergroup has been migrated from a group with the specified identifier, not exceeding 1e13 by absolute value 164 | */ 165 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 166 | private Integer migrate_from_chat_id; 167 | 168 | public Integer getMessage_id() { 169 | return message_id; 170 | } 171 | 172 | public void setMessage_id(Integer message_id) { 173 | this.message_id = message_id; 174 | } 175 | 176 | public User getFrom() { 177 | return from; 178 | } 179 | 180 | public void setFrom(User from) { 181 | this.from = from; 182 | } 183 | 184 | public Integer getDate() { 185 | return date; 186 | } 187 | 188 | public void setDate(Integer date) { 189 | this.date = date; 190 | } 191 | 192 | public Chat getChat() { 193 | return chat; 194 | } 195 | 196 | public void setChat(Chat chat) { 197 | this.chat = chat; 198 | } 199 | 200 | public User getForward_from() { 201 | return forward_from; 202 | } 203 | 204 | public void setForward_from(User forward_from) { 205 | this.forward_from = forward_from; 206 | } 207 | 208 | public Integer getForward_date() { 209 | return forward_date; 210 | } 211 | 212 | public void setForward_date(Integer forward_date) { 213 | this.forward_date = forward_date; 214 | } 215 | 216 | public Message getReply_to_message() { 217 | return reply_to_message; 218 | } 219 | 220 | public void setReply_to_message(Message reply_to_message) { 221 | this.reply_to_message = reply_to_message; 222 | } 223 | 224 | public String getText() { 225 | return text; 226 | } 227 | 228 | public void setText(String text) { 229 | this.text = text; 230 | } 231 | 232 | public Audio getAudio() { 233 | return audio; 234 | } 235 | 236 | public void setAudio(Audio audio) { 237 | this.audio = audio; 238 | } 239 | 240 | public Document getDocument() { 241 | return document; 242 | } 243 | 244 | public void setDocument(Document document) { 245 | this.document = document; 246 | } 247 | 248 | public List getPhoto() { 249 | return photo; 250 | } 251 | 252 | public void setPhoto(List photo) { 253 | this.photo = photo; 254 | } 255 | 256 | public Sticker getSticker() { 257 | return sticker; 258 | } 259 | 260 | public void setSticker(Sticker sticker) { 261 | this.sticker = sticker; 262 | } 263 | 264 | public Video getVideo() { 265 | return video; 266 | } 267 | 268 | public void setVideo(Video video) { 269 | this.video = video; 270 | } 271 | 272 | public Contact getContact() { 273 | return contact; 274 | } 275 | 276 | public void setContact(Contact contact) { 277 | this.contact = contact; 278 | } 279 | 280 | public Location getLocation() { 281 | return location; 282 | } 283 | 284 | public void setLocation(Location location) { 285 | this.location = location; 286 | } 287 | 288 | public User getNew_chat_participant() { 289 | return new_chat_participant; 290 | } 291 | 292 | public void setNew_chat_participant(User new_chat_participant) { 293 | this.new_chat_participant = new_chat_participant; 294 | } 295 | 296 | public User getLeft_chat_participant() { 297 | return left_chat_participant; 298 | } 299 | 300 | public void setLeft_chat_participant(User left_chat_participant) { 301 | this.left_chat_participant = left_chat_participant; 302 | } 303 | 304 | public String getNew_chat_title() { 305 | return new_chat_title; 306 | } 307 | 308 | public void setNew_chat_title(String new_chat_title) { 309 | this.new_chat_title = new_chat_title; 310 | } 311 | 312 | public List getNew_chat_photo() { 313 | return new_chat_photo; 314 | } 315 | 316 | public void setNew_chat_photo(List new_chat_photo) { 317 | this.new_chat_photo = new_chat_photo; 318 | } 319 | 320 | public Boolean getDelete_chat_photo() { 321 | return delete_chat_photo; 322 | } 323 | 324 | public void setDelete_chat_photo(Boolean delete_chat_photo) { 325 | this.delete_chat_photo = delete_chat_photo; 326 | } 327 | 328 | public Boolean getGroup_chat_created() { 329 | return group_chat_created; 330 | } 331 | 332 | public void setGroup_chat_created(Boolean group_chat_created) { 333 | this.group_chat_created = group_chat_created; 334 | } 335 | 336 | public Voice getVoice() { 337 | return voice; 338 | } 339 | 340 | public void setVoice(Voice voice) { 341 | this.voice = voice; 342 | } 343 | 344 | public String getCaption() { 345 | return caption; 346 | } 347 | 348 | public void setCaption(String caption) { 349 | this.caption = caption; 350 | } 351 | 352 | public Boolean getSupergroup_chat_created() { 353 | return supergroup_chat_created; 354 | } 355 | 356 | public void setSupergroup_chat_created(Boolean supergroup_chat_created) { 357 | this.supergroup_chat_created = supergroup_chat_created; 358 | } 359 | 360 | public Boolean getChannel_chat_created() { 361 | return channel_chat_created; 362 | } 363 | 364 | public void setChannel_chat_created(Boolean channel_chat_created) { 365 | this.channel_chat_created = channel_chat_created; 366 | } 367 | 368 | public Integer getMigrate_to_chat_id() { 369 | return migrate_to_chat_id; 370 | } 371 | 372 | public void setMigrate_to_chat_id(Integer migrate_to_chat_id) { 373 | this.migrate_to_chat_id = migrate_to_chat_id; 374 | } 375 | 376 | public Integer getMigrate_from_chat_id() { 377 | return migrate_from_chat_id; 378 | } 379 | 380 | public void setMigrate_from_chat_id(Integer migrate_from_chat_id) { 381 | this.migrate_from_chat_id = migrate_from_chat_id; 382 | } 383 | 384 | @Override 385 | public String toString() { 386 | return "Message{" + 387 | "message_id=" + message_id + 388 | ", from=" + from + 389 | ", date=" + date + 390 | ", chat=" + chat + 391 | ", forward_from=" + forward_from + 392 | ", forward_date=" + forward_date + 393 | ", reply_to_message=" + reply_to_message + 394 | ", text='" + text + '\'' + 395 | ", audio=" + audio + 396 | ", document=" + document + 397 | ", photo=" + photo + 398 | ", sticker=" + sticker + 399 | ", video=" + video + 400 | ", voice=" + voice + 401 | ", caption='" + caption + '\'' + 402 | ", contact=" + contact + 403 | ", location=" + location + 404 | ", new_chat_participant=" + new_chat_participant + 405 | ", left_chat_participant=" + left_chat_participant + 406 | ", new_chat_title='" + new_chat_title + '\'' + 407 | ", new_chat_photo=" + new_chat_photo + 408 | ", delete_chat_photo=" + delete_chat_photo + 409 | ", group_chat_created=" + group_chat_created + 410 | ", supergroup_chat_created=" + supergroup_chat_created + 411 | ", channel_chat_created=" + channel_chat_created + 412 | ", migrate_to_chat_id=" + migrate_to_chat_id + 413 | ", migrate_from_chat_id=" + migrate_from_chat_id + 414 | '}'; 415 | } 416 | } 417 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/PhotoSize.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents one size of a photo or a file / sticker thumbnail. 7 | * 8 | * A missing thumbnail for a file (or sticker) is presented as an empty object. 9 | */ 10 | public class PhotoSize { 11 | /** 12 | * Unique identifier for this file 13 | */ 14 | private String file_id; 15 | 16 | /** 17 | * Photo width 18 | */ 19 | private Integer width; 20 | 21 | /** 22 | * Photo height 23 | */ 24 | private Integer height; 25 | 26 | /** 27 | * Optional. File size 28 | */ 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | private Integer file_size; 31 | 32 | /** 33 | * Optional. File path 34 | */ 35 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 36 | private String file_path; 37 | 38 | public String getFile_id() { 39 | return file_id; 40 | } 41 | 42 | public void setFile_id(String file_id) { 43 | this.file_id = file_id; 44 | } 45 | 46 | public Integer getWidth() { 47 | return width; 48 | } 49 | 50 | public void setWidth(Integer width) { 51 | this.width = width; 52 | } 53 | 54 | public Integer getHeight() { 55 | return height; 56 | } 57 | 58 | public void setHeight(Integer height) { 59 | this.height = height; 60 | } 61 | 62 | public Integer getFile_size() { 63 | return file_size; 64 | } 65 | 66 | public void setFile_size(Integer file_size) { 67 | this.file_size = file_size; 68 | } 69 | 70 | public String getFile_path() { 71 | return file_path; 72 | } 73 | 74 | public void setFile_path(String file_path) { 75 | this.file_path = file_path; 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return "PhotoSize{" + 81 | "file_id='" + file_id + '\'' + 82 | ", width=" + width + 83 | ", height=" + height + 84 | ", file_size=" + file_size + 85 | ", file_path='" + file_path + '\'' + 86 | '}'; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/ReplyKeyboardHide.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * Upon receiving a message with this object, Telegram clients will hide the current custom 7 | * keyboard and display the default letter-keyboard. By default, custom keyboards are 8 | * displayed until a new keyboard is sent by a bot. An exception is made for one-time 9 | * keyboards that are hidden immediately after the user presses a button 10 | * ({@link ReplyKeyboardMarkup}). 11 | * 12 | * Example: A user votes in a poll, bot returns confirmation message in reply to the vote and 13 | * hides keyboard for that user, while still showing the keyboard with poll options to users 14 | * who haven't voted yet. 15 | */ 16 | public class ReplyKeyboardHide { 17 | /** 18 | * Requests clients to hide the custom keyboard 19 | */ 20 | private Boolean hide_keyboard; 21 | 22 | /** 23 | * Optional. Use this parameter if you want to hide keyboard for specific users only. 24 | * Targets: 1) users that are @mentioned in the text of the Message object; 25 | * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. 26 | */ 27 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 28 | private Boolean selective; 29 | 30 | public Boolean getHide_keyboard() { 31 | return hide_keyboard; 32 | } 33 | 34 | public void setHide_keyboard(Boolean hide_keyboard) { 35 | this.hide_keyboard = hide_keyboard; 36 | } 37 | 38 | public Boolean getSelective() { 39 | return selective; 40 | } 41 | 42 | public void setSelective(Boolean selective) { 43 | this.selective = selective; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "ReplyKeyboardHide{" + 49 | "hide_keyboard=" + hide_keyboard + 50 | ", selective=" + selective + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/ReplyKeyboardMarkup.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). 9 | * 10 | * Example: A user requests to change the bot's language, bot replies to the request with a 11 | * keyboard to select the new language. Other users in the group don't see the keyboard. 12 | */ 13 | public class ReplyKeyboardMarkup { 14 | 15 | /** 16 | * Array of button rows, each represented by an Array of Strings 17 | */ 18 | private List> keyboard; 19 | 20 | /** 21 | * Optional. Requests clients to resize the keyboard vertically for optimal fit 22 | * (e.g., make the keyboard smaller if there are just two rows of buttons). 23 | * Defaults to false, in which case the custom keyboard is always of the same 24 | * height as the app's standard keyboard. 25 | */ 26 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 27 | private Boolean resize_keyboard; 28 | 29 | /** 30 | * Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. 31 | */ 32 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 33 | private Boolean one_time_keyboard; 34 | 35 | /** 36 | * Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) 37 | * users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply 38 | * (has reply_to_message_id), sender of the original message. 39 | */ 40 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 41 | private Boolean selective; 42 | 43 | public List> getKeyboard() { 44 | return keyboard; 45 | } 46 | 47 | public void setKeyboard(List> keyboard) { 48 | this.keyboard = keyboard; 49 | } 50 | 51 | public Boolean getResize_keyboard() { 52 | return resize_keyboard; 53 | } 54 | 55 | public void setResize_keyboard(Boolean resize_keyboard) { 56 | this.resize_keyboard = resize_keyboard; 57 | } 58 | 59 | public Boolean getOne_time_keyboard() { 60 | return one_time_keyboard; 61 | } 62 | 63 | public void setOne_time_keyboard(Boolean one_time_keyboard) { 64 | this.one_time_keyboard = one_time_keyboard; 65 | } 66 | 67 | public Boolean getSelective() { 68 | return selective; 69 | } 70 | 71 | public void setSelective(Boolean selective) { 72 | this.selective = selective; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "ReplyKeyboardMarkup{" + 78 | "keyboard=" + keyboard + 79 | ", resize_keyboard=" + resize_keyboard + 80 | ", one_time_keyboard=" + one_time_keyboard + 81 | ", selective=" + selective + 82 | '}'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Sticker.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents a sticker. 7 | */ 8 | public class Sticker { 9 | /** 10 | * Unique identifier for this file 11 | */ 12 | private String file_id; 13 | 14 | /** 15 | * Sticker width 16 | */ 17 | private Integer width; 18 | 19 | /** 20 | * Sticker height 21 | */ 22 | private Integer height; 23 | 24 | /** 25 | * Sticker thumbnail in .webp or .jpg format 26 | */ 27 | private PhotoSize thumb; 28 | 29 | /** 30 | * Optional. File size 31 | */ 32 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 33 | private Integer file_size; 34 | 35 | public String getFile_id() { 36 | return file_id; 37 | } 38 | 39 | public void setFile_id(String file_id) { 40 | this.file_id = file_id; 41 | } 42 | 43 | public Integer getWidth() { 44 | return width; 45 | } 46 | 47 | public void setWidth(Integer width) { 48 | this.width = width; 49 | } 50 | 51 | public Integer getHeight() { 52 | return height; 53 | } 54 | 55 | public void setHeight(Integer height) { 56 | this.height = height; 57 | } 58 | 59 | public PhotoSize getThumb() { 60 | return thumb; 61 | } 62 | 63 | public void setThumb(PhotoSize thumb) { 64 | this.thumb = thumb; 65 | } 66 | 67 | public Integer getFile_size() { 68 | return file_size; 69 | } 70 | 71 | public void setFile_size(Integer file_size) { 72 | this.file_size = file_size; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "Sticker{" + 78 | "file_id='" + file_id + '\'' + 79 | ", width=" + width + 80 | ", height=" + height + 81 | ", thumb=" + thumb + 82 | ", file_size=" + file_size + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Update.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents an incoming update. 7 | */ 8 | public class Update { 9 | 10 | /** 11 | * The update‘s unique identifier. Update identifiers start from a certain positive number and increase 12 | * sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore 13 | * repeated updates or to restore the correct update sequence, should they get out of order. 14 | */ 15 | private Integer update_id; 16 | 17 | /** 18 | * Optional. New incoming message of any kind — text, photo, sticker, etc. 19 | */ 20 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 21 | private Message message; 22 | 23 | /** 24 | * Optional. New incoming inline query 25 | */ 26 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 27 | private InlineQuery inline_query; 28 | 29 | public Integer getUpdate_id() { 30 | return update_id; 31 | } 32 | 33 | public void setUpdate_id(Integer update_id) { 34 | this.update_id = update_id; 35 | } 36 | 37 | public Message getMessage() { 38 | return message; 39 | } 40 | 41 | public void setMessage(Message message) { 42 | this.message = message; 43 | } 44 | 45 | public InlineQuery getInline_query() { 46 | return inline_query; 47 | } 48 | 49 | public void setInline_query(InlineQuery inline_query) { 50 | this.inline_query = inline_query; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Update{" + 56 | "update_id=" + update_id + 57 | ", message=" + message + 58 | ", inline_query=" + inline_query + 59 | '}'; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/User.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents a Telegram user or bot. 7 | */ 8 | public class User { 9 | 10 | /** 11 | * Unique identifier for this user or bot 12 | */ 13 | private Integer id; 14 | 15 | /** 16 | * User's or bot's first name 17 | */ 18 | private String first_name; 19 | 20 | /** 21 | * Optional. User's or bot's last name 22 | */ 23 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 24 | private String last_name; 25 | 26 | /** 27 | * Optional. User's or bot's username 28 | */ 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | private String username; 31 | 32 | public Integer getId() { 33 | return id; 34 | } 35 | 36 | public void setId(Integer id) { 37 | this.id = id; 38 | } 39 | 40 | public String getFirst_name() { 41 | return first_name; 42 | } 43 | 44 | public void setFirst_name(String first_name) { 45 | this.first_name = first_name; 46 | } 47 | 48 | public String getLast_name() { 49 | return last_name; 50 | } 51 | 52 | public void setLast_name(String last_name) { 53 | this.last_name = last_name; 54 | } 55 | 56 | public String getUsername() { 57 | return username; 58 | } 59 | 60 | public void setUsername(String username) { 61 | this.username = username; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "User{" + 67 | "id=" + id + 68 | ", first_name='" + first_name + '\'' + 69 | ", last_name='" + last_name + '\'' + 70 | ", username='" + username + '\'' + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/UserProfilePhotos.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * This object represent a user's profile pictures. 7 | */ 8 | public class UserProfilePhotos { 9 | 10 | /** 11 | * Total number of profile pictures the target user has 12 | */ 13 | private Integer total_count; 14 | 15 | /** 16 | * Requested profile pictures (in up to 4 sizes each) 17 | */ 18 | private List> photos; 19 | 20 | public Integer getTotal_count() { 21 | return total_count; 22 | } 23 | 24 | public void setTotal_count(Integer total_count) { 25 | this.total_count = total_count; 26 | } 27 | 28 | public List> getPhotos() { 29 | return photos; 30 | } 31 | 32 | public void setPhotos(List> photos) { 33 | this.photos = photos; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "UserProfilePhotos{" + 39 | "total_count=" + total_count + 40 | ", photos=" + photos + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Video.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents a video file. 7 | */ 8 | public class Video { 9 | /** 10 | * Unique identifier for this file 11 | */ 12 | private String file_id; 13 | 14 | /** 15 | * Video width as defined by sender 16 | */ 17 | private Integer width; 18 | 19 | /** 20 | * Video height as defined by sender 21 | */ 22 | private Integer height; 23 | 24 | /** 25 | * Duration of the video in seconds as defined by sender 26 | */ 27 | private Integer duration; 28 | 29 | /** 30 | * Video thumbnail 31 | */ 32 | private PhotoSize thumb; 33 | 34 | /** 35 | * Optional. Mime type of a file as defined by sender 36 | */ 37 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 38 | private String mime_type; 39 | 40 | /** 41 | * Optional. File size 42 | */ 43 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 44 | private Integer file_size; 45 | 46 | /** 47 | * Optional. Text description of the video (usually empty) 48 | */ 49 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 50 | private String caption; 51 | 52 | public String getFile_id() { 53 | return file_id; 54 | } 55 | 56 | public void setFile_id(String file_id) { 57 | this.file_id = file_id; 58 | } 59 | 60 | public Integer getWidth() { 61 | return width; 62 | } 63 | 64 | public void setWidth(Integer width) { 65 | this.width = width; 66 | } 67 | 68 | public Integer getHeight() { 69 | return height; 70 | } 71 | 72 | public void setHeight(Integer height) { 73 | this.height = height; 74 | } 75 | 76 | public Integer getDuration() { 77 | return duration; 78 | } 79 | 80 | public void setDuration(Integer duration) { 81 | this.duration = duration; 82 | } 83 | 84 | public PhotoSize getThumb() { 85 | return thumb; 86 | } 87 | 88 | public void setThumb(PhotoSize thumb) { 89 | this.thumb = thumb; 90 | } 91 | 92 | public String getMime_type() { 93 | return mime_type; 94 | } 95 | 96 | public void setMime_type(String mime_type) { 97 | this.mime_type = mime_type; 98 | } 99 | 100 | public Integer getFile_size() { 101 | return file_size; 102 | } 103 | 104 | public void setFile_size(Integer file_size) { 105 | this.file_size = file_size; 106 | } 107 | 108 | public String getCaption() { 109 | return caption; 110 | } 111 | 112 | public void setCaption(String caption) { 113 | this.caption = caption; 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | return "Video{" + 119 | "file_id='" + file_id + '\'' + 120 | ", width=" + width + 121 | ", height=" + height + 122 | ", duration=" + duration + 123 | ", thumb=" + thumb + 124 | ", mime_type='" + mime_type + '\'' + 125 | ", file_size=" + file_size + 126 | ", caption='" + caption + '\'' + 127 | '}'; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/de/raysha/lib/telegram/bot/api/model/Voice.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api.model; 2 | 3 | import org.codehaus.jackson.map.annotate.JsonSerialize; 4 | 5 | /** 6 | * This object represents a voice note. 7 | */ 8 | public class Voice { 9 | 10 | /** 11 | * Unique identifier for this file 12 | */ 13 | private String file_id; 14 | 15 | /** 16 | * Duration of the audio in seconds as defined by sender 17 | */ 18 | private Integer duration; 19 | 20 | /** 21 | * Optional. MIME type of the file as defined by sender 22 | */ 23 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 24 | private String mime_type; 25 | 26 | /** 27 | * Optional. File size 28 | */ 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | private Integer file_size; 31 | 32 | public String getFile_id() { 33 | return file_id; 34 | } 35 | 36 | public void setFile_id(String file_id) { 37 | this.file_id = file_id; 38 | } 39 | 40 | public Integer getDuration() { 41 | return duration; 42 | } 43 | 44 | public void setDuration(Integer duration) { 45 | this.duration = duration; 46 | } 47 | 48 | public String getMime_type() { 49 | return mime_type; 50 | } 51 | 52 | public void setMime_type(String mime_type) { 53 | this.mime_type = mime_type; 54 | } 55 | 56 | public Integer getFile_size() { 57 | return file_size; 58 | } 59 | 60 | public void setFile_size(Integer file_size) { 61 | this.file_size = file_size; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Voice{" + 67 | "file_id='" + file_id + '\'' + 68 | ", duration=" + duration + 69 | ", mime_type='" + mime_type + '\'' + 70 | ", file_size=" + file_size + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/de/raysha/lib/telegram/bot/api/TelegramBotTest.java: -------------------------------------------------------------------------------- 1 | package de.raysha.lib.telegram.bot.api; 2 | 3 | import de.raysha.lib.telegram.bot.api.exception.BotException; 4 | import de.raysha.lib.telegram.bot.api.model.ChatId; 5 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResult; 6 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResultArticle; 7 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResultGif; 8 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResultMpeg4Gif; 9 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResultPhoto; 10 | import de.raysha.lib.telegram.bot.api.model.InlineQueryResultVideo; 11 | import de.raysha.lib.telegram.bot.api.model.Message; 12 | import de.raysha.lib.telegram.bot.api.model.ReplyKeyboardMarkup; 13 | import de.raysha.lib.telegram.bot.api.model.Update; 14 | import de.raysha.lib.telegram.bot.api.model.User; 15 | import org.junit.Before; 16 | import org.junit.BeforeClass; 17 | import org.junit.Test; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.net.URISyntaxException; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | import java.util.Properties; 26 | 27 | import static junit.framework.TestCase.assertTrue; 28 | import static org.junit.Assert.assertEquals; 29 | import static org.junit.Assert.assertNotNull; 30 | 31 | public class TelegramBotTest { 32 | private static String BOT_TOKEN; 33 | private static ChatId CHAT_ID; 34 | private TelegramBot bot; 35 | 36 | @BeforeClass 37 | public static void readProperties() throws IOException { 38 | InputStream in = TelegramBotTest.class.getResourceAsStream("/test.properties"); 39 | try { 40 | Properties configProperties = new Properties(); 41 | configProperties.load(in); 42 | 43 | BOT_TOKEN = configProperties.getProperty("bot.token"); 44 | CHAT_ID = new ChatId(Integer.parseInt(configProperties.getProperty("bot.chat.id"))); 45 | } finally { 46 | try { 47 | in.close(); 48 | } catch (IOException e) { 49 | } 50 | } 51 | } 52 | 53 | @Before 54 | public void setup() throws BotException { 55 | bot = new TelegramBot(BOT_TOKEN); 56 | System.out.println("Updates: \n" + bot.getUpdates(null, null, null)); 57 | } 58 | 59 | @Test 60 | public void getMe() throws BotException { 61 | User user = bot.getMe(); 62 | 63 | assertNotNull(user); 64 | } 65 | 66 | @Test 67 | public void sendChatAction() throws BotException { 68 | for(BotAPI.ChatAction action : BotAPI.ChatAction.values()) { 69 | assertTrue(bot.sendChatAction(CHAT_ID, action)); 70 | } 71 | } 72 | 73 | @Test 74 | public void sendMessage() throws BotException { 75 | ReplyKeyboardMarkup keyboardMarkup = buildReplyKeyboardMarkup(); 76 | String text = "Test sendMessage: *bold* _italic_ [url](http://www.example.org)!"; 77 | 78 | Message result = bot.sendMessage(CHAT_ID, text, null, true, null, keyboardMarkup); 79 | 80 | assertNotNull(result.getMessage_id()); 81 | assertNotNull(result.getDate()); 82 | assertEquals(text, result.getText()); 83 | } 84 | 85 | @Test 86 | public void sendMessageMarkdown() throws BotException { 87 | ReplyKeyboardMarkup keyboardMarkup = buildReplyKeyboardMarkup(); 88 | String text = "Test sendMessageMarkdown: *bold* _italic_ [url](http://www.example.org)!"; 89 | 90 | Message result = bot.sendMessage(CHAT_ID, text, BotAPI.ParseMode.Markdown, true, null, keyboardMarkup); 91 | 92 | assertNotNull(result.getMessage_id()); 93 | assertNotNull(result.getDate()); 94 | assertEquals("Test sendMessageMarkdown: bold italic url!", result.getText()); 95 | } 96 | 97 | @Test 98 | public void forwardMessage() throws BotException { 99 | Message message = bot.sendMessage(CHAT_ID, "Test forwardMessage"); 100 | 101 | Message result = bot.forwardMessage(CHAT_ID, CHAT_ID, message.getMessage_id()); 102 | 103 | assertNotNull(result.getMessage_id()); 104 | assertNotNull(result.getDate()); 105 | assertEquals(message.getText(), result.getText()); 106 | } 107 | 108 | @Test 109 | public void sendPhoto() throws URISyntaxException, BotException { 110 | File testPic = new File(TelegramBotTest.class.getResource("/test-pic.jpg").toURI()); 111 | 112 | String caption = "Test sendPhoto"; 113 | Message result = bot.sendPhoto(CHAT_ID, testPic, caption, null, null); 114 | 115 | assertNotNull(result); 116 | assertEquals(caption, result.getCaption()); 117 | assertNotNull(result.getPhoto()); 118 | assertTrue(result.getPhoto().size() >= 1); 119 | assertNotNull(result.getPhoto().get(0).getFile_id()); 120 | 121 | //send already uploaded photo 122 | caption += "2"; 123 | result = bot.sendPhoto(CHAT_ID, result.getPhoto().get(0).getFile_id(), caption, null, null); 124 | 125 | assertNotNull(result); 126 | assertEquals(caption, result.getCaption()); 127 | assertNotNull(result.getPhoto()); 128 | assertTrue(result.getPhoto().size() >= 1); 129 | assertNotNull(result.getPhoto().get(0).getFile_id()); 130 | } 131 | 132 | @Test 133 | public void sendAudio() throws URISyntaxException, BotException { 134 | File testAudio = new File(TelegramBotTest.class.getResource("/test-audio.mp3").toURI()); 135 | 136 | String performer = "T J McKenzie, http://en.wikipedia.org/wiki/User:T_J_McKenzie"; 137 | String title = "TestAudio"; 138 | Integer duration = 120; 139 | Message result = bot.sendAudio(CHAT_ID, testAudio, duration, performer, title, null, null); 140 | 141 | assertNotNull(result); 142 | assertNotNull(result.getAudio()); 143 | assertNotNull(result.getAudio().getFile_id()); 144 | assertEquals(performer, result.getAudio().getPerformer()); 145 | assertEquals(duration, result.getAudio().getDuration()); 146 | assertEquals(title, result.getAudio().getTitle()); 147 | 148 | result = bot.sendAudio(CHAT_ID, result.getAudio().getFile_id()); 149 | 150 | assertNotNull(result); 151 | assertNotNull(result.getAudio()); 152 | assertNotNull(result.getAudio().getFile_id()); 153 | assertEquals(performer, result.getAudio().getPerformer()); 154 | assertEquals(duration, result.getAudio().getDuration()); 155 | assertEquals(title, result.getAudio().getTitle()); 156 | } 157 | 158 | @Test 159 | public void sendVoice() throws URISyntaxException, BotException { 160 | File testVoice = new File(TelegramBotTest.class.getResource("/test-voice.ogg").toURI()); 161 | 162 | Integer duration = 120; 163 | Message result = bot.sendVoice(CHAT_ID, testVoice, duration, null, null); 164 | 165 | assertNotNull(result); 166 | assertNotNull(result.getVoice()); 167 | assertNotNull(result.getVoice().getFile_id()); 168 | assertEquals(duration, result.getVoice().getDuration()); 169 | 170 | result = bot.sendVoice(CHAT_ID, result.getVoice().getFile_id()); 171 | 172 | assertNotNull(result); 173 | assertNotNull(result.getVoice()); 174 | assertNotNull(result.getVoice().getFile_id()); 175 | assertEquals(duration, result.getVoice().getDuration()); 176 | } 177 | 178 | @Test 179 | public void sendDocument() throws URISyntaxException, BotException { 180 | File testDocument = new File(TelegramBotTest.class.getResource("/test-doc.txt").toURI()); 181 | 182 | Message result = bot.sendDocument(CHAT_ID, testDocument); 183 | 184 | assertNotNull(result); 185 | assertNotNull(result.getDocument()); 186 | assertNotNull(result.getDocument().getFile_id()); 187 | 188 | result = bot.sendDocument(CHAT_ID, result.getDocument().getFile_id()); 189 | 190 | assertNotNull(result); 191 | assertNotNull(result.getDocument()); 192 | assertNotNull(result.getDocument().getFile_id()); 193 | } 194 | 195 | @Test 196 | public void sendSticker() throws URISyntaxException, BotException { 197 | File testSticker = new File(TelegramBotTest.class.getResource("/test-sticker.webp").toURI()); 198 | 199 | Message result = bot.sendSticker(CHAT_ID, testSticker); 200 | 201 | assertNotNull(result); 202 | assertNotNull(result.getSticker()); 203 | assertNotNull(result.getSticker().getFile_id()); 204 | 205 | result = bot.sendSticker(CHAT_ID, result.getSticker().getFile_id()); 206 | 207 | assertNotNull(result); 208 | assertNotNull(result.getSticker()); 209 | assertNotNull(result.getSticker().getFile_id()); 210 | } 211 | 212 | @Test 213 | public void sendVideo() throws URISyntaxException, BotException { 214 | File testVideo = new File(TelegramBotTest.class.getResource("/test-vid.mp4").toURI()); 215 | 216 | String caption = "Test sendVideo"; 217 | Integer duration = 5; 218 | Message result = bot.sendVideo(CHAT_ID, testVideo, duration, caption, null, null); 219 | 220 | assertNotNull(result); 221 | assertNotNull(result.getVideo()); 222 | assertNotNull(result.getVideo().getFile_id()); 223 | assertEquals(duration, result.getVideo().getDuration()); 224 | assertEquals(caption, result.getCaption()); 225 | 226 | result = bot.sendVideo(CHAT_ID, result.getVideo().getFile_id()); 227 | 228 | assertNotNull(result); 229 | assertNotNull(result.getVideo()); 230 | assertNotNull(result.getVideo().getFile_id()); 231 | assertEquals(duration, result.getVideo().getDuration()); 232 | } 233 | 234 | @Test 235 | public void sendLocation() throws URISyntaxException, BotException { 236 | float latitude = 13.12f; 237 | float longitude = 12.13f; 238 | 239 | Message result = bot.sendLocation(CHAT_ID, latitude, longitude); 240 | 241 | assertNotNull(result); 242 | assertNotNull(result.getLocation()); 243 | } 244 | 245 | @Test 246 | public void getFile() throws BotException, URISyntaxException { 247 | File testDocument = new File(TelegramBotTest.class.getResource("/test-doc.txt").toURI()); 248 | 249 | Message result = bot.sendDocument(CHAT_ID, testDocument); 250 | 251 | de.raysha.lib.telegram.bot.api.model.File file = bot.getFile(result.getDocument().getFile_id()); 252 | 253 | assertNotNull(file); 254 | assertTrue(file.getFile_size() > 0); 255 | 256 | assertNotNull(file.getDownloadUrl(BOT_TOKEN)); 257 | } 258 | 259 | @Test 260 | public void setWebhook() throws BotException { 261 | assertTrue(bot.setWebhook("https://raysha.de/bot")); 262 | assertTrue(bot.setWebhook(null)); 263 | } 264 | 265 | @Test 266 | public void answerInlineQuery() throws BotException { 267 | for(Update update : bot.getUpdates(null, null, null)){ 268 | if(update.getInline_query() != null){ 269 | try { 270 | bot.answerInlineQuery(update.getInline_query().getId(), buildInlineQueryResults()); 271 | } catch (BotException e) { 272 | if(!e.getMessage().contains("QUERY_ID_INVALID")){ 273 | throw e; 274 | } 275 | } 276 | } 277 | } 278 | } 279 | 280 | private List buildInlineQueryResults() { 281 | List results = new ArrayList(); 282 | 283 | final String thumb_url = "https://upload.wikimedia.org/wikipedia/commons/7/70/Jpegartefakt90-20.jpg"; 284 | 285 | results.add(new InlineQueryResultArticle("Article title", "Article Message", null, true, "https://github.com/rainu/telegram-bot-api", false, "rainu@git", thumb_url, 10, 10)); 286 | results.add(new InlineQueryResultPhoto(thumb_url, thumb_url, 50, 50, "Test photo", "This is a test photo", "Test caption", "Photo message", null)); 287 | results.add(new InlineQueryResultGif("https://upload.wikimedia.org/wikipedia/commons/5/5a/Live_from_the_Moon_-_Impact!.gif", thumb_url, 100, 100, "Gif title", "Gif caption", "Gif Message", null, true)); 288 | results.add(new InlineQueryResultMpeg4Gif("http://clips.vorwaerts-gmbh.de/VfE_html5.mp4", thumb_url, 100, 100, "Mpeg4 Title", "Mpeg4Caption", "Mpeg4 Message", null, true)); 289 | results.add(new InlineQueryResultVideo("http://clips.vorwaerts-gmbh.de/VfE_html5.mp4", "video/mp4", "Video Message", null, false, 100, 100, 120, thumb_url, "Video Title", "Video Description")); 290 | 291 | return results; 292 | } 293 | 294 | private ReplyKeyboardMarkup buildReplyKeyboardMarkup() { 295 | ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(); 296 | keyboardMarkup.setKeyboard(new ArrayList>()); 297 | keyboardMarkup.getKeyboard().add(new ArrayList()); 298 | keyboardMarkup.getKeyboard().get(0).add("Hallo!"); 299 | return keyboardMarkup; 300 | } 301 | 302 | } 303 | -------------------------------------------------------------------------------- /src/test/resources/test-audio.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainu/telegram-bot-api/25d807240f3d64a434ff91599fda333e923b3928/src/test/resources/test-audio.mp3 -------------------------------------------------------------------------------- /src/test/resources/test-doc.txt: -------------------------------------------------------------------------------- 1 | This is a test document! -------------------------------------------------------------------------------- /src/test/resources/test-pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainu/telegram-bot-api/25d807240f3d64a434ff91599fda333e923b3928/src/test/resources/test-pic.jpg -------------------------------------------------------------------------------- /src/test/resources/test-sticker.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainu/telegram-bot-api/25d807240f3d64a434ff91599fda333e923b3928/src/test/resources/test-sticker.webp -------------------------------------------------------------------------------- /src/test/resources/test-vid.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainu/telegram-bot-api/25d807240f3d64a434ff91599fda333e923b3928/src/test/resources/test-vid.mp4 -------------------------------------------------------------------------------- /src/test/resources/test-voice.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainu/telegram-bot-api/25d807240f3d64a434ff91599fda333e923b3928/src/test/resources/test-voice.ogg -------------------------------------------------------------------------------- /src/test/resources/test.properties: -------------------------------------------------------------------------------- 1 | bot.token= 2 | bot.chat.id= --------------------------------------------------------------------------------