---
updatedAt: 2025-11-11T16:54:55.000Z
agentTools:
  projectIndex: https://beamable2.readme.io/llms.txt
---

# Notifications - Code

Allow game makers to message players, regardless if game is running [LIVE-Notifications-02]

<ul class="breadcrumb">
  <li><a href="/docs/">Docs</a></li>
  <li><a href="/docs/live-ops">Live Ops</a></li>
  <li><a href="/docs/notifications-feature-overview">Notifications</a></li>
  <li>Notifications - Code</li>
</ul>

<div class="links">
  <a class="link normal" href="/docs/notifications-feature-overview" style={{textDecoration: 'none'}}>Overview</a>
  <a class="link active" href="/docs/notifications-code" style={{textDecoration: 'none'}}>Code</a>
</div>

<HTMLBlock>{`
<style>
  /* The "X" image indicating "Not available" */
  .xIcon 
  {
    display: inline !important;
  	-moz-box-sizing: border-box !important;
  	box-sizing: border-box !important;
    border:none !important;
    border-size: 0px !important;
  	background: url('https://files.readme.io/d51e4da-x-16.png') no-repeat  !important;
  	width: 16px !important;
  	height: 16px !important;
    vertical-align: middle !important;
  	padding-left: 20px !important;
  }
  
  /* Images within tables */
  .markdown-body td img {
		display: block !important;
  	margin: auto !important;
    max-width:35px !important;
    max-height:35px !important;
  }
  
  /* Column #1 within tables */
  .markdown-body table td:nth-child(1)
  {
    width:150px !important;
    min-width:150px !important;
    max-width:150px !important;
  }
  
  
</style>
`}</HTMLBlock>

## Overview

The Notifications feature can be accessed via the NotificationsService from the Beamable API. Notifications primarily function using a [Publish-subscribe pattern](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern), where objects that should react to incoming messages (the "subscribers") listen for messages being sent out by another object (the "publishers"). Following this pattern, the API is quite simple.

## Usages

### Example Callback Function

When a subscribed object receives a message, the message carries some data with it that can provide extra content about the event that occurred. For the purposes of this document, this function will be used:

```csharp
void CallbackAction(object callbackObject)
{
    //Some code that uses the callback object
}
```

### Subscribe/Unsubscribe

Subscriptions are PlayerId based, so an event published by the server (e.g., a microservice) must specify your PlayerId in order for your client to receive the event.

```csharp
var beamable = BeamContext.Default;

//Start listening to events published with the specified message name
beamable.Api.NotificationService.Subscribe("messageName", CallbackAction );

//Stop listening for events with the specified message name
beamable.Api.NotificationService.Unsubscribe("messageName", CallbackAction );
```

### Publish (from Microservice)

```csharp
public async Task SendNotificationFromMicroservice(List<long> playerIds, string context, object payload)
{
    var json = JsonUtility.ToJson(payload);
    await Services.Notifications.NotifyPlayer(playerIds, context, json);
}
```

<HTMLBlock>{`
<style>
  .links {
    padding: 0 1em 1em 0;
    display: flex;
    flex-flow: row wrap;
  }

  .link {
    margin-right: 2em;
    padding: 0.3em 1.5em;
    box-sizing: border-box;
  }

  .active {
    border: 1px solid #4274f6;
    background-color: #4274f6;
    color: white;
  }

  .normal {
    background-color: white;
    border: 1px solid gray;
    cursor:pointer;
    text-decoration: none;
  }

  .normal:active {
    background-color: #c4d4ff;
  }

  .normal:hover {
    background-color: #c4d4ff;
  }

  .active:active {
    color: white;
  }

  .active:hover {
    color: white;
  }
  
  ul.breadcrumb {
    padding: 10px 16px;
    list-style: none;
  }
  ul.breadcrumb li {
    display: inline;
    font-size: 18px;
  }
  ul.breadcrumb li+li:before {
    padding: 8px;
    color: black;
    content: "/\\00a0";
  }
  ul.breadcrumb li a {
    color: #0275d8;
    text-decoration: none;
  }
  ul.breadcrumb li a:hover {
    color: #01447e;
    text-decoration: underline;
  }
</style>
`}</HTMLBlock>