From bf5f2142d73a5745124d03f6b6f06c59873e47de Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 27 Dec 2017 16:23:28 +0300 Subject: Messenger bot --- .../main/java/com/juick/api/controllers/MessengerWebhook.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'juick-api/src/main/java/com/juick/api/controllers') 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 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); } } -- cgit v1.2.3