Skip to content

Commit

Permalink
Merge pull request #83 from yvasyliev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
yvasyliev committed Nov 14, 2021
2 parents 4e7a75e + 675cf80 commit 7015cc7
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This library uses the next third-party dependencies:
<dependency>
<groupId>com.github.yvasyliev</groupId>
<artifactId>java-vk-bots-longpoll-api</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</dependency>
```
4. Extend `LongPollBot` class and override necessary methods:
Expand Down
23 changes: 8 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.yvasyliev</groupId>
<artifactId>java-vk-bots-longpoll-api</artifactId>
<packaging>jar</packaging>
<version>3.0.0</version>
<version>3.0.1</version>
<name>Java VK Bots Long Poll API</name>
<description>A Java library to create VK bots using Bots Long Poll API</description>
<url>https://github.com/yvasyliev/java-vk-bots-long-poll-api</url>
Expand All @@ -21,43 +21,36 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

<gson.version>2.8.6</gson.version>
<slf4j.version>1.7.30</slf4j.version>
<log4j12.version>1.7.30</log4j12.version>
<jsoup.version>1.14.2</jsoup.version>
<junit.version>5.7.1</junit.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
<version>1.14.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${log4j12.version}</version>
<version>1.7.32</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/api/longpoll/bots/config/VkBotsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import api.longpoll.bots.async.DefaultAsyncCaller;
import api.longpoll.bots.converter.Converter;
import api.longpoll.bots.converter.impl.BoolIntConverter;
import api.longpoll.bots.converter.impl.ForwardConverter;
import api.longpoll.bots.converter.impl.GsonConverter;
import api.longpoll.bots.converter.impl.ListConverter;
import api.longpoll.bots.converter.impl.VkAttachmentConverter;
Expand All @@ -19,6 +20,7 @@
import api.longpoll.bots.methods.impl.photos.SaveMessagesPhoto;
import api.longpoll.bots.methods.impl.upload.UploadDoc;
import api.longpoll.bots.methods.impl.upload.UploadPhoto;
import api.longpoll.bots.model.objects.additional.Forward;
import api.longpoll.bots.model.objects.additional.VkAttachment;
import api.longpoll.bots.validator.Validator;
import api.longpoll.bots.validator.VkResponseValidator;
Expand Down Expand Up @@ -136,6 +138,8 @@ public class VkBotsConfig {
*/
private Properties botMethods;

private Converter<Forward, String> forwardConverter;

private VkBotsConfig() {
}

Expand Down Expand Up @@ -362,4 +366,15 @@ public Properties getBotMethods() {
public void setBotMethods(Properties botMethods) {
this.botMethods = botMethods;
}

public Converter<Forward, String> getForwardConverter() {
if (forwardConverter == null) {
forwardConverter = new ForwardConverter();
}
return forwardConverter;
}

public void setForwardConverter(Converter<Forward, String> forwardConverter) {
this.forwardConverter = forwardConverter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package api.longpoll.bots.converter.impl;

import api.longpoll.bots.config.VkBotsConfig;
import api.longpoll.bots.converter.Converter;
import api.longpoll.bots.model.objects.additional.Forward;
import com.google.gson.Gson;

/**
* Converts {@link Forward} object to JSON string.
*/
public class ForwardConverter implements Converter<Forward, String> {
/**
* {@link Gson} object.
*/
private final Gson gson = VkBotsConfig.getInstance().getGson();

@Override
public String convert(Forward forward) {
return gson.toJson(forward);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import api.longpoll.bots.config.VkBotsConfig;
import api.longpoll.bots.converter.Converter;
import api.longpoll.bots.methods.impl.VkMethod;
import api.longpoll.bots.model.objects.additional.Forward;
import api.longpoll.bots.model.objects.additional.Keyboard;
import api.longpoll.bots.model.objects.additional.Template;
import api.longpoll.bots.model.objects.additional.VkAttachment;
Expand All @@ -25,6 +26,7 @@ public class Send extends VkMethod<Send.Response> {
private final Converter<Boolean, Integer> boolIntConverter = VkBotsConfig.getInstance().getBoolIntConverter();
private final Converter<List<?>, String> listConverter = VkBotsConfig.getInstance().getListConverter();
private final Converter<List<VkAttachment>, List<String>> vkAttachmentsListConverter = VkBotsConfig.getInstance().getVkAttachmentsListConverterConverter();
private final Converter<Forward, String> forwardConverter = VkBotsConfig.getInstance().getForwardConverter();

public Send(String accessToken) {
super(accessToken);
Expand Down Expand Up @@ -121,6 +123,10 @@ public Send setTemplate(Template template) {
return addParam("template", template);
}

public Send setForward(Forward forward) {
return addParam("forward", forwardConverter.convert(forward));
}

@Override
public Send addParam(String key, Object value) {
return (Send) super.addParam(key, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package api.longpoll.bots.model.objects.additional;

import com.google.gson.annotations.SerializedName;

import java.util.List;

/**
* Stores messages to forward.
*/
public class Forward {
/**
* Messages owner.
* Should be set when forwarding messages from community to dialog.
*/
@SerializedName("owner_id")
private Integer ownerId;

/**
* Messages origin.
*/
@SerializedName("peer_id")
private int peerId;

/**
* Conversation message IDs.
*/
@SerializedName("conversation_message_ids")
private List<Integer> conversationMessageIds;

/**
* Message IDs.
*/
@SerializedName("message_ids")
private List<Integer> messageIds;

/**
* To forward message to the same char.
*/
@SerializedName("is_reply")
private Boolean isReply;

public Integer getOwnerId() {
return ownerId;
}

public Forward setOwnerId(Integer ownerId) {
this.ownerId = ownerId;
return this;
}

public int getPeerId() {
return peerId;
}

public Forward setPeerId(int peerId) {
this.peerId = peerId;
return this;
}

public List<Integer> getConversationMessageIds() {
return conversationMessageIds;
}

public Forward setConversationMessageIds(List<Integer> conversationMessageIds) {
this.conversationMessageIds = conversationMessageIds;
return this;
}

public List<Integer> getMessageIds() {
return messageIds;
}

public Forward setMessageIds(List<Integer> messageIds) {
this.messageIds = messageIds;
return this;
}

public Boolean getReply() {
return isReply;
}

public Forward setReply(Boolean reply) {
isReply = reply;
return this;
}


@Override
public String toString() {
return "Forward{" +
"ownerId=" + ownerId +
", peerId=" + peerId +
", conversationMessageIds=" + conversationMessageIds +
", messageIds=" + messageIds +
", isReply=" + isReply +
'}';
}
}

0 comments on commit 7015cc7

Please sign in to comment.