aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/controllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-12-27 16:23:28 +0300
committerGravatar Vitaly Takmazov2018-01-12 09:12:09 +0300
commitbf5f2142d73a5745124d03f6b6f06c59873e47de (patch)
tree969d43a3bf6d39197313e16080b8b8472975cbe2 /juick-api/src/main/java/com/juick/api/controllers
parent0c78bc5c08632718eb94c0021cf3ee47fb8ddb82 (diff)
Messenger bot
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/controllers')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java11
1 files changed, 6 insertions, 5 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java
index fa57c017..835165ba 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/MessengerWebhook.java
@@ -17,7 +17,8 @@
package com.juick.api.controllers;
-import com.juick.api.MessengerBot;
+import com.github.messenger4j.exception.MessengerVerificationException;
+import com.juick.api.MessengerManager;
import com.juick.server.util.HttpForbiddenException;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
@@ -41,21 +42,21 @@ public class MessengerWebhook {
private static Logger logger = LoggerFactory.getLogger(MessengerWebhook.class);
@Inject
- MessengerBot fbBot;
+ private MessengerManager messengerManager;
@RequestMapping(value = "/fbwbhk", method = RequestMethod.GET)
public ResponseEntity<Integer> verifyHook(@RequestParam(name = "hub.mode") String hubMode,
@RequestParam(name = "hub.challenge") Integer hubChallenge,
@RequestParam(name = "hub.verify_token") String verifyToken) {
- if (hubMode.equals("subscribe") && verifyToken.equals(fbBot.getVerifyToken())) {
+ if (hubMode.equals("subscribe") && verifyToken.equals(messengerManager.getFacebookVerifyToken())) {
return new ResponseEntity<>(hubChallenge, HttpStatus.OK);
}
throw new HttpForbiddenException();
}
@RequestMapping(value = "/fbwbhk", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
- public void processUpdate(InputStream body) throws IOException {
+ public void processUpdate(@RequestHeader(name = "X-Hub-Signature", required = false) String signature, InputStream body) throws IOException, MessengerVerificationException {
String data = IOUtils.toString(body, StandardCharsets.UTF_8);
- logger.info("got data: {}", data);
+ messengerManager.processUpdate(signature, data);
}
}