RingCentral - How to use ringcentral Webhook features for events in Java
Ring central cloud communication Platform provides webhook to notify you for any events like voicemail, SMS from your account.In this blog we will see how to set up you application to receive notifications from ringcentral platform through webhook.
override the handle method to set status to 200 OK to return success response from webserver.
2. you can use service like ngrok download to expose your server publicly.
3. Create a java project using your favorite IDE and import ringcentral sdk dependency compile 'com.ringcentral:ringcentral:1.0.0-beta10'
- I am using jetty server to run my webserver which is listening to the port 5000.
Server server = new Server(5000);server.setHandler(new WebhookServer()); server.start(); server.join();
override the handle method to set status to 200 OK to return success response from webserver.
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Validation-Token", request.getHeader("Validation-Token")); if(request.getMethod() == "POST") { String body = request.getReader().lines().collect(java.util.stream.Collectors.joining(System.lineSeparator())); System.out.println(body); } response.getWriter().println("OK"); baseRequest.setHandled(true);}
2. you can use service like ngrok download to expose your server publicly.
3. Create a java project using your favorite IDE and import ringcentral sdk dependency compile 'com.ringcentral:ringcentral:1.0.0-beta10'
- First authroize with your ringcentral account
- Create subscription with webhook with SMS api filter
- Provide you webserver url configured in step 1.
RestClient rc = new RestClient(RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_SERVER);rc.authorize(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD);String[] eventFilters = new String[]{"/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS"};CreateSubscriptionRequest createSubscriptionRequest = new CreateSubscriptionRequest() .eventFilters(eventFilters) .deliveryMode( new NotificationDeliveryModeRequest() .transportType("WebHook") .address(DELIVERY_ADDRESS) );SubscriptionInfo result = rc.restapi().subscription().post(createSubscriptionRequest); rc.revoke();

Comments
Post a Comment