Skip to content

Commit

Permalink
Merge pull request #241 from rubenlagus/dev
Browse files Browse the repository at this point in the history
Dev 3.0 to Master
  • Loading branch information
dapoldi authored May 19, 2017
2 parents 7d6eab7 + 4cb53e7 commit f574c27
Show file tree
Hide file tree
Showing 54 changed files with 2,181 additions and 171 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ Just import add the library to your project with one of these options:
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>2.4.4.5</version>
<version>3.0</version>
</dependency>
```

2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/2.4.4.5)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/2.4.4.5)
```gradle
compile "org.telegram:telegrambots:3.0"
```

2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/3.0)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/3.0)

In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

Expand Down
13 changes: 12 additions & 1 deletion TelegramBots.wiki/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@
3. Added new How to send photos by file_id to FAQ.
4. Added reference to new gitbook about this library.
5. Added custom ExponentialBackOff waiting time when having network problems in long-polling mode. (Custom implementation is allowed via BotOptions)
3. Bug fixing: #184, #183
6. Bug fixing: #184, #183

### <a id="3.0"></a>3.0 ###
1. New field `gif_duration` and `mpeg4_duration` in `InlineQueryResultGif` and `InlineQueryResultMpeg4Gif`.
2. Field `new_chat_member` was replaced by `new_chat_members` in `Message` object.
3. Some methods gets now constructors with mandatory parameters to simplify their creation (including preconditions).
4. New `deleteMessage` method.
5. New field `language_code` in `User` object.
6. New Payments API methods
7. New Video Messages API methods

**[[How to update to version 3.0|How-To-Update#3.0]]**
4 changes: 2 additions & 2 deletions TelegramBots.wiki/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>2.4.4.5</version>
<version>3.0</version>
</dependency>
```
* With **Gradle**:

```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '2.4.4.5'
compile group: 'org.telegram', name: 'telegrambots', version: '3.0'
```

2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
Expand Down
2 changes: 1 addition & 1 deletion TelegramBots.wiki/Home.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Welcome to the TelegramBots wiki. Use the sidebar on the right. If you're not sure what to look at, why not take a look at the [[Getting Started|Getting-Started]] guide?

If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://www.gitbook.com/button/status/book/monsterdeveloper/writing-telegram-bots-on-java)
If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://www.gitbook.com/book/monsterdeveloper/writing-telegram-bots-on-java/details)
5 changes: 4 additions & 1 deletion TelegramBots.wiki/How-To-Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
### <a id="2.4.4.4"></a>To version 2.4.4.4 ###
1. All calls to `editMessageText`, `editMessageCaption` or `editMessageReplyMarkup` in `AbsSender` return value is changed to `Serializable`
2. In `editMessageTextAsync`, `editMessageCaptionAsync` or `editMessageReplyMarkupAsync` in `AbsSender`, second parameter should become `SentCallback<Serializable>` due to new return type.
2. In `editMessageTextAsync`, `editMessageCaptionAsync` or `editMessageReplyMarkupAsync` in `AbsSender`, second parameter should become `SentCallback<Serializable>` due to new return type.
### <a id="3.0"></a>To version 3.0 ###
1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.telegram</groupId>
<artifactId>Bots</artifactId>
<packaging>pom</packaging>
<version>2.4.4.5</version>
<version>3.0</version>

<modules>
<module>telegrambots</module>
Expand All @@ -24,6 +24,6 @@

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<bots.version>2.4.4.5</bots.version>
<bots.version>3.0</bots.version>
</properties>
</project>
13 changes: 12 additions & 1 deletion telegrambots-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>2.4.4.5</version>
<version>3.0</version>
<packaging>jar</packaging>

<name>Telegram Bots Meta</name>
Expand Down Expand Up @@ -228,6 +228,17 @@
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Constants needed for Telegram Bots API
* @date 20 of June of 2015
* Constants needed for Telegram Bots API
*/
public class ApiConstants {
public static final String BASE_URL = "https://api.telegram.org/bot";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package org.telegram.telegrambots.api.methods;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;

import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* @author Ruben Bermudez
* @version 1.0
*
* Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation
* in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries.
*
* On success, True is returned
*
* @apiNote The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
*/
public class AnswerPreCheckoutQuery extends BotApiMethod<Boolean> {
public static final String PATH = "answerPreCheckoutQuery";

private static final String PRE_CHECKOUT_QUERY_ID_FIELD = "pre_checkout_query_id";
private static final String OK_FIELD = "ok";
private static final String ERROR_MESSAGE_FIELD = "error_message";

@JsonProperty(PRE_CHECKOUT_QUERY_ID_FIELD)
private String preCheckoutQueryId; ///< Unique identifier for the query to be answered
@JsonProperty(OK_FIELD)
private Boolean ok; ///< Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
@JsonProperty(ERROR_MESSAGE_FIELD)
private String errorMessage; ///< Optional. Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout

/**
* Creates an empty answer pre-checkout query
*/
public AnswerPreCheckoutQuery() {
super();
}

/**
* Creates an answer pre-checkout query with mandatory parameters
* @param preCheckoutQueryId Unique identifier for the query to be answered
* @param ok Specify True if delivery to the specified address is possible and False if there are any problems
*/
public AnswerPreCheckoutQuery(String preCheckoutQueryId, Boolean ok) {
this.preCheckoutQueryId = checkNotNull(preCheckoutQueryId);
this.ok = checkNotNull(ok);
}

public String getPreCheckoutQueryId() {
return preCheckoutQueryId;
}

public AnswerPreCheckoutQuery setPreCheckoutQueryId(String preCheckoutQueryId) {
this.preCheckoutQueryId = checkNotNull(preCheckoutQueryId);
return this;
}

public Boolean getOk() {
return ok;
}

public AnswerPreCheckoutQuery setOk(Boolean ok) {
this.ok = checkNotNull(ok);
return this;
}

public String getErrorMessage() {
return errorMessage;
}

public AnswerPreCheckoutQuery setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
return this;
}

@Override
public void validate() throws TelegramApiValidationException {
if (preCheckoutQueryId == null || preCheckoutQueryId.isEmpty()) {
throw new TelegramApiValidationException("PreCheckoutQueryId can't be empty", this);
}
if (ok == null) {
throw new TelegramApiValidationException("Ok can't be null", this);
}
if (!ok) {
if (errorMessage == null || errorMessage.isEmpty()) {
throw new TelegramApiValidationException("ErrorMessage can't be empty if not ok", this);
}
}
}

@Override
public String getMethod() {
return PATH;
}

@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error answering pre-checkout query", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}

@Override
public String toString() {
return "AnswerPreCheckoutQuery{" +
"preCheckoutQueryId='" + preCheckoutQueryId + '\'' +
", ok=" + ok +
", errorMessage='" + errorMessage + '\'' +
'}';
}
}
Loading

0 comments on commit f574c27

Please sign in to comment.