Skip to content

Commit

Permalink
Merge pull request #354 from anfanik/master
Browse files Browse the repository at this point in the history
Implement Bot API 7.0 Reactions
  • Loading branch information
mircoianese authored Jan 12, 2024
2 parents 5a17652 + 42a3fe1 commit c83510e
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Java library for interacting with [Telegram Bot API](https://core.telegram.org/b

Gradle:
```groovy
implementation 'com.github.pengrad:java-telegram-bot-api:6.9.1'
implementation 'com.github.pengrad:java-telegram-bot-api:7.0.0'
```
Maven:
```xml
<dependency>
<groupId>com.github.pengrad</groupId>
<artifactId>java-telegram-bot-api</artifactId>
<version>6.9.1</version>
<version>7.0.0</version>
</dependency>
```
[JAR with all dependencies on release page](https://github.com/pengrad/java-telegram-bot-api/releases)
Expand Down
4 changes: 2 additions & 2 deletions README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Java библиотека, созданная для работы с [Telegram B

Gradle:
```groovy
implementation 'com.github.pengrad:java-telegram-bot-api:6.9.1'
implementation 'com.github.pengrad:java-telegram-bot-api:7.0.0'
```
Maven:
```xml
<dependency>
<groupId>com.github.pengrad</groupId>
<artifactId>java-telegram-bot-api</artifactId>
<version>6.9.1</version>
<version>7.0.0</version>
</dependency>
```
Также JAR со всеми зависимостями можно найти [в релизах](https://github.com/pengrad/java-telegram-bot-api/releases).
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.github.pengrad
VERSION_NAME=6.9.1
VERSION_NAME=7.0.0

POM_DESCRIPTION=Java API for Telegram Bot API
POM_URL=https://github.com/pengrad/java-telegram-bot-api/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.pengrad.telegrambot.request.BaseRequest;
import com.pengrad.telegrambot.request.GetUpdates;
import com.pengrad.telegrambot.response.BaseResponse;
import com.pengrad.telegrambot.utility.BotUtils;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
Expand Down Expand Up @@ -166,7 +167,7 @@ private static Interceptor httpLoggingInterceptor() {
}

private static Gson gson() {
return new Gson();
return BotUtils.GSON;
}

private static String apiUrl(String apiUrl, String botToken, boolean useTestServer) {
Expand Down
13 changes: 11 additions & 2 deletions library/src/main/java/com/pengrad/telegrambot/model/Chat.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.pengrad.telegrambot.model;

import com.google.gson.annotations.SerializedName;
import com.pengrad.telegrambot.model.reaction.ReactionType;


import java.io.Serializable;
import java.util.Arrays;
Expand Down Expand Up @@ -33,6 +35,7 @@ public enum Type {
private Boolean is_forum;
private ChatPhoto photo;
private String[] active_usernames;
private ReactionType[] available_reactions;
private String emoji_status_custom_emoji_id;
private Integer emoji_status_expiration_date;
private String bio;
Expand Down Expand Up @@ -89,7 +92,7 @@ public ChatPhoto photo() {
/**
* @deprecated Use activeUsernames() instead
*/
@Deprecated
@Deprecated
public String[] getActiveUsernames() {
return active_usernames;
}
Expand All @@ -98,10 +101,14 @@ public String[] activeUsernames() {
return active_usernames;
}

@Deprecated
public ReactionType[] availableReactions() {
return available_reactions;
}

/**
* @deprecated Use emojiStatusCustomEmojiId() instead
*/
@Deprecated
public String getEmojiStatusCustomEmojiId() {
return emoji_status_custom_emoji_id;
}
Expand Down Expand Up @@ -200,6 +207,7 @@ public boolean equals(Object o) {
Objects.equals(title, chat.title) &&
Objects.equals(photo, chat.photo) &&
Arrays.equals(active_usernames, chat.active_usernames) &&
Arrays.equals(available_reactions, chat.available_reactions) &&
Objects.equals(emoji_status_custom_emoji_id, chat.emoji_status_custom_emoji_id) &&
Objects.equals(emoji_status_expiration_date, chat.emoji_status_expiration_date) &&
Objects.equals(bio, chat.bio) &&
Expand Down Expand Up @@ -239,6 +247,7 @@ public String toString() {
", title='" + title + '\'' +
", photo=" + photo +
", active_usernames=" + Arrays.toString(active_usernames) +
", available_reactions=" + Arrays.toString(available_reactions) +
", emoji_status_custom_emoji_id='" + emoji_status_custom_emoji_id + '\'' +
", emoji_status_expiration_date='" + emoji_status_expiration_date + '\'' +
", bio='" + bio + '\'' +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.pengrad.telegrambot.model;

import com.pengrad.telegrambot.model.reaction.ReactionCount;

import java.util.Arrays;
import java.util.Objects;

public class MessageReactionCountUpdated {

private Chat chat;
private Integer message_id;
private Integer date;
private ReactionCount[] reactions;

public Chat chat() {
return chat;
}

public Integer messageId() {
return message_id;
}

public Integer date() {
return date;
}

public ReactionCount[] reactions() {
return reactions;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MessageReactionCountUpdated that = (MessageReactionCountUpdated) o;
return Objects.equals(chat, that.chat) &&
Objects.equals(message_id, that.message_id) &&
Objects.equals(date, that.date) &&
Arrays.equals(reactions, that.reactions);
}

@Override
public int hashCode() {
int result = Objects.hash(chat, message_id, date);
result = 31 * result + Arrays.hashCode(reactions);
return result;
}

@Override
public String toString() {
return "MessageReactionCountUpdated{" +
"chat=" + chat +
", message_id=" + message_id +
", date=" + date +
", reactions=" + Arrays.toString(reactions) +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.pengrad.telegrambot.model;

import com.pengrad.telegrambot.model.reaction.ReactionType;

import java.util.Arrays;
import java.util.Objects;

public class MessageReactionUpdated {

private Chat chat;
private Integer message_id;
private User user;
private Chat actor_chat;
private Integer date;
private ReactionType[] old_reaction;
private ReactionType[] new_reaction;

public Chat chat() {
return chat;
}

public Integer messageId() {
return message_id;
}

public User user() {
return user;
}

public Chat actorChat() {
return actor_chat;
}

public Integer date() {
return date;
}

public ReactionType[] oldReaction() {
return old_reaction;
}

public ReactionType[] newReaction() {
return new_reaction;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MessageReactionUpdated that = (MessageReactionUpdated) o;
return Objects.equals(chat, that.chat) &&
Objects.equals(message_id, that.message_id) &&
Objects.equals(user, that.user) &&
Objects.equals(actor_chat, that.actor_chat) &&
Objects.equals(date, that.date) &&
Arrays.equals(old_reaction, that.old_reaction) &&
Arrays.equals(new_reaction, that.new_reaction);
}

@Override
public int hashCode() {
int result = Objects.hash(chat, message_id, user, actor_chat, date);
result = 31 * result + Arrays.hashCode(old_reaction);
result = 31 * result + Arrays.hashCode(new_reaction);
return result;
}

@Override
public String toString() {
return "MessageReactionUpdated{" +
"chat=" + chat +
", message_id=" + message_id +
", user=" + user +
", actor_chat=" + actor_chat +
", date=" + date +
", old_reaction=" + Arrays.toString(old_reaction) +
", new_reaction=" + Arrays.toString(new_reaction) +
'}';
}
}
16 changes: 15 additions & 1 deletion library/src/main/java/com/pengrad/telegrambot/model/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Update implements Serializable {
private ChatMemberUpdated my_chat_member;
private ChatMemberUpdated chat_member;
private ChatJoinRequest chat_join_request;
private MessageReactionUpdated message_reaction;
private MessageReactionCountUpdated message_reaction_count;

public Integer updateId() {
return update_id;
Expand Down Expand Up @@ -86,6 +88,14 @@ public ChatJoinRequest chatJoinRequest() {
return chat_join_request;
}

public MessageReactionUpdated messageReaction() {
return message_reaction;
}

public MessageReactionCountUpdated messageReactionCount() {
return message_reaction_count;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -105,7 +115,9 @@ public boolean equals(Object o) {
Objects.equals(poll_answer, update.poll_answer) &&
Objects.equals(my_chat_member, update.my_chat_member) &&
Objects.equals(chat_member, update.chat_member) &&
Objects.equals(chat_join_request, update.chat_join_request);
Objects.equals(chat_join_request, update.chat_join_request) &&
Objects.equals(message_reaction, update.message_reaction) &&
Objects.equals(message_reaction_count, update.message_reaction_count);
}

@Override
Expand All @@ -131,6 +143,8 @@ public String toString() {
", my_chat_member=" + my_chat_member +
", chat_member=" + chat_member +
", chat_join_request=" + chat_join_request +
", message_reaction=" + message_reaction +
", message_reaction_count=" + message_reaction_count +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pengrad.telegrambot.model.reaction;

import java.util.Objects;

public class ReactionCount {

private ReactionType type;
private Integer total_count;

public ReactionType type() {
return type;
}

public Integer totalCount() {
return total_count;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ReactionCount that = (ReactionCount) o;
return Objects.equals(type, that.type) &&
Objects.equals(total_count, that.total_count);
}

@Override
public int hashCode() {
return Objects.hash(type, total_count);
}

@Override
public String toString() {
return "ReactionCount{" +
"type=" + type +
", total_count=" + total_count +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.pengrad.telegrambot.model.reaction;

import java.util.Objects;

public abstract class ReactionType {

private final String type;

public ReactionType(String type) {
this.type = type;
}

public String type() {
return type;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ReactionType that = (ReactionType) o;
return Objects.equals(type, that.type);
}

@Override
public int hashCode() {
return Objects.hash(type);
}

@Override
public String toString() {
return "ReactionType{" +
"type='" + type + '\'' +
'}';
}
}
Loading

0 comments on commit c83510e

Please sign in to comment.