Retrieve Offline Notifications using Web Socket
Last updated on
Use the following function to retrieve an offline notification:
- Go
- Python
- Java
err := notificationService.GetNotificationMessage()
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.core import get_access_token, get_base_url
from accelbyte_py_sdk.core import WebsocketsWSClient
# Full list of accepted web socket lobby messages are in 'accelbyte_py_sdk.api.lobby.wss_models'.
from accelbyte_py_sdk.api.lobby.wss_models import OfflineNotificationRequest
base_url, error = get_base_url()
if error:
exit(1)
access_token, error = get_access_token()
if error:
exit(1)
client = WebsocketsWSClient(
uri=base_url,
access_token=access_token
)
await client.connect()
# 1. Create an instance of the desired web socket message type.
offline_notification_request = OfflineNotificationRequest()
# 2. Format then send the web socket message.
# Can only be done after 'await client.connect()'.
await client.send(offline_notification_request.to_wsm())
final String request_id = GenerateRandomId(64);
final CountDownLatch response = new CountDownLatch(1);
final StringBuilder responseMessage = new StringBuilder();
WebSocketListener listener = new WebSocketListener() {
@Override
public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
if (response.getCount() > 0) {
responseMessage.append(text);
response.countDown();
}
}
};
OkhttpWebSocketClient ws = OkhttpWebSocketClient.create(
new DefaultConfigRepository(),
DefaultTokenRepository.getInstance(),
listener);
String requestMessage = OfflineNotificationRequest.builder()
.id(requestId)
.build()
.toWSM();
ws.sendMessage(requestMessage);
response.await(10, TimeUnit.SECONDS);