0

This is how my spring boot controller looks like:

@RestController
public class WhatsappController {
    private final String VERIFICATION_TOKEN = "12345";

    @GetMapping("/webhook")
    public ResponseEntity<String> verifyWebhook(@RequestParam("hub.mode") String mode,
                                                @RequestParam("hub.challenge") String challenge,
                                                @RequestParam("hub.verify_token") String token) {
        if (mode.equals("subscribe") && token.equals(VERIFICATION_TOKEN)) {
            return new ResponseEntity<>(challenge, HttpStatus.OK);
        } else {
            return new ResponseEntity<>("Verification token or mode mismatch", HttpStatus.FORBIDDEN);
        }
    }
}

But when I configure ngrok URL with Whatsapp it says:

The callback URL or verify token couldn't be validated. Please verify the provided information or try again later.

Please tell me what I am doing wrong!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Does this answer your question? [The Callback URL or Verify Token couldn't be validated. Please verify the provided information or try again later](https://stackoverflow.com/questions/60544871/the-callback-url-or-verify-token-couldnt-be-validated-please-verify-the-provid) – Ahmed Ashour Jan 21 '23 at 17:04
  • Thanks for sharing but it does not. – akash goyal Jan 21 '23 at 17:07

3 Answers3

1

I was able to solve the issue by deploying my code to on AWS with an actual https URL. The issue was because of ngrok.

0

You can try this:

@RequestMapping(value = "/webhook", method = RequestMethod.GET)
public ResponseEntity<?> verifyToken(@RequestParam("hub.mode") String mode,
                                     @RequestParam("hub.challenge") String challenge,
                                     @RequestParam("hub.verify_token") String token) {
    String verify_token = "token_webhook";
    if (mode.equals("subscribe") && token.equals(verify_token)) {
        System.out.println("WEBHOOK_VERIFIED");
        return new ResponseEntity<String>(challenge, HttpStatus.OK);
    } else {
        return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
    }
}
zforgo
  • 2,508
  • 2
  • 14
  • 22
  • 1
    Can you add a little more explanation why this code would improve the situation would be nice? – MadMike Apr 19 '23 at 11:53
0

If you are using ngrok try https url provided by them. enter image description here

VipinSC
  • 11
  • 4