Skip to content

Commit

Permalink
Telegram Bot API 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadiducho committed Aug 20, 2022
1 parent cabde39 commit 8dc5e68
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ If you want use Telegram Bot API as a Maven Dependency simply add repo and artif
<dependency>
<groupId>com.cadiducho</groupId>
<artifactId>TelegramBotAPI</artifactId>
<version>6.1</version>
<version>6.2</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.cadiducho'
version = '6.1'
version = '6.2'
sourceCompatibility = '1.8'

java {
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/cadiducho/telegrambotapi/BotAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* Interface to build Telegrams Bots
* Telegram Bot API version 6.1
* Telegram Bot API version 6.2
*/
public interface BotAPI {

Expand Down Expand Up @@ -1488,7 +1488,15 @@ default Message sendSticker(Object chat_id, java.io.File sticker) throws Telegra
* @throws com.cadiducho.telegrambotapi.exception.TelegramException if the method fails in Telegram servers
*/
StickerSet getStickerSet(String name) throws TelegramException;


/**
* Use this method to get information about custom emoji stickers by their identifiers.
* @param custom_emoji_ids List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified.
* @return Array of Sticker objects.
* @throws TelegramException com.cadiducho.telegrambotapi.exception.TelegramException if the method fails in Telegram servers
*/
List<Sticker> getCustomEmojiStickers(List<String> custom_emoji_ids) throws TelegramException;

/**
* Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success.
* @param user_id User identifier of sticker file owner
Expand All @@ -1506,13 +1514,13 @@ default Message sendSticker(Object chat_id, java.io.File sticker) throws Telegra
* @param png_sticker PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data
* @param tgs_sticker TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#animated-sticker-requirements for technical requirements
* @param webm_sticker WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirements
* @param sticker_type Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created via the Bot API at the moment. By default, a regular sticker set is created.
* @param emojis One or more emoji corresponding to the sticker
* @param contains_masks Optional. Pass True, if a set of mask stickers should be created
* @param mask_position Optional. A JSON-serialized object for position where the mask should be placed on faces
* @return True on success.
* @throws com.cadiducho.telegrambotapi.exception.TelegramException if the method fails in Telegram servers
*/
Boolean createNewStickerSet(Long user_id, String name, String title, java.io.File png_sticker, java.io.File tgs_sticker, java.io.File webm_sticker, String emojis, Boolean contains_masks, MaskPosition mask_position) throws TelegramException;
Boolean createNewStickerSet(Long user_id, String name, String title, java.io.File png_sticker, java.io.File tgs_sticker, java.io.File webm_sticker, String sticker_type, String emojis, MaskPosition mask_position) throws TelegramException;

/**
* Use this method to add a new sticker to a set created by the bot. Returns True on success.
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/cadiducho/telegrambotapi/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public class Chat {
*/
@Json(name = "has_private_forwards") private Boolean hasPrivateForwards;

/**
* Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat.
*/
@Json(name = "has_restricted_voice_and_video_messages") private Boolean hasRestrictedVoiceAndVideoMessages;

/**
* Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat.
*/
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/com/cadiducho/telegrambotapi/MessageEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.cadiducho.telegrambotapi;

import com.squareup.moshi.Json;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand All @@ -20,11 +21,24 @@ public class MessageEntity {

/**
* Type of the entity.
* Can be “mention” (@username), “hashtag” (#hashtag), “cashtag” ($USD), “bot_command” (/start@jobs_bot),
* “url” (https://telegram.org), “email” (do-not-reply@telegram.org), “phone_number” (+1-212-555-0123),
* “bold” (bold text), “italic” (italic text), “underline” (underlined text), “strikethrough” (strikethrough text),
* “spoiler” (spoiler message), “code” (monowidth string), “pre” (monowidth block),
* “text_link” (for clickable text URLs), “text_mention” (for users without usernames)
* Currently, can be
* “mention” (@username),
* “hashtag” (#hashtag),
* “cashtag” ($USD),
* “bot_command” (/start@jobs_bot),
* “url” (https://telegram.org),
* “email” (do-not-reply@telegram.org),
* “phone_number” (+1-212-555-0123),
* “bold” (bold text),
* “italic” (italic text),
* “underline” (underlined text),
* “strikethrough” (strikethrough text),
* “spoiler” (spoiler message),
* “code” (monowidth string),
* “pre” (monowidth block),
* “text_link” (for clickable text URLs),
* “text_mention” (for users without usernames),
* “custom_emoji” (for inline custom emoji stickers)
*/
private String type;

Expand Down Expand Up @@ -52,5 +66,11 @@ public class MessageEntity {
* Optional. For “pre” only, the programming language of the entity text
*/
private String language;

/**
* Optional. For “custom_emoji” only, unique identifier of the custom emoji.
* Use getCustomEmojiStickers to get full information about the sticker
*/
@Json(name = "custom_emoji_id") private String customEmojiId;

}
5 changes: 5 additions & 0 deletions src/main/java/com/cadiducho/telegrambotapi/Sticker.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public class Sticker {
* Optional. For mask stickers, the position where the mask should be placed
*/
@Json(name = "mask_position") private MaskPosition maskPosition;

/**
* Optional. For custom emoji stickers, unique identifier of the custom emoji
*/
@Json(name = "custom_emoji_id") private MaskPosition customEmojiId;

/**
* Optional. File size
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/cadiducho/telegrambotapi/StickerSet.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright 2018 Cadiducho.
* Copyright 2022 Cadiducho.
* Read more in https://github.com/Cadiducho/Telegram-Bot-API/blob/master/LICENSE
*/

Expand Down Expand Up @@ -30,7 +30,12 @@ public class StickerSet {
* Sticker set title
*/
private String title;


/**
* Type of stickers in the set, currently one of “regular”, “mask”, “custom_emoji”
*/
@Json(name = "sticker_type") private Boolean stickerType;

/**
* True, if the sticker set contains animated stickers
* See <a href="https://telegram.org/blog/animated-stickers">https://telegram.org/blog/animated-stickers</a>
Expand All @@ -43,11 +48,6 @@ public class StickerSet {
*/
@Json(name = "is_video") private Boolean isVideo;

/**
* True, if the sticker set contains masks
*/
@Json(name = "contains_masks") private Boolean containsMasks;

/**
* List of all set stickers
*/
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/com/cadiducho/telegrambotapi/TelegramBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* Default implementation to build Telegrams Bots
* Telegram Bot API version 6.1
* Telegram Bot API version 6.2
*/
public class TelegramBot implements BotAPI {

Expand Down Expand Up @@ -1356,6 +1356,18 @@ public StickerSet getStickerSet(String name) throws TelegramException {
return handleRequest(request, StickerSet.class);
}

@Override
public List<Sticker> getCustomEmojiStickers(List<String> custom_emoji_ids) throws TelegramException {
final MultipartBody.Builder parameters = bodyBuilder();

safeAdd(parameters, "custom_emoji_ids", moshi.adapter(Types.newParameterizedType(List.class, String.class)).toJson(custom_emoji_ids));

final Request request = new Request.Builder()
.url(apiUrl + "getCustomEmojiStickers")
.build();
return handleRequest(request, Types.newParameterizedType(List.class, Sticker.class));
}

@Override
public File uploadStickerFile(Long user_id, java.io.File png_sticker) throws TelegramException {
final MultipartBody.Builder parameters = bodyBuilder();
Expand All @@ -1370,14 +1382,14 @@ public File uploadStickerFile(Long user_id, java.io.File png_sticker) throws Tel
}

@Override
public Boolean createNewStickerSet(Long user_id, String name, String title, java.io.File png_sticker, java.io.File tgs_sticker, java.io.File webm_sticker, String emojis, Boolean contains_masks, MaskPosition mask_position) throws TelegramException {
public Boolean createNewStickerSet(Long user_id, String name, String title, java.io.File png_sticker, java.io.File tgs_sticker, java.io.File webm_sticker, String sticker_type, String emojis, MaskPosition mask_position) throws TelegramException {
final MultipartBody.Builder parameters = bodyBuilder();

safeAdd(parameters, "user_id", user_id);
safeAdd(parameters, "name", name);
safeAdd(parameters, "title", title);
safeAdd(parameters, "sticker_type", sticker_type);
safeAdd(parameters, "emojis", emojis);
safeAdd(parameters, "contains_masks", contains_masks);
safeAdd(parameters, "mask_position", mask_position);
addFile(parameters, "png_sticker", png_sticker, MediaTypes.MEDIA_TYPE_PHOTO);
addFile(parameters, "tgs_sticker", png_sticker, MediaTypes.MEDIA_TYPE_PHOTO);
Expand Down

0 comments on commit 8dc5e68

Please sign in to comment.