# Chat

Kind: Class · Namespace: Sansar.Simulation · Assembly: Sansar.Simulation.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Simulation">Namespace <a href="/scripting/api/sansar.simulation"><code>Sansar.Simulation</code></a></span>
<span>Inherits <a href="/scripting/api/sansar.script/instanceinterface">Sansar.Script.InstanceInterface</a></span>
</div>

<span id="T:Sansar.Simulation.Chat"></span>

The Chat class handles chat subscriptions and sending messages to users and other scripts.

```csharp
public class Chat : Sansar.Script.InstanceInterface
```

## Members at a glance

| Kind | Members |
|---|---|
| **Fields** | [AllChannels](#allchannels) · [DefaultChannel](#defaultchannel) · [Script](#script) · [Server](#server) · [User](#user) |
| **Methods** | [MessageAllUsers](#messageallusers) · [MessageScript](#messagescript) · [Subscribe](#subscribe) |

## Fields

### AllChannels

<div class="api-card">
<span id="F:Sansar.Simulation.Chat.AllChannels"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("All channel subscription no longer allowed", false)]
public static readonly int AllChannels
```

Use as the channel argument for [`Chat.Subscribe`](/scripting/api/sansar.simulation/chat#subscribe-int32-string-action-boolean) to subscribe to all channels.

<details class="api-remarks"><summary>Remarks</summary>

No longer in use, now the same behavior as DefaultChannel

</details>

</div>

### DefaultChannel

<div class="api-card">
<span id="F:Sansar.Simulation.Chat.DefaultChannel"></span>

```csharp signature
public static readonly int DefaultChannel
```

Use as the channel argument for [`Chat.Subscribe`](/scripting/api/sansar.simulation/chat#subscribe-int32-string-action-boolean) to subscribe to the default channel

</div>

### Script

<div class="api-card">
<span id="F:Sansar.Simulation.Chat.Script"></span>

```csharp signature
public static readonly string Script
```

Indicates that the chat message originated from a script.

</div>

### Server

<div class="api-card">
<span id="F:Sansar.Simulation.Chat.Server"></span>

```csharp signature
public static readonly string Server
```

Indicates that the chat message originated from the server.

</div>

### User

<div class="api-card">
<span id="F:Sansar.Simulation.Chat.User"></span>

```csharp signature
public static readonly string User
```

Indicates that the chat message originated from a user.

</div>


## Methods

### MessageAllUsers

<div class="api-card" id="messageallusers-string">
<span id="M:Sansar.Simulation.Chat.MessageAllUsers(System.String)"></span>

```csharp signature
public void MessageAllUsers(string message)
```

Send a chat message to every user in the Experience.

| Parameter | Type | Description |
|---|---|---|
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The message to send. |

<details class="api-remarks"><summary>Remarks</summary>

Messages may be throttled.

</details>

</div>

<div class="api-card" id="messageallusers-string-action">
<span id="M:Sansar.Simulation.Chat.MessageAllUsers(System.String,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void MessageAllUsers(
    string message,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Send a chat message to every user in the Experience.

| Parameter | Type | Description |
|---|---|---|
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The message to send. |
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

Messages may be throttled.

</details>

</div>

### MessageScript

<div class="api-card">
<span id="M:Sansar.Simulation.Chat.MessageScript(System.String,Sansar.Script.ScriptId,System.Int32)"></span>

```csharp signature
public void MessageScript(
    string message,
    Sansar.Script.ScriptId scriptId,
    int channel
)
```

Send a string message to a specific script.

| Parameter | Type | Description |
|---|---|---|
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The message to send. |
| `scriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | The id of the script to send the message to. |
| `channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The channel to send the message on. |

<details class="api-remarks"><summary>Remarks</summary>

Only the script with the matching id will receive the message.

</details>

</div>

### Subscribe

<div class="api-card" id="subscribe-scriptid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(Sansar.Script.ScriptId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    Sansar.Script.ScriptId SourceScriptId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `SourceScriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | Sansar.Script.ScriptId id of the chat source. May be [`ScriptId.Invalid`](/scripting/api/sansar.script/scriptid#invalid) if the source is not a script. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-sessionid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(Sansar.Script.SessionId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    Sansar.Script.SessionId SourceId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `SourceId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId id of the chat source. May be [`SessionId.Invalid`](/scripting/api/sansar.script/sessionid#invalid) if the source is not an agent. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-int32-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    int Channel,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-string-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.String,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    string Source,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-int32-scriptid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,Sansar.Script.ScriptId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    int Channel,
    Sansar.Script.ScriptId SourceScriptId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `SourceScriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | Sansar.Script.ScriptId id of the chat source. May be [`ScriptId.Invalid`](/scripting/api/sansar.script/scriptid#invalid) if the source is not a script. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-int32-sessionid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,Sansar.Script.SessionId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    int Channel,
    Sansar.Script.SessionId SourceId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `SourceId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId id of the chat source. May be [`SessionId.Invalid`](/scripting/api/sansar.script/sessionid#invalid) if the source is not an agent. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-int32-string-subscriptionhandler-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,Sansar.Simulation.Chat.SubscriptionHandler,System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Simulation.ChatData>", false)]
public void Subscribe(
    int Channel,
    string Source,
    Chat.SubscriptionHandler callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `callback` | [Chat.SubscriptionHandler](/scripting/api/sansar.simulation/chat.subscriptionhandler) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

</div>

<div class="api-card" id="subscribe-int32-string-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    int Channel,
    string Source,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-string-scriptid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.String,Sansar.Script.ScriptId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    string Source,
    Sansar.Script.ScriptId SourceScriptId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceScriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | Sansar.Script.ScriptId id of the chat source. May be [`ScriptId.Invalid`](/scripting/api/sansar.script/scriptid#invalid) if the source is not a script. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-string-sessionid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.String,Sansar.Script.SessionId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    string Source,
    Sansar.Script.SessionId SourceId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId id of the chat source. May be [`SessionId.Invalid`](/scripting/api/sansar.script/sessionid#invalid) if the source is not an agent. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-int32-string-scriptid-subscriptionhandler-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,Sansar.Script.ScriptId,Sansar.Simulation.Chat.SubscriptionHandler,System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Simulation.ChatData>", false)]
public void Subscribe(
    int Channel,
    string Source,
    Sansar.Script.ScriptId SourceScriptId,
    Chat.SubscriptionHandler callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceScriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | Sansar.Script.ScriptId id of the chat source. May be [`ScriptId.Invalid`](/scripting/api/sansar.script/scriptid#invalid) if the source is not a script. |
| `callback` | [Chat.SubscriptionHandler](/scripting/api/sansar.simulation/chat.subscriptionhandler) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

</div>

<div class="api-card" id="subscribe-int32-string-scriptid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,Sansar.Script.ScriptId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    int Channel,
    string Source,
    Sansar.Script.ScriptId SourceScriptId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceScriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | Sansar.Script.ScriptId id of the chat source. May be [`ScriptId.Invalid`](/scripting/api/sansar.script/scriptid#invalid) if the source is not a script. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-int32-string-sessionid-subscriptionhandler-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,Sansar.Script.SessionId,Sansar.Simulation.Chat.SubscriptionHandler,System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Simulation.ChatData>", false)]
public void Subscribe(
    int Channel,
    string Source,
    Sansar.Script.SessionId SourceId,
    Chat.SubscriptionHandler callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId id of the chat source. May be [`SessionId.Invalid`](/scripting/api/sansar.script/sessionid#invalid) if the source is not an agent. |
| `callback` | [Chat.SubscriptionHandler](/scripting/api/sansar.simulation/chat.subscriptionhandler) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

</div>

<div class="api-card" id="subscribe-int32-string-sessionid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,Sansar.Script.SessionId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    int Channel,
    string Source,
    Sansar.Script.SessionId SourceId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId id of the chat source. May be [`SessionId.Invalid`](/scripting/api/sansar.script/sessionid#invalid) if the source is not an agent. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

<div class="api-card" id="subscribe-int32-string-sessionid-scriptid-subscriptionhandler-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,Sansar.Script.SessionId,Sansar.Script.ScriptId,Sansar.Simulation.Chat.SubscriptionHandler,System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Simulation.ChatData>", false)]
public void Subscribe(
    int Channel,
    string Source,
    Sansar.Script.SessionId SourceId,
    Sansar.Script.ScriptId SourceScriptId,
    Chat.SubscriptionHandler callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId id of the chat source. May be [`SessionId.Invalid`](/scripting/api/sansar.script/sessionid#invalid) if the source is not an agent. |
| `SourceScriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | Sansar.Script.ScriptId id of the chat source. May be [`ScriptId.Invalid`](/scripting/api/sansar.script/scriptid#invalid) if the source is not a script. |
| `callback` | [Chat.SubscriptionHandler](/scripting/api/sansar.simulation/chat.subscriptionhandler) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

</div>

<div class="api-card" id="subscribe-int32-string-sessionid-scriptid-action-boolean">
<span id="M:Sansar.Simulation.Chat.Subscribe(System.Int32,System.String,Sansar.Script.SessionId,Sansar.Script.ScriptId,System.Action{Sansar.Simulation.ChatData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    int Channel,
    string Source,
    Sansar.Script.SessionId SourceId,
    Sansar.Script.ScriptId SourceScriptId,
    Action<ChatData> callback,
    bool persistent
)
```

Subscribes to Chat Events.

| Parameter | Type | Description |
|---|---|---|
| `Channel` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | int channel which the chat occurs on. |
| `Source` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string source of the chat: system, user or script. |
| `SourceId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId id of the chat source. May be [`SessionId.Invalid`](/scripting/api/sansar.script/sessionid#invalid) if the source is not an agent. |
| `SourceScriptId` | [Sansar.Script.ScriptId](/scripting/api/sansar.script/scriptid) | Sansar.Script.ScriptId id of the chat source. May be [`ScriptId.Invalid`](/scripting/api/sansar.script/scriptid#invalid) if the source is not a script. |
| `callback` | [Action&lt;ChatData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>


## Used in examples

- [StatsExample.cs](/scripting/examples/stats-example)
- [VisitorTrackerExample.cs](/scripting/examples/visitor-tracker)
- [BanHammerExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/BanHammerExample.cs)
- `CameraShakeExample.cs`
- `ColorLutExample.cs`
- [CoroutineEventExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/CoroutineEventExample.cs)
- [CoroutineExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/CoroutineExample.cs)
- [GravityExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/GravityExample.cs)
- [MediaOverrideExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/MediaOverrideExample.cs)
- [MemoryExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/MemoryExample.cs)
- [ObjectScriptExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ObjectScriptExample.cs)
- [QuestDebugExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/QuestDebugExample.cs)

…and 5 more examples in the snapshot.

<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>