Created the DialogflowHandler. Useful to redirect not found messages to dialogflow

This commit is contained in:
mathias 2021-10-02 17:24:21 +02:00
parent d1dd4a5ab8
commit aca8c36dfd
No known key found for this signature in database
GPG Key ID: 8950DF62139C852A

View File

@ -0,0 +1,39 @@
package de.gnmyt.autoresponder.handler;
import de.gnmyt.autoresponder.integration.DialogflowIntegration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class DialogflowHandler extends NotFoundHandler {
private static final Logger LOG = LoggerFactory.getLogger(DialogflowHandler.class);
private DialogflowIntegration dialogflowIntegration;
/**
* Constructor of the {@link DialogflowHandler}.
* <p>
* Runs whenever the request could not be found and redirects the message to dialogflow
*
* @param credentials Your credentials file, created by your google api
*/
public DialogflowHandler(File credentials) {
try {
this.dialogflowIntegration = new DialogflowIntegration(credentials);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public List<String> handleRequest(String sender, String message) {
ArrayList<String> messages = new ArrayList<>();
messages.add(dialogflowIntegration.getMessage(message, sender));
return messages;
}
}