Skip to content

Commit

Permalink
adding button cancel/remind me again tomorrow/remind me again next we…
Browse files Browse the repository at this point in the history
…ek (#52)

* adding button cancel/remind me again tomorrow/remind me again next week
and update the buttons so when someone click the remind me again to ping
them and not the one who set the reminder
* added new feature so people that dont own the remind cant postpone it
and renamed caseDeleteReminder to caseCancelReminder
* adding seconds when you list reminders so the user can know exactly
what time the reminder will notify him (mostly used in recurring reminders)
* updating quarkus to the latest version
  • Loading branch information
HoodElliot authored and JChrist committed May 21, 2019
1 parent ca83c90 commit 28f74be
Show file tree
Hide file tree
Showing 18 changed files with 754 additions and 168 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
a) Bot name
b) Path of the private key
c) Credentials for the connection with database
d) Add production url to database configuration with key buttonUrl and value your production url so you can redirect user when he clicks the button also you can set that from google chat see help 6
## How to use it.
The current functionality that this bot supports after you invite it is the following:
1) Set a reminder
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<groupId>gr.cytech</groupId>
<artifactId>chatreminderbot</artifactId>
<name>Chat Reminder Bot</name>
<version>1.14.0</version>
<version>1.15.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<surefire-plugin.version>3.0.0-M3</surefire-plugin.version>

<quarkus.version>0.14.0</quarkus.version>
<quarkus.version>0.15.0</quarkus.version>
<prettytime.version>4.0.2.Final</prettytime.version>
<google.api.client.version>1.28.0</google.api.client.version>
<guava.version>27.1-jre</guava.version>
Expand Down
78 changes: 32 additions & 46 deletions src/main/java/gr/cytech/chatreminderbot/rest/BotResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import gr.cytech.chatreminderbot.rest.GoogleCards.CardResponseBuilder;
import gr.cytech.chatreminderbot.rest.controlCases.Control;
import gr.cytech.chatreminderbot.rest.message.Message;
import gr.cytech.chatreminderbot.rest.message.Request;
import gr.cytech.chatreminderbot.rest.message.Sender;
import gr.cytech.chatreminderbot.rest.message.ThreadM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import static gr.cytech.chatreminderbot.rest.GoogleCards.CardResponseBuilder.NEW_MESSAGE;
import static gr.cytech.chatreminderbot.rest.controlCases.Control.KEYWORD_REMIND;
import static gr.cytech.chatreminderbot.rest.message.Action.*;

@Path("/services")
public class BotResource {
private static final Logger logger = LoggerFactory.getLogger(BotResource.class);
Expand All @@ -33,6 +35,9 @@ public class BotResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String handleReq(Request req) {
if (req.getAction() != null) {
manipulateRequestBasedOnParameters(req);
}
control.setRequest(req);
String spaceId = req.getMessage().getThread().getSpaceId();
String message;
Expand All @@ -42,51 +47,32 @@ public String handleReq(Request req) {
logger.warn("Error from message:{}", req.getMessage().getText(), e);
message = "Not even a clue what you just said";
}
return responseBuild(spaceId, message);
}

@GET
@Path("/button")
public String onButtonClick(@Context HttpServletRequest request) {
Sender sender = new Sender();
ThreadM threadM = new ThreadM();

sender.setName(request.getParameter("name"));
threadM.setName("space/" + request.getParameter("space") + "/thread/" + request.getParameter("thread"));

//create reminder and get the when
//creating the full text for reminder
String text = "remind me "
+ request.getParameter("text")
+ " in 10 minutes";

//create the Request using the updated message
Message message = new Message();
//case message is already build in json
if (message.startsWith(ALREADY_BUILD_MESSAGE_WITH_ACTION)) {
return message;
}
return new CardResponseBuilder()
.cardWithOnlyText("spaces/" + spaceId, message, NEW_MESSAGE);
}

message.setSender(sender);
message.setThread(threadM);
message.setText(text);
private void manipulateRequestBasedOnParameters(Request req) {
String text = req.getAction().getParameters().get(2).get("value");
int reminderId = Integer.valueOf(req.getAction().getParameters().get(1).get("value"));

Request req = new Request();
req.setMessage(message);
//open tab to get the requirements then immediately close it and handle the request
handleReq(req);
return "<html>"
+ "<head></head>"
+ "<body>"
+ "<script>"
+ "window.close();"
+ "</script>"
+ "</body>"
+ "</html>";
}
req.getMessage().getSender().setName(req.getUser().getName());

private String responseBuild(String spaceId, String message) {
return new CardResponseBuilder()
.thread("spaces/" + spaceId)
.textParagraph(message)
.build();
String remindMe = KEYWORD_REMIND + " me " + text + " ";

if (REMIND_AGAIN_IN_10_MINUTES.equals(req.getAction().getActionMethodName())) {
req.getMessage().setText(remindMe + "in 10 minutes");
} else if (REMIND_AGAIN_TOMORROW.equals(req.getAction().getActionMethodName())) {
req.getMessage().setText(remindMe + "tomorrow");
} else if (REMIND_AGAIN_NEXT_WEEK.equals(req.getAction().getActionMethodName())) {
req.getMessage().setText(remindMe + "in next week");
} else if (CANCEL_REMINDER.equals(req.getAction().getActionMethodName())) {
req.getMessage().setText("delete " + reminderId);
}
}

}
Loading

0 comments on commit 28f74be

Please sign in to comment.