diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c4f97f --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Telegram Bot Java Library +A simple to use library to create Telegram Bots in Java (Still Beta Version) + +## Translations +Bots are now supporting multilanguage. If you want to add your own, feel free to translate at [transifex](https://www.transifex.com/projects/p/telegrambots/) + +## Contributions +Feel free to fork this project, work on it and then make a pull request. Most of the times I will accept them if they add something valuable to the code. + +Please, **DO NOT PUSH ANY TOKEN OR API KEY**, I will never accept a pull request with that content. + +## Webhooks vs GetUpdates +Both ways are supported (but I still didn't tested webhooks). To change between them, just go to *BuildVars.java* and change variable *useWebHook* value. + +I recommend using getUpdates methods. Webhooks only works using a certificated that is not self-signed + +## Example bots +Open them and send them */help* command to get some information about their capabilities: + +https://telegram.me/weatherbot + +https://telegram.me/directionsbot + +https://telegram.me/filesbot + +https://telegram.me/TGlanguagesbot + +## Telegram Bot API +This library use [Telegram bot API](https://core.telegram.org/bots), you can find more information following the link. + +## Questions or Suggestions +Feel free to create issues [here](https://github.com/rubenlagus/TelegramBots/issues) as you need + +## Usage with eclipse + +Follow the steps created by Rico [here](https://github.com/rubenlagus/TelegramBots/blob/master/eclipse%20configuration.md) + +## License + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . diff --git a/eclipse configuration.md b/eclipse configuration.md new file mode 100644 index 0000000..8637ab1 --- /dev/null +++ b/eclipse configuration.md @@ -0,0 +1,27 @@ +# How to use TelegramBots with Eclipse + + +### Step 1: Install Maven +To get started, you need to install the Maven-Plugin for Eclipse. Click on Help > Eclipse Marketplace. After it finished loading, search for “Maven”. +Now install **“Maven (Java EE) Integration for Eclipse WTP”**. You have to restart, after the installation is completed. + +### Step 2: Download the Project +Now you need to get the project itself. +Visit [TelegramBots - github.com][1] and choose “Download Zip”, to download the zip-file. [Here] is a direct link if you are lazy. + +### Step 3: Create folder +Now let’s setup the project-folder. Go to your Eclipse-Workspace and create a folder (name it whatever you want it to be called). I just named it **“TelegramBotApi”**. Afterwards copy everything from the zip-file into that folder. + +### Step 4: Import project +To import your project into the workspace you have to go to File > Import > (Folder) Maven > Existing Maven Projects > Next. Choose the folder, you have created in Step 3. In my case: **“TelegramBotApi”**. Click on finish and let Maven import the dependencies. + +### Step 5: Setting the compliance level +In this last step you need to change the Compiler compliance level. To do this right-click on your Project (in my case **“TelegramBotApi”**) > Properties > Java Compiler. Uncheck the “Use compliance from…” if necessary and set it to 1.7 + +*Now you are done. Everything should work fine. You need to set your Bot-Token in the BotConfig.java, afterwards you can run Main.java to check.* + +**For a better intstruction sheet, visit [Google Drive]** + +[Google Drive]:https://goo.gl/5jd40w +[here]:https://github.com/rubenlagus/TelegramBots/archive/master.zip +[1]:https://github.com/rubenlagus/TelegramBots/ diff --git a/src/main/java/org/telegram/api/Document.java b/src/main/java/org/telegram/api/Document.java index 16f7735..00ecf1d 100644 --- a/src/main/java/org/telegram/api/Document.java +++ b/src/main/java/org/telegram/api/Document.java @@ -34,7 +34,12 @@ public class Document { public Document(JSONObject jsonObject) { this.fileId = jsonObject.getString(FILEID_FIELD); - this.thumb = new PhotoSize(jsonObject.getJSONObject(THUMB_FIELD)); + if (jsonObject.has(THUMB_FIELD) { + this.thumb = new PhotoSize(jsonObject.getJSONObject(THUMB_FIELD)); + } + else { + this.thumb = null; + } this.fileName = jsonObject.optString(FILENAME_FIELD, ""); this.mimeType = jsonObject.optString(MIMETYPE_FIELD, ""); this.fileSize = jsonObject.optInt(FILESIZE_FIELD, 0);