diff --git a/pom.xml b/pom.xml
index 8be0fe9..0701693 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,17 +47,9 @@
${bot.core.ver}
-
- com.google.cloud
- google-cloud-speech
- 1.3.0
-
-
- com.google.cloud
- google-cloud-storage
- 1.73.0
-
+
+
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java
index fda8c42..a88ccd6 100644
--- a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java
+++ b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java
@@ -1,22 +1,21 @@
package org.sadtech.vkbot.core.distribution;
-import com.google.cloud.speech.v1.*;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
-import com.google.protobuf.ByteString;
import com.vk.api.sdk.objects.messages.Message;
import com.vk.api.sdk.objects.messages.MessageAttachment;
import com.vk.api.sdk.objects.messages.MessageAttachmentType;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.ArrayUtils;
import org.apache.log4j.Logger;
import org.sadtech.bot.core.domain.Mail;
+import org.sadtech.bot.core.domain.attachment.Attachment;
+import org.sadtech.bot.core.domain.attachment.AudioMessage;
import org.sadtech.vkbot.core.service.distribution.MailService;
-import java.io.*;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.Instant;
+import java.time.LocalDateTime;
import java.util.*;
public class MailSubscriber implements EventSubscribe {
@@ -46,44 +45,6 @@ public class MailSubscriber implements EventSubscribe {
Message userMessage = gson.fromJson(object, Message.class);
log.info(userMessage);
- if (userMessage.getAttachments()!=null) {
- for (MessageAttachment attachment : userMessage.getAttachments()) {
- if (MessageAttachmentType.AUDIO_MESSAGE.equals(attachment.getType())) {
- try (SpeechClient speechClient = SpeechClient.create()) {
-
- byte[] data = IOUtils.toByteArray(userMessage.getAttachments().get(0).getAudioMessage().getLinkOgg().openStream());
- ByteString audioBytes = ByteString.copyFrom(data);
-
- // Builds the sync recognize request
- RecognitionConfig config = RecognitionConfig.newBuilder()
- .setEncoding(RecognitionConfig.AudioEncoding.OGG_OPUS)
- .setSampleRateHertz(16000)
- .setLanguageCode("ru-RU")
- .build();
- RecognitionAudio audio = RecognitionAudio.newBuilder()
- .setContent(audioBytes)
- .build();
-
- // Performs speech recognition on the audio file
- RecognizeResponse response = speechClient.recognize(config, audio);
- List results = response.getResultsList();
-
- for (SpeechRecognitionResult result : results) {
- // There can be several alternative transcripts for a given chunk of speech. Just use the
- // first (most likely) one here.
- SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
- userMessage.setText(alternative.getTranscript());
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
-
-
-
if (userMessage.getPeerId() > 2000000000) {
if (eventDistributionMap.containsKey("chat")) {
eventDistributionMap.get("chat").update(userMessage);
@@ -114,9 +75,19 @@ public class MailSubscriber implements EventSubscribe {
private Mail createMaail(Message message) {
Mail mail = new Mail();
mail.setMessage(message.getText());
- mail.setDate(message.getDate());
+ mail.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), TimeZone.getDefault().toZoneId()));
mail.setId(message.getId());
mail.setPersonId(message.getPeerId());
+
+ List attachments = new ArrayList<>();
+ for (MessageAttachment attachment : message.getAttachments()) {
+ if (MessageAttachmentType.AUDIO_MESSAGE.equals(attachment.getType())) {
+ AudioMessage audioMessage = new AudioMessage();
+ audioMessage.setLinkOdd(attachment.getAudioMessage().getLinkOgg());
+ attachments.add(audioMessage);
+ }
+ }
+ mail.setAttachments(attachments);
return mail;
}
diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
index baa3743..6b3e8d9 100644
--- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
+++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
@@ -5,21 +5,16 @@ import com.vk.api.sdk.client.VkApiClient;
import com.vk.api.sdk.client.actors.GroupActor;
import com.vk.api.sdk.exceptions.ApiException;
import com.vk.api.sdk.exceptions.ClientException;
-import com.vk.api.sdk.objects.messages.*;
+import com.vk.api.sdk.objects.messages.Keyboard;
import com.vk.api.sdk.queries.messages.MessagesSendQuery;
import org.apache.log4j.Logger;
import org.sadtech.bot.core.domain.BoxAnswer;
-import org.sadtech.bot.core.domain.keyboard.ButtonColor;
-import org.sadtech.bot.core.domain.keyboard.KeyBoard;
-import org.sadtech.bot.core.domain.keyboard.KeyBoardButton;
-import org.sadtech.bot.core.domain.keyboard.KeyBoardLine;
import org.sadtech.bot.core.sender.Sent;
import org.sadtech.vkbot.core.VkConnect;
import org.sadtech.vkbot.core.VkInsertData;
import org.sadtech.vkbot.core.convert.KeyBoardConvert;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collections;
import java.util.concurrent.ThreadLocalRandom;
public class MailSenderVk implements Sent {
@@ -49,7 +44,6 @@ public class MailSenderVk implements Sent {
sendMessage(messagesSendQuery);
}
- //FIXME: Пофиксить клавиатуры
private MessagesSendQuery createMessage(BoxAnswer boxAnswer, Integer peerId) {
MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId).message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId)).randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE));
if (boxAnswer.getKeyboard() != null) {
@@ -57,6 +51,7 @@ public class MailSenderVk implements Sent {
} else {
Keyboard keyboard = new Keyboard();
keyboard.setOneTime(true);
+ keyboard.setButtons(Collections.EMPTY_LIST);
messages.keyboard(keyboard);
}
if (boxAnswer.getLat() != null && boxAnswer.getaLong() != null) {
diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java
index ebbef13..8e839c7 100644
--- a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java
+++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java
@@ -6,6 +6,7 @@ import org.sadtech.bot.core.repository.MailRepository;
import org.sadtech.bot.core.repository.impl.MailRepositoryList;
import org.sadtech.vkbot.core.service.distribution.MailService;
+import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -33,8 +34,8 @@ public class MailServiceImpl implements MailService {
}
@Override
- public List getFirstEventByTime(Integer timeFrom, Integer timeTo) {
- log.info("Запрошены сообщения " + timeFrom + "-" + timeTo);
+ public List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
+ log.info("Запрошены сообщения " + timeFrom + " - " + timeTo);
List mails = mailRepository.getMailByTime(timeFrom, timeTo);
Set people = new HashSet<>();
List returnMails = new ArrayList<>();
@@ -48,7 +49,7 @@ public class MailServiceImpl implements MailService {
}
@Override
- public List getLastEventByTime(Integer timeFrom, Integer timeTo) {
+ public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
List mails = mailRepository.getMailByTime(timeFrom, timeTo);
Set people = new HashSet<>();
List returnMails = new ArrayList<>();
@@ -62,7 +63,7 @@ public class MailServiceImpl implements MailService {
}
@Override
- public List getEvent(Integer timeFrom, Integer timeTo) {
+ public List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.info("Запрос на получение сообщений в интервале от " + timeFrom + " до " + timeTo);
return mailRepository.getMailByTime(timeFrom, timeTo);
}