out.println("Message received, length is " + textMessage.getPayloadLength()); View source on GitHub Configuring Spring to use our manager A WebSocket connection is established by the client sending a regular HTTP request. The server informs the client that this endpoint is expecting WebSocket data with a binding that begins philippines mobile number example with an HTTP 101 Switching Protocols response . The client confirms this and starts sending messages.
With a little configuration, Spring can handle all of this for us. In the same package containing your existing classes, create a new class called WebSocketConfig. This class configures Spring to ensure that requests to a particular path (in our case /messages) will be handled by our code WebSocketHandler above.

Java Copy the code // Note: package name will depend on your group and artifact name // Your IDE should be able to help you here package lol.
gilliard.websocketstranscription; import org.springframework.context.annotation.Configuration; import org.springframework.web.socket.config.annotation.EnableWebSocket; import org.springframework.web.socket.config.annotation.WebSocketConfigurer; @Configuration @EnableWebSocket public class WebSocketConfig implements WebSocketConfigurer { } This does not compile as is, because for the implementation of WebSocketConfigurer, we need to implement a method called registerWebSocketHandlers : Java Copy the code @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.
addHandler(new TwilioMediaStreamsHandler(), "/messages").setAllowedOrigins("*"); } See the full code on GitHub Broadcasting a phone call That's enough to handle WebSocket clients; now we need to set up something to send data to our WebSocket endpoint.
Enter Twilio Media Streams . Twilio 101 You can buy a Twilio phone number and configure what happens when someone calls it by creating a webhook that responds with a configuration language we like to call TwiML .
The Spring Boot application will serve this TwiML and support WebSocket connections. Use the Twilio Java Helper library , adding the following to the <dependency> section <dependencies> , pom.xmlnext to the dependency spring-boot-starter-websocket : XML Copy the code