Websocket (Realtime)

You will learn about WAPIM WebSocket on this page.

When you want to work real-time on the WhatsApp API, Wapim offers you a WebSocket connection. In this way, you can process all updates on your WhatsApp account in real time without any additional development. With this feature, you can even develop WhatsApp Web clone application.

<html>
	<body>
		Hello WAPIM WS | Please check console!
	</body>

	<script>
		let socket = new WebSocket('wss://api.wapim.io/ws?token=YOUR_WAPIM_TOKEN');

		socket.onopen = function(e) {
			console.log('[open] Connection established');
		};

		socket.onmessage = function(event) {
			console.log(`[message] Data received from server: ${event.data}`);
		};

		socket.onclose = function(event) {
			if (event.wasClean) {
				console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
			} else {
				// e.g. server process killed or network down
				// event.code is usually 1006 in this case
				console.log('[close] Connection died');
			}
		};

		socket.onerror = function(error) {
			console.log(`[error] ${error.message}`);
		};
	</script>
</html>

Last updated