Payments API

This commit is contained in:
Rubenlagus 2017-03-27 00:49:08 +02:00 committed by Ruben Bermudez
parent 28197cc7c0
commit fc712656fa
40 changed files with 1547 additions and 134 deletions

View File

@ -27,12 +27,12 @@ Just import add the library to your project with one of these options:
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>2.4.4.5</version> <version>2.4.4.6</version>
</dependency> </dependency>
``` ```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/2.4.4.5) 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/2.4.4.6)
3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/2.4.4.5) 3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/2.4.4.6)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -43,3 +43,11 @@
4. Added reference to new gitbook about this library. 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) 5. Added custom ExponentialBackOff waiting time when having network problems in long-polling mode. (Custom implementation is allowed via BotOptions)
6. Bug fixing: #184, #183 6. Bug fixing: #184, #183
### <a id="2.4.4.6"></a>2.4.4.6 ###
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 Payments API methods
**[[How to update to version 2.4.4.6|How-To-Update#2.4.4.6]]**

View File

@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>2.4.4.5</version> <version>2.4.4.6</version>
</dependency> </dependency>
``` ```
* With **Gradle**: * With **Gradle**:
```groovy ```groovy
compile group: 'org.telegram', name: 'telegrambots', version: '2.4.4.5' compile group: 'org.telegram', name: 'telegrambots', version: '2.4.4.6'
``` ```
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -21,3 +21,6 @@
### <a id="2.4.4.4"></a>To version 2.4.4.4 ### ### <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` 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="2.4.4.6"></a>To version 2.4.4.6 ###
1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users.

View File

@ -7,7 +7,7 @@
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>Bots</artifactId> <artifactId>Bots</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>2.4.4.5</version> <version>2.4.4.6</version>
<modules> <modules>
<module>telegrambots</module> <module>telegrambots</module>
@ -24,6 +24,6 @@
<properties> <properties>
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
<bots.version>2.4.4.5</bots.version> <bots.version>2.4.4.6</bots.version>
</properties> </properties>
</project> </project>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId> <artifactId>telegrambots-meta</artifactId>
<version>2.4.4.5</version> <version>2.4.4.6</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Telegram Bots Meta</name> <name>Telegram Bots Meta</name>
@ -228,6 +228,17 @@
</rules> </rules>
</configuration> </configuration>
</plugin> </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> </plugins>
<pluginManagement> <pluginManagement>
<plugins> <plugins>

View File

@ -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 + '\'' +
'}';
}
}

View File

