diff options
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.java | 11 |
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); } } |