Merge pull request #241 from rubenlagus/dev

Dev 3.0 to Master
This commit is contained in:
dapoldi 2017-05-19 09:20:05 +02:00 committed by GitHub
commit f574c27464
54 changed files with 2181 additions and 171 deletions

View File

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

View File

@ -42,4 +42,15 @@
3. Added new How to send photos by file_id to FAQ.
4. Added reference to new gitbook about this library.
5. Added custom ExponentialBackOff waiting time when having network problems in long-polling mode. (Custom implementation is allowed via BotOptions)
3. Bug fixing: #184, #183
6. Bug fixing: #184, #183
### <a id="3.0"></a>3.0 ###
1. New field `gif_duration` and `mpeg4_duration` in `InlineQueryResultGif` and `InlineQueryResultMpeg4Gif`.
2. Field `new_chat_member` was replaced by `new_chat_members` in `Message` object.
3. Some methods gets now constructors with mandatory parameters to simplify their creation (including preconditions).
4. New `deleteMessage` method.
5. New field `language_code` in `User` object.
6. New Payments API methods
7. New Video Messages API methods
**[[How to update to version 3.0|How-To-Update#3.0]]**

View File

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

View File

@ -1,3 +1,3 @@
Welcome to the TelegramBots wiki. Use the sidebar on the right. If you're not sure what to look at, why not take a look at the [[Getting Started|Getting-Started]] guide?
If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://www.gitbook.com/button/status/book/monsterdeveloper/writing-telegram-bots-on-java)
If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://www.gitbook.com/book/monsterdeveloper/writing-telegram-bots-on-java/details)

View File

@ -20,4 +20,7 @@
### <a id="2.4.4.4"></a>To version 2.4.4.4 ###
1. All calls to `editMessageText`, `editMessageCaption` or `editMessageReplyMarkup` in `AbsSender` return value is changed to `Serializable`
2. In `editMessageTextAsync`, `editMessageCaptionAsync` or `editMessageReplyMarkupAsync` in `AbsSender`, second parameter should become `SentCallback<Serializable>` due to new return type.
2. In `editMessageTextAsync`, `editMessageCaptionAsync` or `editMessageReplyMarkupAsync` in `AbsSender`, second parameter should become `SentCallback<Serializable>` due to new return type.
### <a id="3.0"></a>To version 3.0 ###
1. In `Message` object, field `new_chat_member` was replaced by `new_chat_members` that is now an array of users.

View File

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

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>2.4.4.5</version>
<version>3.0</version>
<packaging>jar</packaging>
<name>Telegram Bots Meta</name>
@ -228,6 +228,17 @@
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>

View File

@ -3,8 +3,7 @@ package org.telegram.telegrambots;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Constants needed for Telegram Bots API
* @date 20 of June of 2015
* Constants needed for Telegram Bots API
*/
public class ApiConstants {
public static final String BASE_URL = "https://api.telegram.org/bot";

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

@ -14,10 +14,9 @@ import java.util.Objects;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to unban a previously kicked user in a supergroup. The user will not
* Use this method to unban a previously kicked user in a supergroup. The user will not
* return to the group automatically, but will be able to join via link, etc. The bot must be an
* administrator in the group for this to work. Returns True on success.
* @date 10 of April of 2016
*/
public class UnbanChatMember extends BotApiMethod<Boolean> {
public static final String PATH = "unbanchatmember";

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 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
/**
* 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 Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private String performer; ///< Optional. Performer of sent audio
private String title; ///< Optional. Title of sent audio

View File

@ -13,13 +13,14 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method when you need to tell the user that something is happening on the bot's
* Use this method when you need to tell the user that something is happening on the bot's
* side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram
* clients clear its typing status).
* @date 20 of June of 2015
*/
public class SendChatAction extends BotApiMethod<Boolean> {
@ -31,10 +32,10 @@ public class SendChatAction extends BotApiMethod<Boolean> {
@JsonProperty(CHATID_FIELD)
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
/**
* Type of action to broadcast. Choose one, depending on what the user is about to receive:
* 'typing' for text messages 'upload_photo' for photos 'record_video' or 'upload_video' for
* videos 'record_audio' or 'upload_audio' for audio files 'upload_document' for general files,
* 'find_location' for location data.
* Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages,
* upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files,
* upload_document for general files, find_location for location data,
* record_video_note or upload_video_note for video notes.
*/
@JsonProperty(ACTION_FIELD)
private String action;
@ -43,6 +44,16 @@ public class SendChatAction extends BotApiMethod<Boolean> {
super();
}
public SendChatAction(String chatId, String action) {
this.chatId = checkNotNull(chatId);
this.action = checkNotNull(action);
}
public SendChatAction(Long chatId, String action) {
this.chatId = checkNotNull(chatId).toString();
this.action = checkNotNull(action);
}
public String getChatId() {
return chatId;
}

View File

@ -39,12 +39,8 @@ public class SendContact extends BotApiMethod<Message> {
private String firstName; ///< User's first name
@JsonProperty(LAST_NAME_FIELD)
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)
private Boolean disableNotification;
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@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 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
/**
* 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 Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
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

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)
@JsonProperty(GAMESHORTNAME_FIELD)
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)
private Boolean disableNotification;
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@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
@JsonProperty(LONGITUDE_FIELD)
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)
private Boolean disableNotification;
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD)

View File

@ -14,11 +14,12 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Use this method to send text messages. On success, the sent Message is returned.
* @date 20 of June of 2015
* Use this method to send text messages. On success, the sent Message is returned.
*/
public class SendMessage extends BotApiMethod<Message> {
public static final String PATH = "sendmessage";
@ -39,12 +40,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.
@JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD)
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)
private Boolean disableNotification;
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(REPLYTOMESSAGEID_FIELD)
private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message
@JsonProperty(REPLYMARKUP_FIELD)
@ -54,6 +51,16 @@ public class SendMessage extends BotApiMethod<Message> {
super();
}
public SendMessage(String chatId, String text) {
this.chatId = checkNotNull(chatId);
this.text = checkNotNull(text);
}
public SendMessage(Long chatId, String text) {
this.chatId = checkNotNull(chatId).toString();
this.text = checkNotNull(text);
}
public String getChatId() {
return chatId;
}

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 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).
/**
* 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 Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
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

View File

@ -30,11 +30,7 @@ public class SendSticker extends PartialBotApiMethod<Message> {
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 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
/**
* 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 Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
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

View File

@ -41,12 +41,8 @@ public class SendVenue extends BotApiMethod<Message> {
private Float longitude; ///< Longitude of venue location
@JsonProperty(TITLE_FIELD)
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)
private Boolean disableNotification;
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
@JsonProperty(ADDRESS_FIELD)
private String address; ///< Address of the venue
@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 Integer width; ///< Optional. Video width
private Integer height; ///< OptionaL. Video height
/**
* 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 Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
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

View File

@ -0,0 +1,282 @@
package org.telegram.telegrambots.api.methods.send;
import com.fasterxml.jackson.core.type.TypeReference;
import org.telegram.telegrambots.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.replykeyboard.ApiResponse;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
* As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
* Use this method to send video messages. On success, the sent Message is returned.
*/
public class SendVideoNote extends PartialBotApiMethod<Message> {
public static final String PATH = "sendvideonote";
public static final String CHATID_FIELD = "chat_id";
public static final String VIDEONOTE_FIELD = "video_note";
public static final String DURATION_FIELD = "duration";
public static final String LENGTH_FIELD = "length";
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
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 videoNote; ///< Videonote to send. file_id as String to resend a video that is already on the Telegram servers.
private Integer duration; ///< Optional. Duration of sent video in seconds
private Integer length; ///< Optional. Video width and height
private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
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 boolean isNewVideoNote; ///< True to upload a new video note, false to use a fileId
private String videoNoteName; ///< Name of the video
private File newVideoNoteFile; ///< New video note file
private InputStream newVideoNoteStream; ///< New video note stream
public SendVideoNote() {
super();
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNote Video note file_id to send
*/
public SendVideoNote(String chatId, String videoNote) {
this.chatId = checkNotNull(chatId);
this.videoNote = checkNotNull(videoNote);
this.isNewVideoNote = false;
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNote Video note file_id to send
*/
public SendVideoNote(Long chatId, String videoNote) {
this.chatId = checkNotNull(chatId).toString();
this.videoNote = checkNotNull(videoNote);
this.isNewVideoNote = false;
}
/**
* Creates a new video note with a new video note
* @param chatId Chat Id to send the video note
* @param newVideoNoteFile Video note file to upload
*/
public SendVideoNote(String chatId, File newVideoNoteFile) {
this.chatId = checkNotNull(chatId);
this.newVideoNoteFile = checkNotNull(newVideoNoteFile);
this.isNewVideoNote = true;
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param newVideoNoteFile Video note file to upload
*/
public SendVideoNote(Integer chatId, File newVideoNoteFile) {
this.chatId = checkNotNull(chatId).toString();
this.newVideoNoteFile = checkNotNull(newVideoNoteFile);
this.isNewVideoNote = true;
}
/**
* Creates a new video note with a new video note
* @param chatId Chat Id to send the video note
* @param videoNoteName Name of the video note file
* @param newVideoNoteStream Video note file to upload
*/
public SendVideoNote(String chatId, String videoNoteName, InputStream newVideoNoteStream) {
this.chatId = checkNotNull(chatId);
this.videoNoteName = checkNotNull(videoNoteName);
this.newVideoNoteStream = checkNotNull(newVideoNoteStream);
this.isNewVideoNote = true;
}
/**
* Creates a new video note with a video already present in telegram servers
* @param chatId Chat Id to send the video note
* @param videoNoteName Name of the video note file
* @param newVideoNoteStream Video note file to upload
*/
public SendVideoNote(Integer chatId, String videoNoteName, InputStream newVideoNoteStream) {
this.chatId = checkNotNull(chatId).toString();
this.videoNoteName = checkNotNull(videoNoteName);
this.newVideoNoteStream = checkNotNull(newVideoNoteStream);
this.isNewVideoNote = true;
}
public String getChatId() {
return chatId;
}
public SendVideoNote setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public String getVideoNote() {
return videoNote;
}
public SendVideoNote setVideoNote(String videoNote) {
this.videoNote = videoNote;
this.isNewVideoNote = false;
return this;
}
public Integer getLength() {
return length;
}
public SendVideoNote setLength(Integer length) {
this.length = length;
return this;
}
public SendVideoNote setChatId(Long chatId) {
Objects.requireNonNull(chatId);
this.chatId = chatId.toString();
return this;
}
public Integer getDuration() {
return duration;
}
public SendVideoNote setDuration(Integer duration) {
this.duration = duration;
return this;
}
public Integer getReplyToMessageId() {
return replyToMessageId;
}
public SendVideoNote setReplyToMessageId(Integer replyToMessageId) {
this.replyToMessageId = replyToMessageId;
return this;
}
public ReplyKeyboard getReplyMarkup() {
return replyMarkup;
}
public SendVideoNote setReplyMarkup(ReplyKeyboard replyMarkup) {
this.replyMarkup = replyMarkup;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public SendVideoNote enableNotification() {
this.disableNotification = false;
return this;
}
public SendVideoNote disableNotification() {
this.disableNotification = true;
return this;
}
public boolean isNewVideoNote() {
return isNewVideoNote;
}
public SendVideoNote setNewVideoNote(File file) {
this.isNewVideoNote = true;
this.newVideoNoteFile = file;
return this;
}
public SendVideoNote setNewVideo(String videoName, InputStream inputStream) {
Objects.requireNonNull(videoName, "videoName cannot be null!");
Objects.requireNonNull(inputStream, "inputStream cannot be null!");
this.videoNoteName = videoName;
this.isNewVideoNote = true;
this.newVideoNoteStream = inputStream;
return this;
}
public String getVideoNoteName() {
return videoNoteName;
}
public File getNewVideoNoteFile() {
return newVideoNoteFile;
}
public InputStream getNewVideoNoteStream() {
return newVideoNoteStream;
}
@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 video", 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 (isNewVideoNote) {
if (newVideoNoteFile == null && newVideoNoteStream == null) {
throw new TelegramApiValidationException("Videonote can't be empty", this);
}
if (newVideoNoteStream != null && (videoNoteName == null || videoNoteName.isEmpty())) {
throw new TelegramApiValidationException("Video note name can't be empty", this);
}
} else if (videoNote == null) {
throw new TelegramApiValidationException("Video note can't be empty", this);
}
if (replyMarkup != null) {
replyMarkup.validate();
}
}
@Override
public String toString() {
return "SendVideoNote{" +
"chatId='" + chatId + '\'' +
", videoNote='" + videoNote + '\'' +
", duration=" + duration +
", length=" + length +
", disableNotification=" + disableNotification +
", replyToMessageId=" + replyToMessageId +
", replyMarkup=" + replyMarkup +
", isNewVideoNote=" + isNewVideoNote +
", videoNoteName='" + videoNoteName + '\'' +
", newVideoNoteFile=" + newVideoNoteFile +
", newVideoNoteStream=" + newVideoNoteStream +
'}';
}
}

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 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.
/**
* 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 Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound.
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 Integer duration; ///< Optional. Duration of sent audio in seconds

View File

@ -0,0 +1,112 @@
package org.telegram.telegrambots.api.methods.updatingmessages;
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.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
*
* Use this method to delete a message. A message can only be deleted if it was sent less than
* 48 hours ago. Any sent outgoing message may be deleted.
* Additionally, if the bot is an administrator in a group chat, it can delete any message.
* If the bot is an administrator of a supergroup or channel,
* it can delete ordinary messages from any other user,
* including service messages about people added or removed from the chat.
*/
public class DeleteMessage extends BotApiMethod<Boolean> {
public static final String PATH = "deleteMessage";
private static final String CHATID_FIELD = "chat_id";
private static final String MESSAGEID_FIELD = "message_id";
/**
* Unique identifier for the chat to send the message to (Or username for channels)
*/
@JsonProperty(CHATID_FIELD)
private String chatId;
/**
* Identifier of the message to delete
*/
@JsonProperty(MESSAGEID_FIELD)
private Integer messageId;
public DeleteMessage() {
super();
}
public DeleteMessage(String chatId, Integer messageId) {
this.chatId = checkNotNull(chatId);
this.messageId = checkNotNull(messageId);
}
public DeleteMessage(Long chatId, Integer messageId) {
this.chatId = checkNotNull(chatId).toString();
this.messageId = checkNotNull(messageId);
}
public String getChatId() {
return chatId;
}
public DeleteMessage setChatId(String chatId) {
this.chatId = chatId;
return this;
}
public Integer getMessageId() {
return messageId;
}
public DeleteMessage setMessageId(Integer messageId) {
this.messageId = messageId;
return 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 editing message caption", 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 (messageId == null) {
throw new TelegramApiValidationException("MessageId parameter can't be empty", this);
}
}
@Override
public String toString() {
return "DeleteMessage{" +
"chatId='" + chatId + '\'' +
", messageId=" + messageId +
'}';
}
}

View File

@ -1,17 +1,17 @@
package org.telegram.telegrambots.api.objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
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;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents a message.
* @date 20 of June of 2015
* This object represents a message.
*/
public class Message implements BotApiObject {
private static final String MESSAGEID_FIELD = "message_id";
@ -32,7 +32,7 @@ public class Message implements BotApiObject {
private static final String LOCATION_FIELD = "location";
private static final String VENUE_FIELD = "venue";
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 NEWCHATTITLE_FIELD = "new_chat_title";
private static final String NEWCHATPHOTO_FIELD = "new_chat_photo";
@ -48,6 +48,9 @@ public class Message implements BotApiObject {
private static final String EDITDATE_FIELD = "edit_date";
private static final String GAME_FIELD = "game";
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";
private static final String VIDEO_NOTE_FIELD = "video_note";
@JsonProperty(MESSAGEID_FIELD)
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
@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.
@JsonProperty(NEWCHATMEMBER_FIELD)
private User newChatMember; ///< Optional. A new member was added to the group, information about them (this member may be bot itself)
@JsonProperty(NEWCHATMEMBERS_FIELD)
private List<User> newChatMembers; ///< Optional. New members were added to the group or supergroup, information about them (the bot itself may be one of these members)
@JsonProperty(LEFTCHATMEMBER_FIELD)
private User leftChatMember; ///< Optional. A member was removed from the group, information about them (this member may be bot itself)
@JsonProperty(NEWCHATTITLE_FIELD)
@ -149,6 +152,12 @@ public class Message implements BotApiObject {
private Game game; ///< Optional. Message is a game, information about the game
@JsonProperty(FORWARDFROMMESSAGEID_FIELD)
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.
@JsonProperty(VIDEO_NOTE_FIELD)
private VideoNote videoNote; ///< Optional. Message is a video note, information about the video message
public Message() {
super();
@ -223,8 +232,8 @@ public class Message implements BotApiObject {
return pinnedMessage;
}
public User getNewChatMember() {
return newChatMember;
public List<User> getNewChatMembers() {
return newChatMembers;
}
public User getLeftChatMember() {
@ -351,6 +360,26 @@ public class Message implements BotApiObject {
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;
}
public VideoNote getVideoNote() {
return videoNote;
}
@Override
public String toString() {
return "Message{" +
@ -372,7 +401,7 @@ public class Message implements BotApiObject {
", location=" + location +
", venue=" + venue +
", pinnedMessage=" + pinnedMessage +
", newChatMember=" + newChatMember +
", newChatMembers=" + newChatMembers +
", leftChatMember=" + leftChatMember +
", newChatTitle='" + newChatTitle + '\'' +
", newChatPhoto=" + newChatPhoto +
@ -388,6 +417,9 @@ public class Message implements BotApiObject {
", editDate=" + editDate +
", game=" + game +
", forwardFromMessageId=" + forwardFromMessageId +
", invoice=" + invoice +
", successfulPayment=" + successfulPayment +
", videoNote=" + videoNote +
'}';
}
}

View File

@ -5,13 +5,16 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
import org.telegram.telegrambots.api.objects.inlinequery.ChosenInlineQuery;
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
* @version 1.0
* @brief This object represents an incoming update.
* Only one of the optional parameters can be present in any given update.
* @date 20 of June of 2015
*
* This object represents an incoming update.
*
* @apiNote Only one of the optional parameters can be present in any given update.
*/
public class Update implements BotApiObject {
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 CHANNELPOST_FIELD = "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)
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.
@JsonProperty(EDITEDCHANNELPOST_FIELD)
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() {
super();
@ -77,6 +85,14 @@ public class Update implements BotApiObject {
return editedChannelPost;
}
public ShippingQuery getShippingQuery() {
return shippingQuery;
}
public PreCheckoutQuery getPreCheckoutQuery() {
return preCheckoutQuery;
}
public boolean hasMessage() {
return message != null;
}
@ -105,6 +121,14 @@ public class Update implements BotApiObject {
return editedChannelPost != null;
}
public boolean hasShippingQuery() {
return shippingQuery != null;
}
public boolean hasPreCheckoutQuery() {
return preCheckoutQuery != null;
}
@Override
public String toString() {
return "Update{" +
@ -116,6 +140,8 @@ public class Update implements BotApiObject {
", editedMessage=" + editedMessage +
", channelPost=" + channelPost +
", editedChannelPost=" + editedChannelPost +
", shippingQuery=" + shippingQuery +
", preCheckoutQuery=" + preCheckoutQuery +
'}';
}
}

View File

@ -6,9 +6,8 @@ import org.telegram.telegrambots.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief This object represents a Telegram user or bot.
* @date 20 of June of 2015
* @version 3.0
* This object represents a Telegram user or bot.
*/
public class User implements BotApiObject {
@ -16,6 +15,7 @@ public class User implements BotApiObject {
private static final String FIRSTNAME_FIELD = "first_name";
private static final String LASTNAME_FIELD = "last_name";
private static final String USERNAME_FIELD = "username";
private static final String LANGUAGECODE_FIELD = "language_code";
@JsonProperty(ID_FIELD)
private Integer id; ///< Unique identifier for this user or bot
@ -25,6 +25,8 @@ public class User implements BotApiObject {
private String lastName; ///< Optional. Users or bots last name
@JsonProperty(USERNAME_FIELD)
private String userName; ///< Optional. Users or bots username
@JsonProperty(LANGUAGECODE_FIELD)
private String languageCode; ///< Optional. IETF language tag of the user's language
public User() {
super();
@ -46,6 +48,10 @@ public class User implements BotApiObject {
return userName;
}
public String getLanguageCode() {
return languageCode;
}
@Override
public String toString() {
return "User{" +
@ -53,6 +59,7 @@ public class User implements BotApiObject {
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", userName='" + userName + '\'' +
", languageCode='" + languageCode + '\'' +
'}';
}
}

View File

@ -0,0 +1,64 @@
package org.telegram.telegrambots.api.objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 1.0
*
* This object represents a video message (available in Telegram apps as of v.4.0).
*/
public class VideoNote implements BotApiObject {
private static final String FILEID_FIELD = "file_id";
private static final String LENGTH_FIELD = "length";
private static final String DURATION_FIELD = "duration";
private static final String THUMB_FIELD = "thumb";
private static final String FILESIZE_FIELD = "file_size";
@JsonProperty(FILEID_FIELD)
private String fileId; ///< Unique identifier for this file
@JsonProperty(LENGTH_FIELD)
private Integer length; ///< Video width and height as defined by sender
@JsonProperty(DURATION_FIELD)
private Integer duration; ///< Duration of the video in seconds as defined by sender
@JsonProperty(THUMB_FIELD)
private PhotoSize thumb; ///< Optional. Video thumbnail
@JsonProperty(FILESIZE_FIELD)
private Integer fileSize; ///< Optional. File size
public VideoNote() {
super();
}
public String getFileId() {
return fileId;
}
public Integer getLength() {
return length;
}
public Integer getDuration() {
return duration;
}
public PhotoSize getThumb() {
return thumb;
}
public Integer getFileSize() {
return fileSize;
}
@Override
public String toString() {
return "VideoNote{" +
"fileId='" + fileId + '\'' +
", length=" + length +
", duration=" + duration +
", thumb=" + thumb +
", fileSize=" + fileSize +
'}';
}
}

View File

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

View File

@ -26,6 +26,7 @@ public class InlineQueryResultGif implements InlineQueryResult {
private static final String CAPTION_FIELD = "caption";
private static final String INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String GIF_DURATION_FIELD = "gif_duration";
@JsonProperty(TYPE_FIELD)
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
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(GIF_DURATION_FIELD)
private Integer gifDuration; ///< Optional. Duration of the GIF
public InlineQueryResultGif() {
super();
@ -137,6 +140,14 @@ public class InlineQueryResultGif implements InlineQueryResult {
return this;
}
public Integer getGifDuration() {
return gifDuration;
}
public void setGifDuration(Integer gifDuration) {
this.gifDuration = gifDuration;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@ -164,8 +175,9 @@ public class InlineQueryResultGif implements InlineQueryResult {
", thumbUrl='" + thumbUrl + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' +
", replyMarkup='" + replyMarkup + '\'' +
", inputMessageContent=" + inputMessageContent +
", 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 INPUTMESSAGECONTENT_FIELD = "input_message_content";
private static final String REPLY_MARKUP_FIELD = "reply_markup";
private static final String MPEG4_DURATION_FIELD = "mpeg4_duration";
@JsonProperty(TYPE_FIELD)
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
@JsonProperty(REPLY_MARKUP_FIELD)
private InlineKeyboardMarkup replyMarkup; ///< Optional. Inline keyboard attached to the message
@JsonProperty(MPEG4_DURATION_FIELD)
private Integer mpeg4Duration; ///< Optional. Video duration
public InlineQueryResultMpeg4Gif() {
super();
@ -137,6 +140,14 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
return this;
}
public Integer getMpeg4Duration() {
return mpeg4Duration;
}
public void setMpeg4Duration(Integer mpeg4Duration) {
this.mpeg4Duration = mpeg4Duration;
}
@Override
public void validate() throws TelegramApiValidationException {
if (id == null || id.isEmpty()) {
@ -164,8 +175,9 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
", thumbUrl='" + thumbUrl + '\'' +
", title='" + title + '\'' +
", caption='" + caption + '\'' +
", inputMessageContent='" + inputMessageContent + '\'' +
", replyMarkup='" + replyMarkup + '\'' +
", inputMessageContent=" + inputMessageContent +
", 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)
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)
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.
* Targets:
@ -59,12 +59,12 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
return this;
}
public Boolean getOneTimeKeyboad() {
return oneTimeKeyboad;
public Boolean getOneTimeKeyboard() {
return oneTimeKeyboard;
}
public ReplyKeyboardMarkup setOneTimeKeyboad(Boolean oneTimeKeyboad) {
this.oneTimeKeyboad = oneTimeKeyboad;
public ReplyKeyboardMarkup setOneTimeKeyboard(Boolean oneTimeKeyboard) {
this.oneTimeKeyboard = oneTimeKeyboard;
return this;
}
@ -92,7 +92,7 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard {
return "ReplyKeyboardMarkup{" +
"keyboard=" + keyboard +
", resizeKeyboard=" + resizeKeyboard +
", oneTimeKeyboad=" + oneTimeKeyboad +
", oneTimeKeyboard=" + oneTimeKeyboard +
", selective=" + selective +
'}';
}

View File

@ -1,12 +1,13 @@
package org.telegram.telegrambots.api.objects.replykeyboard.buttons;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.InputBotApiObject;
import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.api.objects.games.CallbackGame;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Ruben Bermudez
* @version 1.0
@ -14,7 +15,6 @@ import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
* optional fields.
* @note This will only work in Telegram versions released after 9 April, 2016. Older clients will
* display unsupported message.
* @date 10 of April of 2016
*/
public class InlineKeyboardButton implements InputBotApiObject, Validable {
@ -24,6 +24,7 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
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_CURRENT_CHAT_FIELD = "switch_inline_query_current_chat";
private static final String PAY_FIELD = "pay";
@JsonProperty(TEXT_FIELD)
private String text; ///< Label text on the button
@ -43,7 +44,8 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
* 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.
* 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.
* 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.
@ -58,10 +60,22 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
@JsonProperty(SWITCH_INLINE_QUERY_CURRENT_CHAT_FIELD)
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(PAY_FIELD)
private Boolean pay;
public InlineKeyboardButton() {
super();
}
public InlineKeyboardButton(String text) {
this.text = checkNotNull(text);
}
public String getText() {
return text;
}
@ -116,6 +130,15 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
return this;
}
public Boolean getPay() {
return pay;
}
public InlineKeyboardButton setPay(Boolean pay) {
this.pay = pay;
return this;
}
@Override
public void validate() throws TelegramApiValidationException {
if (text == null || text.isEmpty()) {
@ -132,6 +155,7 @@ public class InlineKeyboardButton implements InputBotApiObject, Validable {
", callbackGame=" + callbackGame +
", switchInlineQuery='" + switchInlineQuery + '\'' +
", switchInlineQueryCurrentChat='" + switchInlineQueryCurrentChat + '\'' +
", pay=" + pay +
'}';
}
}

View File

@ -1,45 +1,17 @@
package org.telegram.telegrambots.bots;
import org.telegram.telegrambots.api.methods.AnswerCallbackQuery;
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.*;
import org.telegram.telegrambots.api.methods.games.GetGameHighScores;
import org.telegram.telegrambots.api.methods.games.SetGameScore;
import org.telegram.telegrambots.api.methods.groupadministration.GetChat;
import org.telegram.telegrambots.api.methods.groupadministration.GetChatAdministrators;
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.groupadministration.*;
import org.telegram.telegrambots.api.methods.send.*;
import org.telegram.telegrambots.api.methods.updates.DeleteWebhook;
import org.telegram.telegrambots.api.methods.updates.GetWebhookInfo;
import org.telegram.telegrambots.api.methods.updatingmessages.DeleteMessage;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageCaption;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageReplyMarkup;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.api.objects.Chat;
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.*;
import org.telegram.telegrambots.api.objects.games.GameHighScore;
import org.telegram.telegrambots.exceptions.TelegramApiException;
import org.telegram.telegrambots.updateshandlers.SentCallback;
@ -249,6 +221,34 @@ public abstract class AbsSender {
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);
}
public final Boolean deleteMessage(DeleteMessage deleteMessage) throws TelegramApiException {
if(deleteMessage == null){
throw new TelegramApiException("Parameter deleteMessage can not be null");
}
return sendApiMethod(deleteMessage);
}
// Send Requests Async
public final void sendMessageAsync(SendMessage sendMessage, SentCallback<Message> sentCallback) throws TelegramApiException {
@ -530,6 +530,46 @@ public abstract class AbsSender {
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);
}
public final void deleteMessage(DeleteMessage deleteMessage, SentCallback<Boolean> sentCallback) throws TelegramApiException {
if (deleteMessage == null) {
throw new TelegramApiException("Parameter deleteMessage can not be null");
}
if (sentCallback == null) {
throw new TelegramApiException("Parameter sentCallback can not be null");
}
sendApiMethodAsync(deleteMessage, sentCallback);
}
// Specific Send Requests
public abstract Message sendDocument(SendDocument sendDocument) throws TelegramApiException;
@ -537,6 +577,8 @@ public abstract class AbsSender {
public abstract Message sendVideo(SendVideo sendVideo) throws TelegramApiException;
public abstract Message sendVideoNote(SendVideoNote sendVideoNote) throws TelegramApiException;
public abstract Message sendSticker(SendSticker sendSticker) throws TelegramApiException;
/**

View File

@ -7,4 +7,5 @@ package org.telegram.telegrambots.generics;
* @date 29 of October of 2016
*/
public interface BotOptions {
String getBaseUrl();
}

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>2.4.4.5</version>
<version>3.0</version>
<packaging>jar</packaging>
<name>Telegram Bots</name>
@ -66,7 +66,7 @@
<jackson.version>2.8.7</jackson.version>
<jacksonanotation.version>2.8.0</jacksonanotation.version>
<commonio.version>2.5</commonio.version>
<bots.version>2.4.4.5</bots.version>
<bots.version>3.0</bots.version>
</properties>
<dependencyManagement>
@ -305,6 +305,17 @@
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>

View File

@ -1,7 +1,6 @@
package org.telegram.telegrambots.bots;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
@ -18,14 +17,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.telegram.telegrambots.ApiConstants;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.methods.send.SendAudio;
import org.telegram.telegrambots.api.methods.send.SendDocument;
import org.telegram.telegrambots.api.methods.send.SendPhoto;
import org.telegram.telegrambots.api.methods.send.SendSticker;
import org.telegram.telegrambots.api.methods.send.SendVideo;
import org.telegram.telegrambots.api.methods.send.SendVoice;
import org.telegram.telegrambots.api.methods.send.*;
import org.telegram.telegrambots.api.objects.File;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.exceptions.TelegramApiException;
@ -45,6 +38,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
/**
* @author Ruben Bermudez
* @version 1.0
@ -72,6 +67,13 @@ public abstract class DefaultAbsSender extends AbsSender {
.build();
requestConfig = options.getRequestConfig();
if (requestConfig == null) {
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
.setSocketTimeout(SOCKET_TIMEOUT)
.setConnectTimeout(SOCKET_TIMEOUT)
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
}
}
/**
@ -394,6 +396,79 @@ public abstract class DefaultAbsSender extends AbsSender {
return sendVideo.deserializeResponse(responseContent);
}
@Override
public final Message sendVideoNote(SendVideoNote sendVideoNote) throws TelegramApiException {
if(sendVideoNote == null){
throw new TelegramApiException("Parameter sendVideoNote can not be null");
}
sendVideoNote.validate();
String responseContent;
try {
String url = getBaseUrl() + SendVideoNote.PATH;
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
if (sendVideoNote.isNewVideoNote()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendVideoNote.CHATID_FIELD, sendVideoNote.getChatId());
if (sendVideoNote.getNewVideoNoteFile() != null) {
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getNewVideoNoteFile());
} else if (sendVideoNote.getNewVideoNoteStream() != null) {
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getNewVideoNoteStream(), ContentType.APPLICATION_OCTET_STREAM, sendVideoNote.getVideoNoteName());
} else {
builder.addBinaryBody(SendVideoNote.VIDEONOTE_FIELD, new java.io.File(sendVideoNote.getVideoNote()), ContentType.APPLICATION_OCTET_STREAM, sendVideoNote.getVideoNoteName());
}
if (sendVideoNote.getReplyMarkup() != null) {
builder.addTextBody(SendVideoNote.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendVideoNote.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
}
if (sendVideoNote.getReplyToMessageId() != null) {
builder.addTextBody(SendVideoNote.REPLYTOMESSAGEID_FIELD, sendVideoNote.getReplyToMessageId().toString());
}
if (sendVideoNote.getDuration() != null) {
builder.addTextBody(SendVideoNote.DURATION_FIELD, sendVideoNote.getDuration().toString());
}
if (sendVideoNote.getLength() != null) {
builder.addTextBody(SendVideoNote.LENGTH_FIELD, sendVideoNote.getLength().toString());
}
if (sendVideoNote.getDisableNotification() != null) {
builder.addTextBody(SendVideoNote.DISABLENOTIFICATION_FIELD, sendVideoNote.getDisableNotification().toString());
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
} else {
List<NameValuePair> nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.CHATID_FIELD, sendVideoNote.getChatId()));
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.VIDEONOTE_FIELD, sendVideoNote.getVideoNote()));
if (sendVideoNote.getReplyMarkup() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(sendVideoNote.getReplyMarkup())));
}
if (sendVideoNote.getReplyToMessageId() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.REPLYTOMESSAGEID_FIELD, sendVideoNote.getReplyToMessageId().toString()));
}
if (sendVideoNote.getDuration() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.DURATION_FIELD, sendVideoNote.getDuration().toString()));
}
if (sendVideoNote.getLength() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.LENGTH_FIELD, sendVideoNote.getLength().toString()));
}
if (sendVideoNote.getDisableNotification() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideoNote.DISABLENOTIFICATION_FIELD, sendVideoNote.getDisableNotification().toString()));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, StandardCharsets.UTF_8));
}
try (CloseableHttpResponse response = httpclient.execute(httppost)) {
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
}
} catch (IOException e) {
throw new TelegramApiException("Unable to send video note", e);
}
return sendVideoNote.deserializeResponse(responseContent);
}
@Override
public final Message sendSticker(SendSticker sendSticker) throws TelegramApiException {
if(sendSticker == null){
@ -678,7 +753,7 @@ public abstract class DefaultAbsSender extends AbsSender {
return method.deserializeResponse(responseContent);
}
private String getBaseUrl() {
return ApiConstants.BASE_URL + getBotToken() + "/";
protected String getBaseUrl() {
return options.getBaseUrl() + getBotToken() + "/";
}
}

View File

@ -1,6 +1,7 @@
package org.telegram.telegrambots.bots;
import org.apache.http.client.config.RequestConfig;
import org.telegram.telegrambots.ApiConstants;
import org.telegram.telegrambots.generics.BotOptions;
import org.telegram.telegrambots.updatesreceivers.ExponentialBackOff;
@ -17,10 +18,20 @@ public class DefaultBotOptions implements BotOptions {
private RequestConfig requestConfig;
private ExponentialBackOff exponentialBackOff;
private Integer maxWebhookConnections;
private String baseUrl;
private List<String> allowedUpdates;
public DefaultBotOptions() {
maxThreads = 1;
baseUrl = ApiConstants.BASE_URL;
}
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
public void setMaxThreads(int maxThreads) {

View File

@ -38,7 +38,7 @@ public abstract class TelegramLongPollingBot extends DefaultAbsSender implements
@Override
public void clearWebhook() throws TelegramApiRequestException {
try (CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build()) {
String url = ApiConstants.BASE_URL + getBotToken() + "/" + SetWebhook.PATH;
String url = getOptions().getBaseUrl() + getBotToken() + "/" + SetWebhook.PATH;
HttpGet httpGet = new HttpGet(url);
httpGet.setConfig(getOptions().getRequestConfig());
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {

View File

@ -45,7 +45,7 @@ public abstract class TelegramWebhookBot extends DefaultAbsSender implements Web
@Override
public void setWebhook(String url, String publicCertificatePath) throws TelegramApiRequestException {
try (CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build()) {
String requestUrl = ApiConstants.BASE_URL + getBotToken() + "/" + SetWebhook.PATH;
String requestUrl = getBaseUrl() + getBotToken() + "/" + SetWebhook.PATH;
HttpPost httppost = new HttpPost(requestUrl);
httppost.setConfig(botOptions.getRequestConfig());

View File

@ -186,7 +186,7 @@ public class DefaultBotSession implements BotSession {
request.setAllowedUpdates(options.getAllowedUpdates());
}
String url = ApiConstants.BASE_URL + token + "/" + GetUpdates.PATH;
String url = options.getBaseUrl() + token + "/" + GetUpdates.PATH;
//http client
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("charset", StandardCharsets.UTF_8.name());

View File

@ -39,11 +39,6 @@ import com.google.common.base.Preconditions;
* <b>Note:</b> max_interval caps the retry_interval and not the randomized_interval.
* </p>
*
* <p>
* If the time elapsed since an {@link ExponentialBackOff} instance is created goes past the
* max_elapsed_time then the method {@link #nextBackOffMillis()} starts returning
* {@link ExponentialBackOff#STOP}. The elapsed time can be reset by calling {@link #reset()}.
* </p>
*
* <p>
* Example: The default retry_interval is .5 seconds, default randomization_factor is 0.5, default

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.LeaveChat;
import org.telegram.telegrambots.api.methods.groupadministration.UnbanChatMember;
import org.telegram.telegrambots.api.methods.send.SendChatAction;
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.send.*;
import org.telegram.telegrambots.api.methods.updates.GetWebhookInfo;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageCaption;
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.InlineQueryResultArticle;
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.InlineKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
@ -191,7 +187,7 @@ public final class BotApiMethodHelperFactory {
private static ReplyKeyboard getKeyboardMarkup() {
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
keyboardMarkup.setResizeKeyboard(true);
keyboardMarkup.setOneTimeKeyboad(true);
keyboardMarkup.setOneTimeKeyboard(true);
keyboardMarkup.setSelective(true);
List<KeyboardRow> keyboard = new ArrayList<>();
KeyboardRow row = new KeyboardRow();
@ -289,4 +285,19 @@ public final class BotApiMethodHelperFactory {
.setChatId("12345")
.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));
}
@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() {
ObjectMapper mapper = new ObjectMapper();
try {