@ -0,0 +1,146 @@
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.payments.ShippingOption;
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 java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
*
* If you sent an invoice requesting a shipping address and the parameter flexible was specified,
* the Bot API will send an Update with a shipping_query field to the bot.
* Use this method to reply to shipping queries.
*
* On success, True is returned
*/
public class AnswerShippingQuery extends BotApiMethod<Boolean> {
public static final String PATH = "answerShippingQuery";
private static final String SHIPPING_QUERY_ID_FIELD = "shipping_query_id";
private static final String OK_FIELD = "ok";
private static final String SHIPPING_OPTIONS_FIELD = "shipping_options";
private static final String ERROR_MESSAGE_FIELD = "error_message";
@JsonProperty(SHIPPING_QUERY_ID_FIELD)
private String shippingQueryId; ///< Unique identifier for the query to be answered
@JsonProperty(OK_FIELD)
private Boolean ok; ///< Specify True if delivery to the specified address is possible and False if there are any problems
@JsonProperty(SHIPPING_OPTIONS_FIELD)
private List<ShippingOption> shippingOptions; ///< Optional. Required if ok is True. A JSON-serialized array of available shipping options.
@JsonProperty(ERROR_MESSAGE_FIELD)
private String errorMessage; ///< Optional. Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable').
/**
* Creates an empty answer shipping query
*/
public AnswerShippingQuery() {
super();
}
/**
* Creates an answer shipping query with mandatory parameters
* @param shippingQueryId 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 AnswerShippingQuery(String shippingQueryId, Boolean ok) {
this.shippingQueryId = checkNotNull(shippingQueryId);
this.ok = checkNotNull(ok);
}
public String getShippingQueryId() {
return shippingQueryId;
}
public AnswerShippingQuery setShippingQueryId(String shippingQueryId) {
this.shippingQueryId = checkNotNull(shippingQueryId);
return this;
}
public Boolean getOk() {
return ok;
}
public AnswerShippingQuery setOk(Boolean ok) {
this.ok = checkNotNull(ok);
return this;
}
public List<ShippingOption> getShippingOptions() {
return shippingOptions;
}
public AnswerShippingQuery setShippingOptions(List<ShippingOption> shippingOptions) {
this.shippingOptions = shippingOptions;
return this;
}
public String getErrorMessage() {
return errorMessage;
}
public AnswerShippingQuery setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (shippingQueryId == null || shippingQueryId.isEmpty()) {
throw new TelegramApiValidationException("ShippingQueryId can't be empty", this);
}
if (ok == null) {
throw new TelegramApiValidationException("Ok can't be null", this);
}
if (ok) {
if (shippingOptions == null || shippingOptions.isEmpty()) {
throw new TelegramApiValidationException("ShippingOptions array can't be empty if ok", this);
}
for (ShippingOption shippingOption : shippingOptions) {
shippingOption.validate();
}
} else {
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 shipping query", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public String toString() {
return "AnswerShippingQuery{" +
"shippingQueryId='" + shippingQueryId + '\'' +
", ok=" + ok +
", shippingOptions=" + shippingOptions +
", errorMessage='" + errorMessage + '\'' +
'}';
}
}

View File

@ -41,11 +41,7 @@ public class SendAudio extends PartialBotApiMethod<Message> {
private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro channels) private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro channels)
private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers or Url to upload it private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers or Url to upload it
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
/** private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
private Boolean disableNotification;
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private String performer; ///< Optional. Performer of sent audio private String performer; ///< Optional. Performer of sent audio
private String title; ///< Optional. Title of sent audio private String title; ///< Optional. Title of sent audio

View File

@ -39,12 +39,8 @@ public class SendContact extends BotApiMethod<Message> {
private String firstName; ///< User's first name private String firstName; ///< User's first name
@JsonProperty(LAST_NAME_FIELD) @JsonProperty(LAST_NAME_FIELD)
private String lastName; ///< Optional. User's last name private String lastName; ///< Optional. User's last name
/**
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
@JsonProperty(DISABLENOTIFICATION_FIELD) @JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD) @JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD) @JsonProperty(REPLYMARKUP_FIELD)

View File

@ -32,11 +32,7 @@ public class SendDocument extends PartialBotApiMethod<Message> {
private String chatId; ///< Unique identifier for the chat to send the message to or Username for the channel to send the message to private String chatId; ///< Unique identifier for the chat to send the message to or Username for the channel to send the message to
private String document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers or Url to upload it private String document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers or Url to upload it
private String caption; ///< Optional. Document caption (may also be used when resending documents by file_id), 0-200 characters private String caption; ///< Optional. Document caption (may also be used when resending documents by file_id), 0-200 characters
/** private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
private Boolean disableNotification;
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard

View File

@ -49,12 +49,8 @@ public class SendGame extends BotApiMethod<Message> {
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
@JsonProperty(GAMESHORTNAME_FIELD) @JsonProperty(GAMESHORTNAME_FIELD)
private String gameShortName; ///< Short name of the game private String gameShortName; ///< Short name of the game
/**
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
@JsonProperty(DISABLENOTIFICATION_FIELD) @JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD) @JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD) @JsonProperty(REPLYMARKUP_FIELD)

View File

@ -0,0 +1,388 @@
package org.telegram.telegrambots.api.methods.send;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.payments.LabeledPrice;
import org.telegram.telegrambots.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* Use this method to send an invoice. On success, the sent Message is returned.
*/
public class SendInvoice extends BotApiMethod<Message> {
public static final String PATH = "sendinvoice";
private static final String CHATID_FIELD = "chat_id";
private static final String TITLE_FIELD = "title";
private static final String DESCRIPTION_FIELD = "description";
private static final String PAYLOAD_FIELD = "payload";
private static final String PROVIDER_TOKEN_FIELD = "provider_token";
private static final String START_PARAMETER_FIELD = "start_parameter";
private static final String CURRENCY_FIELD = "currency";
private static final String PRICES_FIELD = "prices";
private static final String PHOTO_URL_FIELD = "photo_url";
private static final String PHOTO_SIZE_FIELD = "photo_size";
private static final String PHOTO_WIDTH_FIELD = "photo_width";
private static final String PHOTO_HEIGHT_FIELD = "photo_height";
private static final String NEED_NAME_FIELD = "need_name";
private static final String NEED_PHONE_NUMBER_FIELD = "need_phone_number";
private static final String NEED_EMAIL_FIELD = "need_email";
private static final String NEED_SHIPPING_ADDRESS_FIELD = "need_shipping_address";
private static final String IS_FLEXIBLE_FIELD = "is_flexible";
private static final String DISABLE_NOTIFICATION_FIELD = "disable_notification";
private static final String REPLY_TO_MESSAGE_ID_FIELD = "reply_to_message_id";
private static final String REPLY_MARKUP_FIELD = "reply_markup\t";
@JsonProperty(CHATID_FIELD)
private Integer chatId; ///< Unique identifier for the target private chat
@JsonProperty(TITLE_FIELD)
private String title; ///< Product name
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Product description
@JsonProperty(PAYLOAD_FIELD)
private String payload; ///< Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
@JsonProperty(PROVIDER_TOKEN_FIELD)
private String providerToken; ///< Payments provider token, obtained via Botfather
@JsonProperty(START_PARAMETER_FIELD)
private String startParameter; ///< Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter.
@JsonProperty(CURRENCY_FIELD)
private String currency; ///< 3-letter ISO 4217 currency code
@JsonProperty(PRICES_FIELD)
private List<LabeledPrice> prices; ///< Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
@JsonProperty(PHOTO_URL_FIELD)
/**
* Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
* People like it better when they see what they are paying for
*/
private String photoUrl;
@JsonProperty(PHOTO_SIZE_FIELD)
private Integer photoSize; ///< Optional. Photo size
@JsonProperty(PHOTO_WIDTH_FIELD)
private Integer photoWidth; ///< Optional. Photo width
@JsonProperty(PHOTO_HEIGHT_FIELD)
private Integer photoHeight; ///< Optional. Photo height
@JsonProperty(NEED_NAME_FIELD)
private Boolean needName; ///< Optional. Pass True, if you require the user's full name to complete the order
@JsonProperty(NEED_PHONE_NUMBER_FIELD)
private Boolean needPhoneNumber; ///< Optional. Pass True, if you require the user's phone number to complete the order
@JsonProperty(NEED_EMAIL_FIELD)
private Boolean needEmail; ///< Optional. Pass True, if you require the user's email to complete the order
@JsonProperty(NEED_SHIPPING_ADDRESS_FIELD)
private Boolean needShippingAddress; ///< Optional. Pass True, if you require the user's shipping address to complete the order
@JsonProperty(IS_FLEXIBLE_FIELD)
private Boolean isFlexible; ///< Optional. Pass True, if the final price depends on the shipping method
@JsonProperty(DISABLE_NOTIFICATION_FIELD)
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLY_TO_MESSAGE_ID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLY_MARKUP_FIELD)
/**
* Optional. A JSON-serialized object for an inline keyboard.
*
* @note If empty, one 'Buy title' button will be shown. If not empty, the first button must be a Pay button.
*/
private InlineKeyboardMarkup replyMarkup;
/**
* Build an empty SendInvoice object
*/
public SendInvoice() {
super();
}
/**
* Build a SendInvoice object with empty parameters
* @param chatId Unique identifier for the target private chat
* @param title Product name
* @param description Product description
* @param payload Bot defined invoice payload, 1-128 bytes.
* @param providerToken Payments provider token
* @param startParameter Unique deep-linking parameter.
* @param currency 3-letter ISO 4217 currency code
* @param prices Price breakdown, a list of components
*/
public SendInvoice(Integer chatId, String title, String description, String payload, String providerToken,
String startParameter, String currency, List<LabeledPrice> prices) {
this.chatId = checkNotNull(chatId);
this.title = checkNotNull(title);
this.description = checkNotNull(description);
this.payload = checkNotNull(payload);
this.providerToken = checkNotNull(providerToken);
this.startParameter = checkNotNull(startParameter);
this.currency = checkNotNull(currency);
this.prices = checkNotNull(prices);
}
public Integer getChatId() {
return chatId;
}
public SendInvoice setChatId(Integer chatId) {
this.chatId = checkNotNull(chatId);
return this;
}
public String getTitle() {
return title;
}
public SendInvoice setTitle(String title) {
this.title = checkNotNull(title);
return this;
}
public String getDescription() {
return description;
}
public SendInvoice setDescription(String description) {
this.description = checkNotNull(description);
return this;
}
public String getPayload() {
return payload;
}
public SendInvoice setPayload(String payload) {
this.payload = checkNotNull(payload);
return this;
}
public String getProviderToken() {
return providerToken;
}
public SendInvoice setProviderToken(String providerToken) {
this.providerToken = checkNotNull(providerToken);
return this;
}
public String getStartParameter() {
return startParameter;
}
public SendInvoice setStartParameter(String startParameter) {
this.startParameter = checkNotNull(startParameter);
return this;
}
public String getCurrency() {
return currency;
}
public SendInvoice setCurrency(String currency) {
this.currency = checkNotNull(currency);
return this;
}
public List<LabeledPrice> getPrices() {
return prices;
}
public SendInvoice setPrices(List<LabeledPrice> prices) {
this.prices = checkNotNull(prices);
return this;
}
public String getPhotoUrl() {
return photoUrl;
}
public SendInvoice setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
return this;
}
public Integer getPhotoSize() {
return photoSize;
}
public SendInvoice setPhotoSize(Integer photoSize) {
this.photoSize = photoSize;
return this;
}
public Integer getPhotoWidth() {
return photoWidth;
}
public SendInvoice setPhotoWidth(Integer photoWidth) {
this.photoWidth = photoWidth;
return this;
}
public Integer getPhotoHeight() {
return photoHeight;
}
public SendInvoice setPhotoHeight(Integer photoHeight) {
this.photoHeight = photoHeight;
return this;
}
public Boolean getNeedName() {
return needName;
}
public SendInvoice setNeedName(Boolean needName) {
this.needName = needName;
return this;
}
public Boolean getNeedPhoneNumber() {
return needPhoneNumber;
}
public SendInvoice setNeedPhoneNumber(Boolean needPhoneNumber) {
this.needPhoneNumber = needPhoneNumber;
return this;
}
public Boolean getNeedEmail() {
return needEmail;
}
public SendInvoice setNeedEmail(Boolean needEmail) {
this.needEmail = needEmail;
return this;
}
public Boolean getNeedShippingAddress() {
return needShippingAddress;
}
public SendInvoice setNeedShippingAddress(Boolean needShippingAddress) {
this.needShippingAddress = needShippingAddress;
return this;
}
public Boolean getFlexible() {
return isFlexible;
}
public SendInvoice setFlexible(Boolean flexible) {
isFlexible = flexible;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendInvoice setDisableNotification(Boolean disableNotification) {
this.disableNotification = disableNotification;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendInvoice setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public InlineKeyboardMarkup getReplyMarkup() {
return replyMarkup;
}
public SendInvoice setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
@Override
public String getMethod() {
return PATH;
}
@Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error sending invoice", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId == null) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
if (title == null || title.isEmpty()) {
throw new TelegramApiValidationException("Title parameter can't be empty", this);
}
if (description == null || description.isEmpty()) {
throw new TelegramApiValidationException("Description parameter can't be empty", this);
}
if (payload == null || payload.isEmpty()) {
throw new TelegramApiValidationException("Payload parameter can't be empty", this);
}
if (providerToken == null || providerToken.isEmpty()) {
throw new TelegramApiValidationException("ProviderToken parameter can't be empty", this);
}
if (startParameter == null || startParameter.isEmpty()) {
throw new TelegramApiValidationException("StartParameter parameter can't be empty", this);
}
if (currency == null || currency.isEmpty()) {
throw new TelegramApiValidationException("Currency parameter can't be empty", this);
}
if (prices == null || prices.isEmpty()) {
throw new TelegramApiValidationException("Prices parameter can't be empty", this);
} else {
for (LabeledPrice price : prices) {
price.validate();
}
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendInvoice{" +
"chatId='" + chatId + '\'' +
", title='" + title + '\'' +
", description='" + description + '\'' +
", payload='" + payload + '\'' +
", providerToken='" + providerToken + '\'' +
", startParameter='" + startParameter + '\'' +
", currency='" + currency + '\'' +
", prices=" + prices +
", photoUrl='" + photoUrl + '\'' +
", photoSize=" + photoSize +
", photoWidth=" + photoWidth +
", photoHeight=" + photoHeight +
", needName=" + needName +
", needPhoneNumber=" + needPhoneNumber +
", needEmail=" + needEmail +
", needShippingAddress=" + needShippingAddress +
", isFlexible=" + isFlexible +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
'}';
}
}

View File

@ -35,12 +35,8 @@ public class SendLocation extends BotApiMethod<Message> {
private Float latitude; ///< Latitude of location private Float latitude; ///< Latitude of location
@JsonProperty(LONGITUDE_FIELD) @JsonProperty(LONGITUDE_FIELD)
private Float longitude; ///< Longitude of location private Float longitude; ///< Longitude of location
/**
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
@JsonProperty(DISABLENOTIFICATION_FIELD) @JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD) @JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD) @JsonProperty(REPLYMARKUP_FIELD)

View File

@ -39,12 +39,8 @@ public class SendMessage extends BotApiMethod<Message> {
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and URL text in your bot's message. private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and URL text in your bot's message.
@JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD) @JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD)
private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in this message private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in this message
/**
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
@JsonProperty(DISABLENOTIFICATION_FIELD) @JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD) @JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD) @JsonProperty(REPLYMARKUP_FIELD)

View File

@ -32,11 +32,7 @@ public class SendPhoto extends PartialBotApiMethod<Message> {
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers or URL to upload it private String photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers or URL to upload it
private String caption; ///< Optional Photo caption (may also be used when resending photos by file_id). private String caption; ///< Optional Photo caption (may also be used when resending photos by file_id).
/** private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
private Boolean disableNotification;
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard

View File

@ -30,11 +30,7 @@ public class SendSticker extends PartialBotApiMethod<Message> {
public static final String REPLYMARKUP_FIELD = "reply_markup"; public static final String REPLYMARKUP_FIELD = "reply_markup";
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
private String sticker; ///< Sticker file to send. file_id as String to resend a sticker that is already on the Telegram servers or URL to upload it private String sticker; ///< Sticker file to send. file_id as String to resend a sticker that is already on the Telegram servers or URL to upload it
/** private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
private Boolean disableNotification;
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard

View File

@ -41,12 +41,8 @@ public class SendVenue extends BotApiMethod<Message> {
private Float longitude; ///< Longitude of venue location private Float longitude; ///< Longitude of venue location
@JsonProperty(TITLE_FIELD) @JsonProperty(TITLE_FIELD)
private String title; ///< Title of the venue private String title; ///< Title of the venue
/**
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
@JsonProperty(DISABLENOTIFICATION_FIELD) @JsonProperty(DISABLENOTIFICATION_FIELD)
private Boolean disableNotification; private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(ADDRESS_FIELD) @JsonProperty(ADDRESS_FIELD)
private String address; ///< Address of the venue private String address; ///< Address of the venue
@JsonProperty(FOURSQUARE_ID_FIELD) @JsonProperty(FOURSQUARE_ID_FIELD)

View File

@ -39,11 +39,7 @@ public class SendVideo extends PartialBotApiMethod<Message> {
private String caption; ///< OptionaL. Video caption (may also be used when resending videos by file_id). private String caption; ///< OptionaL. Video caption (may also be used when resending videos by file_id).
private Integer width; ///< Optional. Video width private Integer width; ///< Optional. Video width
private Integer height; ///< OptionaL. Video height private Integer height; ///< OptionaL. Video height
/** private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
private Boolean disableNotification;
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard

View File

@ -35,11 +35,7 @@ public class SendVoice extends PartialBotApiMethod<Message> {
private String chatId; ///< Unique identifier for the chat sent message to (Or username for channels) private String chatId; ///< Unique identifier for the chat sent message to (Or username for channels)
private String voice; ///< Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data. private String voice; ///< Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
/** private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
* Optional. Sends the message silently. iOS users will not receive a notification, Android
* users will receive a notification with no sound. Other apps coming soon
*/
private Boolean disableNotification;
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private Integer duration; ///< Optional. Duration of sent audio in seconds private Integer duration; ///< Optional. Duration of sent audio in seconds

View File

@ -1,9 +1,10 @@
package org.telegram.telegrambots.api.objects; package org.telegram.telegrambots.api.objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject; import org.telegram.telegrambots.api.interfaces.BotApiObject;
import org.telegram.telegrambots.api.objects.games.Game; import org.telegram.telegrambots.api.objects.games.Game;
import org.telegram.telegrambots.api.objects.payments.Invoice;
import org.telegram.telegrambots.api.objects.payments.SuccessfulPayment;
import java.util.List; import java.util.List;
@ -32,7 +33,7 @@ public class Message implements BotApiObject {
private static final String LOCATION_FIELD = "location"; private static final String LOCATION_FIELD = "location";
private static final String VENUE_FIELD = "venue"; private static final String VENUE_FIELD = "venue";
private static final String PINNED_MESSAGE_FIELD = "pinned_message"; private static final String PINNED_MESSAGE_FIELD = "pinned_message";
private static final String NEWCHATMEMBER_FIELD = "new_chat_member"; private static final String NEWCHATMEMBERS_FIELD = "new_chat_members";
private static final String LEFTCHATMEMBER_FIELD = "left_chat_member"; private static final String LEFTCHATMEMBER_FIELD = "left_chat_member";
private static final String NEWCHATTITLE_FIELD = "new_chat_title"; private static final String NEWCHATTITLE_FIELD = "new_chat_title";
private static final String NEWCHATPHOTO_FIELD = "new_chat_photo"; private static final String NEWCHATPHOTO_FIELD = "new_chat_photo";
@ -48,6 +49,8 @@ public class Message implements BotApiObject {
private static final String EDITDATE_FIELD = "edit_date"; private static final String EDITDATE_FIELD = "edit_date";
private static final String GAME_FIELD = "game"; private static final String GAME_FIELD = "game";
private static final String FORWARDFROMMESSAGEID_FIELD = "forward_from_message_id"; private static final String FORWARDFROMMESSAGEID_FIELD = "forward_from_message_id";
private static final String INVOICE_FIELD = "invoice";
private static final String SUCCESSFUL_PAYMENT_FIELD = "successful_payment";
@JsonProperty(MESSAGEID_FIELD) @JsonProperty(MESSAGEID_FIELD)
private Integer messageId; ///< Integer Unique message identifier private Integer messageId; ///< Integer Unique message identifier
@ -89,8 +92,8 @@ public class Message implements BotApiObject {
private Venue venue; ///< Optional. Message is a venue, information about the venue private Venue venue; ///< Optional. Message is a venue, information about the venue
@JsonProperty(PINNED_MESSAGE_FIELD) @JsonProperty(PINNED_MESSAGE_FIELD)
private Message pinnedMessage; ///< Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply. private Message pinnedMessage; ///< Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
@JsonProperty(NEWCHATMEMBER_FIELD) @JsonProperty(NEWCHATMEMBERS_FIELD)
private User newChatMember; ///< Optional. A new member was added to the group, information about them (this member may be bot itself) private List<User> newChatMembers; ///< Optional. New members were added to the group or supergroup, information about them (there are may be the bot itself among them)
@JsonProperty(LEFTCHATMEMBER_FIELD) @JsonProperty(LEFTCHATMEMBER_FIELD)
private User leftChatMember; ///< Optional. A member was removed from the group, information about them (this member may be bot itself) private User leftChatMember; ///< Optional. A member was removed from the group, information about them (this member may be bot itself)
@JsonProperty(NEWCHATTITLE_FIELD) @JsonProperty(NEWCHATTITLE_FIELD)
@ -149,6 +152,10 @@ public class Message implements BotApiObject {
private Game game; ///< Optional. Message is a game, information about the game private Game game; ///< Optional. Message is a game, information about the game
@JsonProperty(FORWARDFROMMESSAGEID_FIELD) @JsonProperty(FORWARDFROMMESSAGEID_FIELD)
private Integer forwardFromMessageId; ///< Optional. For forwarded channel posts, identifier of the original message in the channel private Integer forwardFromMessageId; ///< Optional. For forwarded channel posts, identifier of the original message in the channel
@JsonProperty(INVOICE_FIELD)
private Invoice invoice; ///< Optional. Message is an invoice for a payment, information about the invoice.
@JsonProperty(SUCCESSFUL_PAYMENT_FIELD)
private SuccessfulPayment successfulPayment; ///< Optional. Message is a service message about a successful payment, information about the payment.
public Message() { public Message() {
super(); super();
@ -223,8 +230,8 @@ public class Message implements BotApiObject {
return pinnedMessage; return pinnedMessage;
} }
public User getNewChatMember() { public List<User> getNewChatMembers() {
return newChatMember; return newChatMembers;
} }
public User getLeftChatMember() { public User getLeftChatMember() {
@ -351,6 +358,22 @@ public class Message implements BotApiObject {
return photo != null && !photo.isEmpty(); return photo != null && !photo.isEmpty();
} }
public boolean hasInvoice() {
return invoice != null;
}
public boolean hasSuccessfulPayment() {
return successfulPayment != null;
}
public Invoice getInvoice() {
return invoice;
}
public SuccessfulPayment getSuccessfulPayment() {
return successfulPayment;
}
@Override @Override
public String toString() { public String toString() {
return "Message{" + return "Message{" +
@ -372,7 +395,7 @@ public class Message implements BotApiObject {
", location=" + location + ", location=" + location +
", venue=" + venue + ", venue=" + venue +
", pinnedMessage=" + pinnedMessage + ", pinnedMessage=" + pinnedMessage +
", newChatMember=" + newChatMember + ", newChatMembers=" + newChatMembers +
", leftChatMember=" + leftChatMember + ", leftChatMember=" + leftChatMember +
", newChatTitle='" + newChatTitle + '\'' + ", newChatTitle='" + newChatTitle + '\'' +
", newChatPhoto=" + newChatPhoto + ", newChatPhoto=" + newChatPhoto +
@ -388,6 +411,8 @@ public class Message implements BotApiObject {
", editDate=" + editDate + ", editDate=" + editDate +
", game=" + game + ", game=" + game +
", forwardFromMessageId=" + forwardFromMessageId + ", forwardFromMessageId=" + forwardFromMessageId +
", invoice=" + invoice +
", successfulPayment=" + successfulPayment +
'}'; '}';
} }
} }

View File

@ -5,13 +5,16 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject; import org.telegram.telegrambots.api.interfaces.BotApiObject;
import org.telegram.telegrambots.api.objects.inlinequery.ChosenInlineQuery; import org.telegram.telegrambots.api.objects.inlinequery.ChosenInlineQuery;
import org.telegram.telegrambots.api.objects.inlinequery.InlineQuery; import org.telegram.telegrambots.api.objects.inlinequery.InlineQuery;
import org.telegram.telegrambots.api.objects.payments.PreCheckoutQuery;
import org.telegram.telegrambots.api.objects.payments.ShippingQuery;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
* @brief This object represents an incoming update. *
* Only one of the optional parameters can be present in any given update. * This object represents an incoming update.
* @date 20 of June of 2015 *
* @apiNote Only one of the optional parameters can be present in any given update.
*/ */
public class Update implements BotApiObject { public class Update implements BotApiObject {
private static final String UPDATEID_FIELD = "update_id"; private static final String UPDATEID_FIELD = "update_id";
@ -22,6 +25,8 @@ public class Update implements BotApiObject {
private static final String EDITEDMESSAGE_FIELD = "edited_message"; private static final String EDITEDMESSAGE_FIELD = "edited_message";
private static final String CHANNELPOST_FIELD = "channel_post"; private static final String CHANNELPOST_FIELD = "channel_post";
private static final String EDITEDCHANNELPOST_FIELD = "edited_channel_post"; private static final String EDITEDCHANNELPOST_FIELD = "edited_channel_post";
private static final String SHIPPING_QUERY_FIELD = "shipping_query";
private static final String PRE_CHECKOUT_QUERY_FIELD = "pre_checkout_query";
@JsonProperty(UPDATEID_FIELD) @JsonProperty(UPDATEID_FIELD)
private Integer updateId; private Integer updateId;
@ -39,7 +44,10 @@ public class Update implements BotApiObject {
private Message channelPost; ///< Optional. New incoming channel post of any kind text, photo, sticker, etc. private Message channelPost; ///< Optional. New incoming channel post of any kind text, photo, sticker, etc.
@JsonProperty(EDITEDCHANNELPOST_FIELD) @JsonProperty(EDITEDCHANNELPOST_FIELD)
private Message editedChannelPost; ///< Optional. New version of a channel post that is known to the bot and was edited private Message editedChannelPost; ///< Optional. New version of a channel post that is known to the bot and was edited
@JsonProperty(SHIPPING_QUERY_FIELD)
private ShippingQuery shippingQuery; ///< Optional. New incoming shipping query. Only for invoices with flexible price
@JsonProperty(PRE_CHECKOUT_QUERY_FIELD)
private PreCheckoutQuery preCheckoutQuery; ///< Optional. New incoming pre-checkout query. Contains full information about checkout
public Update() { public Update() {
super(); super();
@ -77,6 +85,14 @@ public class Update implements BotApiObject {
return editedChannelPost; return editedChannelPost;
} }
public ShippingQuery getShippingQuery() {
return shippingQuery;
}
public PreCheckoutQuery getPreCheckoutQuery() {
return preCheckoutQuery;
}
public boolean hasMessage() { public boolean hasMessage() {
return message != null; return message != null;
} }
@ -105,6 +121,14 @@ public class Update implements BotApiObject {
return editedChannelPost != null; return editedChannelPost != null;
} }
public boolean hasShippingQuery() {
return shippingQuery != null;
}
public boolean hasPreCheckoutQuery() {
return preCheckoutQuery != null;
}
@Override @Override
public String toString() { public String toString() {
return "Update{" + return "Update{" +
@ -116,6 +140,8 @@ public class Update implements BotApiObject {
", editedMessage=" + editedMessage + ", editedMessage=" + editedMessage +
", channelPost=" + channelPost + ", channelPost=" + channelPost +
", editedChannelPost=" + editedChannelPost + ", editedChannelPost=" + editedChannelPost +
", shippingQuery=" + shippingQuery +
", preCheckoutQuery=" + preCheckoutQuery +
'}'; '}';
} }
} }

View File

@ -25,9 +25,10 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
* @brief Represents a Game *
* @note This will only work in Telegram versions released after 1 October, 2016. Older clients will ignore them. * Represents a Game
* @date 27 of September 2016 *
* @apiNote This will only work in Telegram versions released after 1 October, 2016. Older clients will ignore them.
*/ */
public class InlineQueryResultGame implements InlineQueryResult { public class InlineQueryResultGame implements InlineQueryResult {
@ -95,7 +96,8 @@ public class InlineQueryResultGame implements InlineQueryResult {
@Override @Override
public String toString() { public String toString() {
return "InlineQueryResultGame{" + return "InlineQueryResultGame{" +
"id='" + id + '\'' + "type='" + type + '\'' +
", id='" + id + '\'' +
", gameShortName='" + gameShortName + '\'' + ", gameShortName='" + gameShortName + '\'' +
", replyMarkup=" + replyMarkup + ", replyMarkup=" + replyMarkup +
'}'; '}';

View File

@ -26,6 +26,7 @@ public class InlineQueryResultGif implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption"; private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup"; private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String GIF_DURATION_FIELD = "gif_duration";
@JsonProperty(TYPE_FIELD) @JsonProperty(TYPE_FIELD)
private final String type = "gif"; ///< Type of the result, must be "gif" private final String type = "gif"; ///< Type of the result, must be "gif"
@ -47,6 +48,8 @@ public class InlineQueryResultGif implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the GIF animation private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the GIF animation
@JsonProperty(REPLY_MARKUP_FIELD) @JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(GIF_DURATION_FIELD)
private Integer gifDuration; ///< Optional. Duration of the GIF
public InlineQueryResultGif() { public InlineQueryResultGif() {
super(); super();
@ -137,6 +140,14 @@ public class InlineQueryResultGif implements InlineQueryResult {
return this; return this;
} }
public Integer getGifDuration() {
return gifDuration;
}
public void setGifDuration(Integer gifDuration) {
this.gifDuration = gifDuration;
}
@Override @Override
public void validate() throws TelegramApiValidationException { public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) { if (id == null || id.isEmpty()) {
@ -164,8 +175,9 @@ public class InlineQueryResultGif implements InlineQueryResult {
", thumbUrl='" + thumbUrl + '\'' + ", thumbUrl='" + thumbUrl + '\'' +
", title='" + title + '\'' + ", title='" + title + '\'' +
", caption='" + caption + '\'' + ", caption='" + caption + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' + ", inputMessageContent=" + inputMessageContent +
", replyMarkup='" + replyMarkup + '\'' + ", replyMarkup=" + replyMarkup +
", gifDuration=" + gifDuration +
'}'; '}';
} }
} }

View File

@ -26,6 +26,7 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption"; private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content"; private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup"; private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String MPEG4_DURATION_FIELD = "mpeg4_duration";
@JsonProperty(TYPE_FIELD) @JsonProperty(TYPE_FIELD)
private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif" private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif"
@ -47,6 +48,8 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo private InputMessageContent inputMessageContent; ///< Optional. Content of the message to be sent instead of the photo
@JsonProperty(REPLY_MARKUP_FIELD) @JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(MPEG4_DURATION_FIELD)
private Integer mpeg4Duration; ///< Optional. Video duration
public InlineQueryResultMpeg4Gif() { public InlineQueryResultMpeg4Gif() {
super(); super();
@ -137,6 +140,14 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
return this; return this;
} }
public Integer getMpeg4Duration() {
return mpeg4Duration;
}
public void setMpeg4Duration(Integer mpeg4Duration) {
this.mpeg4Duration = mpeg4Duration;
}
@Override @Override
public void validate() throws TelegramApiValidationException { public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) { if (id == null || id.isEmpty()) {
@ -164,8 +175,9 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
", thumbUrl='" + thumbUrl + '\'' + ", thumbUrl='" + thumbUrl + '\'' +
", title='" + title + '\'' + ", title='" + title + '\'' +
", caption='" + caption + '\'' + ", caption='" + caption + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' + ", inputMessageContent=" + inputMessageContent +
", replyMarkup='" + replyMarkup + '\'' + ", replyMarkup=" + replyMarkup +
", mpeg4Duration=" + mpeg4Duration +
'}'; '}';
} }
} }

View File

@ -0,0 +1,77 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
import org.telegram.telegrambots.api.objects.PhotoSize;
/**
* @author Ruben Bermudez
* @version 1.0
*
* This object contains basic information about an invoice.
*/
public class Invoice implements BotApiObject {
private static final String TITLE_FIELD = "title";
private static final String DESCRIPTION_FIELD = "description";
private static final String START_PARAMETER_FIELD = "start_parameter";
private static final String CURRENCY_FIELD = "currency";
private static final String TOTAL_AMOUNT_FIELD = "total_amount";
private static final String PHOTO_FIELD = "photo";
@JsonProperty(TITLE_FIELD)
private String title; ///< Product name
@JsonProperty(DESCRIPTION_FIELD)
private String description; ///< Product description
@JsonProperty(START_PARAMETER_FIELD)
private String startParameter; ///< Unique bot deep-linking parameter for generation of this invoice
@JsonProperty(CURRENCY_FIELD)
private String currency; ///< Three-letter ISO 4217 currency code
@JsonProperty(TOTAL_AMOUNT_FIELD)
/**
* Total price in the smallest units of the currency (integer, not float/double).
* For example, for a price of US$ 1.45 pass amount = 145.
*/
private Integer totalAmount; ///< Goods total price in minimal quantity of the currency
@JsonProperty(PHOTO_FIELD)
private PhotoSize photo; ///< Optional. Goods photo
public Invoice() {
super();
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getStartParameter() {
return startParameter;
}
public String getCurrency() {
return currency;
}
public Integer getTotalAmount() {
return totalAmount;
}
public PhotoSize getPhoto() {
return photo;
}
@Override
public String toString() {
return "Invoice{" +
"title='" + title + '\'' +
", description='" + description + '\'' +
", startParameter='" + startParameter + '\'' +
", currency='" + currency + '\'' +
", totalAmount=" + totalAmount +
", photo=" + photo +
'}';
}
}

View File

@ -0,0 +1,79 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* This object represents a portion of goods price.
*/
public class LabeledPrice implements InputBotApiObject, Validable {
private static final String LABEL_FIELD = "label";
private static final String AMOUNT_FIELD = "amount";
@JsonProperty(LABEL_FIELD)
private String label; ///< Portion label
@JsonProperty(AMOUNT_FIELD)
/**
* Price of the product in the smallest units of the currency (integer, not float/double).
* For example, for a price of US$ 1.45 pass amount = 145.
*/
private Integer amount;
/**
* Builds an empty LabeledPrice
*/
public LabeledPrice() {
super();
}
/**
* Builds a LabeledPrice with mandatory parameters
* @param label Portion label
* @param amount Currency amount in minimal quantity of the currency
*/
public LabeledPrice(String label, Integer amount) {
super();
this.label = checkNotNull(label);
this.amount = checkNotNull(amount);
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = checkNotNull(label);
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = checkNotNull(amount);
}
@Override
public void validate() throws TelegramApiValidationException {
if (label == null || label.isEmpty()) {
throw new TelegramApiValidationException("Label parameter can't be empty", this);
}
if (amount == null) {
throw new TelegramApiValidationException("Amount parameter can't be empty", this);
}
}
@Override
public String toString() {
return "LabeledPrice{" +
"label='" + label + '\'' +
", amount=" + amount +
'}';
}
}

View File

@ -0,0 +1,56 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
*
* This object represents information about an order.
*/
public class OrderInfo implements BotApiObject {
private static final String NAME_FIELD = "name";
private static final String PHONE_NUMBER_FIELD = "phone_number";
private static final String EMAIL_FIELD = "email";
private static final String SHIPPING_ADDRESS_FIELD = "shipping_address";
@JsonProperty(NAME_FIELD)
private String name; ///< Optional. User name
@JsonProperty(PHONE_NUMBER_FIELD)
private String phoneNumber; ///< Optional. User's phone number
@JsonProperty(EMAIL_FIELD)
private String email; ///< Optional. User email
@JsonProperty(SHIPPING_ADDRESS_FIELD)
private ShippingAddress shippingAddress; ///< Optional. First line for the address
public OrderInfo() {
super();
}
public String getName() {
return name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getEmail() {
return email;
}
public ShippingAddress getShippingAddress() {
return shippingAddress;
}
@Override
public String toString() {
return "OrderInfo{" +
"name='" + name + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", email='" + email + '\'' +
", shippingAddress=" + shippingAddress +
'}';
}
}

View File

@ -0,0 +1,85 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
import org.telegram.telegrambots.api.objects.User;
/**
* @author Ruben Bermudez
* @version 1.0
*
* This object contains information about incoming pre-checkout query.
*/
public class PreCheckoutQuery implements BotApiObject {
private static final String ID_FIELD = "id";
private static final String FROM_FIELD = "from";
private static final String CURRENCY_FIELD = "currency";
private static final String TOTAL_AMOUNT_FIELD = "total_amount";
private static final String INVOICE_PAYLOAD_FIELD = "invoice_payload";
private static final String SHIPPING_OPTION_ID_FIELD = "shipping_option_id";
private static final String ORDER_INFO_FIELD = "order_info";
@JsonProperty(ID_FIELD)
private String id; ///< Unique query identifier
@JsonProperty(FROM_FIELD)
private User from; ///< User who sent the query
@JsonProperty(CURRENCY_FIELD)
private String currency; ///< Three-letter ISO 4217 currency code
@JsonProperty(TOTAL_AMOUNT_FIELD)
/**
* Total price in the smallest units of the currency (integer, not float/double).
* For example, for a price of US$ 1.45 pass amount = 145.
*/
private Integer totalAmount;
@JsonProperty(INVOICE_PAYLOAD_FIELD)
private String invoicePayload; ///< Bot specified invoice payload
@JsonProperty(SHIPPING_OPTION_ID_FIELD)
private String shippingOptionId; ///< Optional. Identifier of a chosen by user shipping option
@JsonProperty(ORDER_INFO_FIELD)
private OrderInfo orderInfo; ///< Optional. Order info provided by the user
public PreCheckoutQuery() {
super();
}
public String getId() {
return id;
}
public User getFrom() {
return from;
}
public String getCurrency() {
return currency;
}
public Integer getTotalAmount() {
return totalAmount;
}
public String getInvoicePayload() {
return invoicePayload;
}
public String getShippingOptionId() {
return shippingOptionId;
}
public OrderInfo getOrderInfo() {
return orderInfo;
}
@Override
public String toString() {
return "PreCheckoutQuery{" +
"id='" + id + '\'' +
", from=" + from +
", currency='" + currency + '\'' +
", totalAmount=" + totalAmount +
", invoicePayload='" + invoicePayload + '\'' +
", shippingOptionId='" + shippingOptionId + '\'' +
", orderInfo=" + orderInfo +
'}';
}
}

View File

@ -0,0 +1,72 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
*
* 2-letter ISO 3166-1 alpha-2 country code
*/
public class ShippingAddress implements BotApiObject {
private static final String COUNTRY_CODE_FIELD = "country_code";
private static final String STATE_FIELD = "state";
private static final String CITY_FIELD = "city";
private static final String STREET_LINE1_FIELD = "street_line1";
private static final String STREET_LINE2_FIELD = "street_line2";
private static final String POST_CODE_FIELD = "post_code";
@JsonProperty(COUNTRY_CODE_FIELD)
private String countryCode; ///< Two-letter ISO 3166-1 alpha-2 country code
@JsonProperty(STATE_FIELD)
private String state; ///< State, if applicable
@JsonProperty(CITY_FIELD)
private String city; ///< City
@JsonProperty(STREET_LINE1_FIELD)
private String streetLine1; ///< First line for the address
@JsonProperty(STREET_LINE2_FIELD)
private String streetLine2; ///< Second line for the address
@JsonProperty(POST_CODE_FIELD)
private String postCode; ///< Address post code
public ShippingAddress() {
super();
}
public String getCountryCode() {
return countryCode;
}
public String getState() {
return state;
}
public String getCity() {
return city;
}
public String getStreetLine1() {
return streetLine1;
}
public String getStreetLine2() {
return streetLine2;
}
public String getPostCode() {
return postCode;
}
@Override
public String toString() {
return "ShippingAddress{" +
"countryCode='" + countryCode + '\'' +
", state='" + state + '\'' +
", city='" + city + '\'' +
", streetLine1='" + streetLine1 + '\'' +
", streetLine2='" + streetLine2 + '\'' +
", postCode='" + postCode + '\'' +
'}';
}
}

View File

@ -0,0 +1,100 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
*
* This object represents one shipping option.
*/
public class ShippingOption implements InputBotApiObject, Validable {
private static final String ID_FIELD = "id";
private static final String TITLE_FIELD = "title";
private static final String PRICES_FIELD = "prices";
@JsonProperty(ID_FIELD)
private String id; ///< Shipping option identifier
@JsonProperty(TITLE_FIELD)
private String title; ///< Option title
@JsonProperty(PRICES_FIELD)
private List<LabeledPrice> prices; ///< List of price portions
/**
* Creates an empty shipping option
*/
public ShippingOption() {
super();
}
/**
* Creates a shipping option with mandatory fields
* @param id Shipping option identifier
* @param title Option title
* @param prices List of price portions
*/
public ShippingOption(String id, String title, List<LabeledPrice> prices) {
this.id = checkNotNull(id);
this.title = checkNotNull(title);
this.prices = checkNotNull(prices);
}
public String getId() {
return id;
}
public ShippingOption setId(String id) {
this.id = checkNotNull(id);
return this;
}
public String getTitle() {
return title;
}
public ShippingOption setTitle(String title) {
this.title = checkNotNull(title);
return this;
}
public List<LabeledPrice> getPrices() {
return prices;
}
public ShippingOption setPrices(List<LabeledPrice> prices) {
this.prices = checkNotNull(prices);
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
throw new TelegramApiValidationException("Id parameter can't be empty", this);
}
if (title == null || title.isEmpty()) {
throw new TelegramApiValidationException("Title parameter can't be empty", this);
}
if (prices == null || prices.isEmpty()) {
throw new TelegramApiValidationException("Prices parameter can't be empty", this);
}
for (LabeledPrice price : prices) {
price.validate();
}
}
@Override
public String toString() {
return "ShippingOption{" +
"id='" + id + '\'' +
", title='" + title + '\'' +
", prices=" + prices +
'}';
}
}

View File

@ -0,0 +1,57 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
import org.telegram.telegrambots.api.objects.User;
/**
* @author Ruben Bermudez
* @version 1.0
*
* This object contains information about incoming shipping query.
*/
public class ShippingQuery implements BotApiObject {
private static final String ID_FIELD = "id";
private static final String FROM_FIELD = "from";
private static final String INVOICE_PAYLOAD_FIELD = "invoice_payload";
private static final String SHIPPING_ADDRESS_FIELD = "shipping_address";
@JsonProperty(ID_FIELD)
private String id; ///< Unique query identifier
@JsonProperty(FROM_FIELD)
private User from; ///< User who sent the query
@JsonProperty(INVOICE_PAYLOAD_FIELD)
private String invoicePayload; ///< Bot specified invoice payload
@JsonProperty(SHIPPING_ADDRESS_FIELD)
private ShippingAddress shippingAddress; ///< User specified shipping address
public ShippingQuery() {
super();
}
public String getId() {
return id;
}
public User getFrom() {
return from;
}
public String getInvoicePayload() {
return invoicePayload;
}
public ShippingAddress getShippingAddress() {
return shippingAddress;
}
@Override
public String toString() {
return "ShippingQuery{" +
"id='" + id + '\'' +
", from=" + from +
", invoicePayload='" + invoicePayload + '\'' +
", shippingAddress=" + shippingAddress +
'}';
}
}

View File

@ -0,0 +1,84 @@
package org.telegram.telegrambots.api.objects.payments;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
*
* This object contains basic information about a successful payment.
*/
public class SuccessfulPayment implements BotApiObject {
private static final String CURRENCY_FIELD = "currency";
private static final String TOTAL_AMOUNT_FIELD = "total_amount";
private static final String INVOICE_PAYLOAD_FIELD = "invoice_payload";
private static final String SHIPPING_OPTION_ID_FIELD = "shipping_option_id";
private static final String ORDER_INFO_FIELD = "order_info";
private static final String TELEGRAM_PAYMENT_CHARGE_ID_FIELD = "telegram_payment_charge_id";
private static final String PROVIDER_PAYMENT_CHARGE_ID_FIELD = "provider_payment_charge_id";
@JsonProperty(CURRENCY_FIELD)
private String currency; ///< Three-letter ISO 4217 currency code
@JsonProperty(TOTAL_AMOUNT_FIELD)
/**
* Total price in the smallest units of the currency (integer, not float/double).
* For example, for a price of US$ 1.45 pass amount = 145.
*/
private Integer totalAmount;
@JsonProperty(INVOICE_PAYLOAD_FIELD)
private String invoicePayload; ///< Bot specified invoice payload
@JsonProperty(SHIPPING_OPTION_ID_FIELD)
private String shippingOptionId; ///< Optional. Identifier of a chosen by user shipping option
@JsonProperty(ORDER_INFO_FIELD)
private OrderInfo orderInfo; ///< Optional. Order info provided by the user
@JsonProperty(TELEGRAM_PAYMENT_CHARGE_ID_FIELD)
private String telegramPaymentChargeId; ///< Telegram payment identifier
@JsonProperty(PROVIDER_PAYMENT_CHARGE_ID_FIELD)
private String providerPaymentChargeId; ///< Provider payment identifier
public SuccessfulPayment() {
super();
}
public String getCurrency() {
return currency;
}
public Integer getTotalAmount() {
return totalAmount;
}
public String getInvoicePayload() {
return invoicePayload;
}
public String getShippingOptionId() {
return shippingOptionId;
}
public OrderInfo getOrderInfo() {
return orderInfo;
}
public String getTelegramPaymentChargeId() {
return telegramPaymentChargeId;
}
public String getProviderPaymentChargeId() {
return providerPaymentChargeId;
}
@Override
public String toString() {
return "SuccessfulPayment{" +
"currency='" + currency + '\'' +
", totalAmount=" + totalAmount +
", invoicePayload='" + invoicePayload + '\'' +
", shippingOptionId='" + shippingOptionId + '\'' +
", orderInfo=" + orderInfo +
", telegramPaymentChargeId='" + telegramPaymentChargeId + '\'' +
", providerPaymentChargeId='" + providerPaymentChargeId + '\'' +
'}';
}
}

View File

@ -26,7 +26,7 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
@JsonProperty(RESIZEKEYBOARD_FIELD) @JsonProperty(RESIZEKEYBOARD_FIELD)
private Boolean resizeKeyboard; ///< Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false. private Boolean resizeKeyboard; ///< Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false.
@JsonProperty(ONETIMEKEYBOARD_FIELD) @JsonProperty(ONETIMEKEYBOARD_FIELD)
private Boolean oneTimeKeyboad; ///< Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. private Boolean oneTimeKeyboard; ///< Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false.
/** /**
* Optional. Use this parameter if you want to show the keyboard to specific users only. * Optional. Use this parameter if you want to show the keyboard to specific users only.
* Targets: * Targets:
@ -59,12 +59,12 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
return this; return this;
} }
public Boolean getOneTimeKeyboad() { public Boolean getOneTimeKeyboard() {
return oneTimeKeyboad; return oneTimeKeyboard;
} }
public ReplyKeyboardMarkup setOneTimeKeyboad(Boolean oneTimeKeyboad) { public ReplyKeyboardMarkup setOneTimeKeyboard(Boolean oneTimeKeyboard) {
this.oneTimeKeyboad = oneTimeKeyboad; this.oneTimeKeyboard = oneTimeKeyboard;
return this; return this;
} }
@ -92,7 +92,7 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
return "ReplyKeyboardMarkup{" + return "ReplyKeyboardMarkup{" +
"keyboard=" + keyboard + "keyboard=" + keyboard +
", resizeKeyboard=" + resizeKeyboard + ", resizeKeyboard=" + resizeKeyboard +
", oneTimeKeyboad=" + oneTimeKeyboad + ", oneTimeKeyboard=" + oneTimeKeyboard +
", selective=" + selective + ", selective=" + selective +
'}'; '}';
} }

View File

@ -14,7 +14,6 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
* optional fields. * optional fields.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will * @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* display unsupported message. * display unsupported message.
* @date 10 of April of 2016
*/ */
public class InlineKeyboardButton implements InputBotApiObject, Validable { public class InlineKeyboardButton implements InputBotApiObject, Validable {
@ -24,6 +23,7 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
private static final String CALLBACK_GAME_FIELD = "callback_game"; private static final String CALLBACK_GAME_FIELD = "callback_game";
private static final String SWITCH_INLINE_QUERY_FIELD = "switch_inline_query"; private static final String SWITCH_INLINE_QUERY_FIELD = "switch_inline_query";
private static final String SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD = "switch_inline_query_current_chat"; private static final String SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD = "switch_inline_query_current_chat";
private static final String BUY_FIELD = "buy";
@JsonProperty(TEXT_FIELD) @JsonProperty(TEXT_FIELD)
private String text; ///< Label text on the button private String text; ///< Label text on the button
@ -43,7 +43,8 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
* If set, pressing the button will prompt the user to select one of their chats, * If set, pressing the button will prompt the user to select one of their chats,
* open that chat and insert the bots username and the specified inline query in the input field. * open that chat and insert the bots username and the specified inline query in the input field.
* Can be empty, in which case just the bots username will be inserted. * Can be empty, in which case just the bots username will be inserted.
* @note: This offers an easy way for users to start using your bot in inline mode when *
* @note This offers an easy way for users to start using your bot in inline mode when
* they are currently in a private chat with it. * they are currently in a private chat with it.
* Especially useful when combined with switch_pm actions in this case the user will * Especially useful when combined with switch_pm actions in this case the user will
* be automatically returned to the chat they switched from, skipping the chat selection screen. * be automatically returned to the chat they switched from, skipping the chat selection screen.
@ -58,6 +59,14 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
@JsonProperty(SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD) @JsonProperty(SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD)
private String switchInlineQueryCurrentChat; private String switchInlineQueryCurrentChat;
/**
* Optional. Specify True, to send a Buy button.
*
* @note This type of button must always be the first button in the first row.
*/
@JsonProperty(BUY_FIELD)
private Boolean buy;
public InlineKeyboardButton() { public InlineKeyboardButton() {
super(); super();
} }
@ -116,6 +125,15 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
return this; return this;
} }
public Boolean getBuy() {
return buy;
}
public InlineKeyboardButton setBuy(Boolean buy) {
this.buy = buy;
return this;
}
@Override @Override
public void validate() throws TelegramApiValidationException { public void validate() throws TelegramApiValidationException {
if (text == null || text.isEmpty()) { if (text == null || text.isEmpty()) {
@ -132,6 +150,7 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
", callbackGame=" + callbackGame + ", callbackGame=" + callbackGame +
", switchInlineQuery='" + switchInlineQuery + '\'' + ", switchInlineQuery='" + switchInlineQuery + '\'' +
", switchInlineQueryCurrentChat='" + switchInlineQueryCurrentChat + '\'' + ", switchInlineQueryCurrentChat='" + switchInlineQueryCurrentChat + '\'' +
", buy=" + buy +
'}'; '}';
} }
} }

View File

@ -1,45 +1,16 @@
package org.telegram.telegrambots.bots; package org.telegram.telegrambots.bots;
import org.telegram.telegrambots.api.methods.AnswerCallbackQuery; import org.telegram.telegrambots.api.methods.*;
import org.telegram.telegrambots.api.methods.AnswerInlineQuery;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.methods.ForwardMessage;
import org.telegram.telegrambots.api.methods.GetFile;
import org.telegram.telegrambots.api.methods.GetMe;
import org.telegram.telegrambots.api.methods.GetUserProfilePhotos;
import org.telegram.telegrambots.api.methods.games.GetGameHighScores; import org.telegram.telegrambots.api.methods.games.GetGameHighScores;
import org.telegram.telegrambots.api.methods.games.SetGameScore; import org.telegram.telegrambots.api.methods.games.SetGameScore;
import org.telegram.telegrambots.api.methods.groupadministration.GetChat; import org.telegram.telegrambots.api.methods.groupadministration.*;
import org.telegram.telegrambots.api.methods.groupadministration.GetChatAdministrators; import org.telegram.telegrambots.api.methods.send.*;
import org.telegram.telegrambots.api.methods.groupadministration.GetChatMember;
import org.telegram.telegrambots.api.methods.groupadministration.GetChatMemberCount;
import org.telegram.telegrambots.api.methods.groupadministration.KickChatMember;
import org.telegram.telegrambots.api.methods.groupadministration.LeaveChat;
import org.telegram.telegrambots.api.methods.groupadministration.UnbanChatMember;
import org.telegram.telegrambots.api.methods.send.SendAudio;
import org.telegram.telegrambots.api.methods.send.SendChatAction;
import org.telegram.telegrambots.api.methods.send.SendContact;
import org.telegram.telegrambots.api.methods.send.SendDocument;
import org.telegram.telegrambots.api.methods.send.SendGame;
import org.telegram.telegrambots.api.methods.send.SendLocation;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.methods.send.SendPhoto;
import org.telegram.telegrambots.api.methods.send.SendSticker;
import org.telegram.telegrambots.api.methods.send.SendVenue;
import org.telegram.telegrambots.api.methods.send.SendVideo;
import org.telegram.telegrambots.api.methods.send.SendVoice;
import org.telegram.telegrambots.api.methods.updates.DeleteWebhook; import org.telegram.telegrambots.api.methods.updates.DeleteWebhook;
import org.telegram.telegrambots.api.methods.updates.GetWebhookInfo; import org.telegram.telegrambots.api.methods.updates.GetWebhookInfo;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageCaption; import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageCaption;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageReplyMarkup; import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageReplyMarkup;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageText; import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.api.objects.Chat; import org.telegram.telegrambots.api.objects.*;
import org.telegram.telegrambots.api.objects.ChatMember;
import org.telegram.telegrambots.api.objects.File;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.User;
import org.telegram.telegrambots.api.objects.UserProfilePhotos;
import org.telegram.telegrambots.api.objects.WebhookInfo;
import org.telegram.telegrambots.api.objects.games.GameHighScore; import org.telegram.telegrambots.api.objects.games.GameHighScore;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.exceptions.TelegramApiException;
import org.telegram.telegrambots.updateshandlers.SentCallback; import org.telegram.telegrambots.updateshandlers.SentCallback;
@ -249,6 +220,27 @@ public abstract class AbsSender {
return sendApiMethod(deleteWebhook); return sendApiMethod(deleteWebhook);
} }
public final Message sendInvoice(SendInvoice sendInvoice) throws TelegramApiException {
if(sendInvoice == null){
throw new TelegramApiException("Parameter sendInvoice can not be null");
}
return sendApiMethod(sendInvoice);
}
public final Boolean answerShippingQuery(AnswerShippingQuery answerShippingQuery) throws TelegramApiException {
if(answerShippingQuery == null){
throw new TelegramApiException("Parameter answerShippingQuery can not be null");
}
return sendApiMethod(answerShippingQuery);
}
public final Boolean answerPreCheckoutQuery(AnswerPreCheckoutQuery answerPreCheckoutQuery) throws TelegramApiException {
if(answerPreCheckoutQuery == null){
throw new TelegramApiException("Parameter answerPreCheckoutQuery can not be null");
}
return sendApiMethod(answerPreCheckoutQuery);
}
// Send Requests Async // Send Requests Async
public final void sendMessageAsync(SendMessage sendMessage, SentCallback<Message> sentCallback) throws TelegramApiException { public final void sendMessageAsync(SendMessage sendMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
@ -530,6 +522,36 @@ public abstract class AbsSender {
sendApiMethodAsync(deleteWebhook, sentCallback); sendApiMethodAsync(deleteWebhook, sentCallback);
} }
public final void sendInvoice(SendInvoice sendInvoice, SentCallback<Message> sentCallback) throws TelegramApiException {
if (sendInvoice == null) {
throw new TelegramApiException("Parameter sendInvoice can not be null");
}
if (sentCallback == null) {
throw new TelegramApiException("Parameter sentCallback can not be null");
}
sendApiMethodAsync(sendInvoice, sentCallback);
}
public final void answerShippingQuery(AnswerShippingQuery answerShippingQuery, SentCallback<Boolean> sentCallback) throws TelegramApiException {
if (answerShippingQuery == null) {
throw new TelegramApiException("Parameter answerShippingQuery can not be null");
}
if (sentCallback == null) {
throw new TelegramApiException("Parameter sentCallback can not be null");
}
sendApiMethodAsync(answerShippingQuery, sentCallback);
}
public final void answerPreCheckoutQuery(AnswerPreCheckoutQuery answerPreCheckoutQuery, SentCallback<Boolean> sentCallback) throws TelegramApiException {
if (answerPreCheckoutQuery == null) {
throw new TelegramApiException("Parameter answerPreCheckoutQuery can not be null");
}
if (sentCallback == null) {
throw new TelegramApiException("Parameter sentCallback can not be null");
}
sendApiMethodAsync(answerPreCheckoutQuery, sentCallback);
}
// Specific Send Requests // Specific Send Requests
public abstract Message sendDocument(SendDocument sendDocument) throws TelegramApiException; public abstract Message sendDocument(SendDocument sendDocument) throws TelegramApiException;

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>2.4.4.5</version> <version>2.4.4.6</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Telegram Bots</name> <name>Telegram Bots</name>
@ -66,7 +66,7 @@
<jackson.version>2.8.7</jackson.version> <jackson.version>2.8.7</jackson.version>
<jacksonanotation.version>2.8.0</jacksonanotation.version> <jacksonanotation.version>2.8.0</jacksonanotation.version>
<commonio.version>2.5</commonio.version> <commonio.version>2.5</commonio.version>
<bots.version>2.4.4.5</bots.version> <bots.version>2.4.4.6</bots.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -305,6 +305,17 @@
</rules> </rules>
</configuration> </configuration>
</plugin> </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> </plugins>
<pluginManagement> <pluginManagement>
<plugins> <plugins>

View File

@ -45,6 +45,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
@ -72,6 +74,13 @@ public abstract class DefaultAbsSender extends AbsSender {
.build(); .build();
requestConfig = options.getRequestConfig(); requestConfig = options.getRequestConfig();
if (requestConfig == null) {
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
.setSocketTimeout(SOCKET_TIMEOUT)
.setConnectTimeout(SOCKET_TIMEOUT)
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
}
} }
/** /**

View File

@ -18,12 +18,7 @@ import org.telegram.telegrambots.api.methods.groupadministration.GetChatMemberCo
import org.telegram.telegrambots.api.methods.groupadministration.KickChatMember; import org.telegram.telegrambots.api.methods.groupadministration.KickChatMember;
import org.telegram.telegrambots.api.methods.groupadministration.LeaveChat; import org.telegram.telegrambots.api.methods.groupadministration.LeaveChat;
import org.telegram.telegrambots.api.methods.groupadministration.UnbanChatMember; import org.telegram.telegrambots.api.methods.groupadministration.UnbanChatMember;
import org.telegram.telegrambots.api.methods.send.SendChatAction; import org.telegram.telegrambots.api.methods.send.*;
import org.telegram.telegrambots.api.methods.send.SendContact;
import org.telegram.telegrambots.api.methods.send.SendGame;
import org.telegram.telegrambots.api.methods.send.SendLocation;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.methods.send.SendVenue;
import org.telegram.telegrambots.api.methods.updates.GetWebhookInfo; import org.telegram.telegrambots.api.methods.updates.GetWebhookInfo;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageCaption; import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageCaption;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageReplyMarkup; import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageReplyMarkup;
@ -33,6 +28,7 @@ import org.telegram.telegrambots.api.objects.inlinequery.inputmessagecontent.Inp
import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResult; import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResultArticle; import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResultArticle;
import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResultPhoto; import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResultPhoto;
import org.telegram.telegrambots.api.objects.payments.LabeledPrice;
import org.telegram.telegrambots.api.objects.replykeyboard.ForceReplyKeyboard; import org.telegram.telegrambots.api.objects.replykeyboard.ForceReplyKeyboard;
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup; import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard; import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
@ -191,7 +187,7 @@ public final class BotApiMethodHelperFactory {
private static ReplyKeyboard getKeyboardMarkup() { private static ReplyKeyboard getKeyboardMarkup() {
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(); ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
keyboardMarkup.setResizeKeyboard(true); keyboardMarkup.setResizeKeyboard(true);
keyboardMarkup.setOneTimeKeyboad(true); keyboardMarkup.setOneTimeKeyboard(true);
keyboardMarkup.setSelective(true); keyboardMarkup.setSelective(true);
List<KeyboardRow> keyboard = new ArrayList<>(); List<KeyboardRow> keyboard = new ArrayList<>();
KeyboardRow row = new KeyboardRow(); KeyboardRow row = new KeyboardRow();
@ -289,4 +285,19 @@ public final class BotApiMethodHelperFactory {
.setChatId("12345") .setChatId("12345")
.setUserId(98765); .setUserId(98765);
} }
public static BotApiMethod getSendInvoice() {
List<LabeledPrice> prices = new ArrayList<>();
prices.add(new LabeledPrice("LABEL", 1000));
return new SendInvoice()
.setChatId(12345)
.setTitle("Random title")
.setDescription("Random description")
.setPayload("Random Payload")
.setProviderToken("Random provider token")
.setStartParameter("STARTPARAM")
.setCurrency("EUR")
.setPrices(prices);
}
} }

View File

@ -392,6 +392,23 @@ public class TestRestApi extends JerseyTest {
assertEquals("{\"chat_id\":\"12345\",\"user_id\":98765,\"method\":\"unbanchatmember\"}", map(result)); assertEquals("{\"chat_id\":\"12345\",\"user_id\":98765,\"method\":\"unbanchatmember\"}", map(result));
} }
@Test
public void TestSendInvoice() {
webhookBot.setReturnValue(BotApiMethodHelperFactory.getSendInvoice());
Entity<Update> entity = Entity.json(getUpdate());
BotApiMethod result =
target("callback/testbot")
.request(MediaType.APPLICATION_JSON)
.post(entity, SendInvoice.class);
assertEquals("{\"chat_id\":12345,\"title\":\"Random title\",\"description\":\"Random description\"" +
",\"payload\":\"Random Payload\",\"provider_token\":\"Random provider token\",\"start_parameter\":" +
"\"STARTPARAM\",\"currency\":\"EUR\",\"prices\":[{\"@class\":" +
"\"org.telegram.telegrambots.api.objects.payments.LabeledPrice\",\"label\":\"LABEL\"," +
"\"amount\":1000}],\"method\":\"sendinvoice\"}", map(result));
}
private Update getUpdate() { private Update getUpdate() {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {