diff --git a/pom.xml b/pom.xml
index 93d7037..f2f6c73 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,6 @@
0.5.13-SNAPSHOT
1.2.17
20180813
- 1.1.2-SNAPHOT
@@ -57,11 +56,6 @@
json
${json.ver}
-
- org.sadtech.autoresponder
- autoresponder
- ${autoresponder.ver}
-
diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java
index 9f9937e..4037f3d 100644
--- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java
+++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java
@@ -9,18 +9,24 @@ import java.util.List;
public class KeyBoard {
private List lineKeyBoards = new ArrayList<>();
+ private boolean oneTime;
public KeyBoard() {
}
- public KeyBoard(List lineKeyBoards) {
+ public KeyBoard(List lineKeyBoards, boolean oneTime) {
this.lineKeyBoards = lineKeyBoards;
+ this.oneTime = oneTime;
}
- public JSONObject getKeyboard(Boolean one_time) {
+ public void setOneTime(boolean oneTime) {
+ this.oneTime = oneTime;
+ }
+
+ public JSONObject getKeyboard() {
JSONObject keyboard = new JSONObject();
- keyboard.put("one_time", one_time);
+ keyboard.put("one_time", oneTime);
JSONArray menuLine = new JSONArray();
for (LineKeyBoard lineKeyboard : lineKeyBoards) {
@@ -50,6 +56,11 @@ public class KeyBoard {
return this;
}
+ public Builder setOneTime(boolean oneTime) {
+ KeyBoard.this.oneTime = oneTime;
+ return this;
+ }
+
public KeyBoard build() {
return KeyBoard.this;
}
diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java
index 81de780..fc77787 100644
--- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java
+++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java
@@ -1,31 +1,29 @@
package org.sadtech.vkbot.core.keyboard;
-import org.json.JSONObject;
-
import java.util.List;
public class KeyBoardService {
- private JSONObject keyBoardYesNo = generateKeyBoardYesNo();
+ private KeyBoard keyBoardYesNo = generateKeyBoardYesNo();
- private JSONObject generateKeyBoardYesNo() {
+ private KeyBoard generateKeyBoardYesNo() {
ButtonKeyBoard yesButton = ButtonKeyBoard.builder().setColor(ColorButton.POSITIVE).setLabel("Да").setPayload("{\"button\": \"yes\"}").build();
ButtonKeyBoard noButton = ButtonKeyBoard.builder().setColor(ColorButton.NEGATIVE).setLabel("Нет").setPayload("{\"button\": \"no\"}").build();
LineKeyBoard lineKeyBoard = LineKeyBoard.builder().setButtonKeyBoard(yesButton).setButtonKeyBoard(noButton).build();
KeyBoard keyBoard = KeyBoard.builder().setLineKeyBoard(lineKeyBoard).build();
- return keyBoard.getKeyboard(true);
+ return keyBoard;
}
- public static JSONObject verticalMenu(List labelButtons) {
+ public static KeyBoard verticalMenu(List labelButtons) {
KeyBoard keyBoard = new KeyBoard();
for (String labelButton : labelButtons) {
ButtonKeyBoard buttonKeyBoard = ButtonKeyBoard.builder().setLabel(labelButton).setType("text").setPayload("{\"button\": \"" + labelButton + "\"}").build();
keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build());
}
- return keyBoard.getKeyboard(true);
+ return keyBoard;
}
- public JSONObject getKeyBoardYesNo() {
+ public KeyBoard getKeyBoardYesNo() {
return keyBoardYesNo;
}
}
diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java
index a195800..1358b7d 100644
--- a/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java
+++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java
@@ -10,6 +10,8 @@ import org.sadtech.vkbot.core.entity.Person;
public class MailSanderVk implements MailSandler {
private Person person;
+
+ private Integer idRecipient;
private VkApiClient vkApiClient;
private GroupActor groupActor;
@@ -24,14 +26,27 @@ public class MailSanderVk implements MailSandler {
this.groupActor = vkConnect.getGroupActor();
}
+ public void setIdRecipient(Integer idRecipient) {
+ this.idRecipient = idRecipient;
+ }
+
public void setPerson(Person person) {
- this.person = person;
+ idRecipient = person.getId();
+ }
+
+ @Override
+ public void send(String text, String keyBoard) {
+ try {
+ vkApiClient.messages().send(groupActor).peerId(idRecipient).keyboard(keyBoard).message(text).execute();
+ } catch (ApiException | ClientException e) {
+ e.printStackTrace();
+ }
}
@Override
public void send(String text) {
try {
- vkApiClient.messages().send(groupActor).userId(person.getId()).message(text).execute();
+ vkApiClient.messages().send(groupActor).userId(idRecipient).message(text).execute();
} catch (ApiException | ClientException e) {
e.printStackTrace();
}
diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java
index 8d743b6..a7e569a 100644
--- a/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java
+++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java
@@ -8,4 +8,6 @@ public interface MailSandler {
void setPerson(Person person);
+ void send(String text, String keyBoard);
+
}