> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NSChatSessionEntity

> Chat sessions belong to a chat topic, and contain messages to/from users. Carrier object for ChatSessionEntity.

Chat sessions belong to a chat topic, and contain messages to/from users. Carrier object for ChatSessionEntity.

## Constructors

### NSChatSessionEntity()

```crmscript theme={null}
NSChatSessionEntity
```

Initializes a new instance of the NSChatSessionEntity class.

## Methods

## GetAlertLevel()

```crmscript theme={null}
Integer GetAlertLevel()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The alert level for this chat session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer alertLevel = thing.GetAlertLevel();
```

## GetChatbotIsActive()

```crmscript theme={null}
Bool GetChatbotIsActive()
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - Indicates that a chatbot is active on the session. This will cause bot triggers to fire. Set to 0 when bot hands off to user.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Bool chatbotIsActive = thing.GetChatbotIsActive();
```

## GetChatSessionId()

```crmscript theme={null}
Integer GetChatSessionId()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The primary key (auto-incremented).

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer chatSessionId = thing.GetChatSessionId();
```

## GetContact()

```crmscript theme={null}
NSContact GetContact()
```

**Returns:** [CRMScript.NetServer.NSContact](CRMScript.NetServer.NSContact) - Contact this session is connected to. Could be empty if we don't know exactly.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSContact contact = thing.GetContact();
```

## GetCustomerAlias()

```crmscript theme={null}
String GetCustomerAlias()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The alias for the customer.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerAlias = thing.GetCustomerAlias();
```

## GetCustomerCompanyName()

```crmscript theme={null}
String GetCustomerCompanyName()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The name of the customers company, if provided.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerCompanyName = thing.GetCustomerCompanyName();
```

## GetCustomerConsented()

```crmscript theme={null}
Bool GetCustomerConsented()
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - The customer consented when starting the session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Bool customerConsented = thing.GetCustomerConsented();
```

## GetCustomerEmail()

```crmscript theme={null}
String GetCustomerEmail()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The email address of the customer, if provided.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerEmail = thing.GetCustomerEmail();
```

## GetCustomerHost()

```crmscript theme={null}
String GetCustomerHost()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The hostname or IP address for the customer.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerHost = thing.GetCustomerHost();
```

## GetCustomerName()

```crmscript theme={null}
String GetCustomerName()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The name of customer, if provided.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerName = thing.GetCustomerName();
```

## GetCustomerPhone()

```crmscript theme={null}
String GetCustomerPhone()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The phone number of the customer, if provided.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerPhone = thing.GetCustomerPhone();
```

## GetFirstMessage()

```crmscript theme={null}
String GetFirstMessage()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - A copy of the first message in the chat session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String firstMessage = thing.GetFirstMessage();
```

## GetFlags()

```crmscript theme={null}
Integer GetFlags()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - Various flags for the chat session. See \<xref href="CRMScript.NetServer.ChatSessionFlags" data-throw-if-not-resolved="false">\</xref>.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer flags = thing.GetFlags();
```

## GetInitialQueuePos()

```crmscript theme={null}
Integer GetInitialQueuePos()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The initial queue pos (the number of pending sessions + 1) when the session was requested.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer initialQueuePos = thing.GetInitialQueuePos();
```

## GetLastMessage()

```crmscript theme={null}
String GetLastMessage()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - A copy of the last message in the chat session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String lastMessage = thing.GetLastMessage();
```

## GetPerson()

```crmscript theme={null}
NSPerson GetPerson()
```

**Returns:** [CRMScript.NetServer.NSPerson](CRMScript.NetServer.NSPerson) - Customer person in this session. Could be empty if we don't know exactly.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSPerson person = thing.GetPerson();
```

## GetProject()

```crmscript theme={null}
NSProject GetProject()
```

**Returns:** [CRMScript.NetServer.NSProject](CRMScript.NetServer.NSProject) - Project the session is connected to. Could be empty if we don't know exactly.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSProject project = thing.GetProject();
```

## GetRank()

```crmscript theme={null}
Integer GetRank()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - Lowest possible unique number for active sessions for user. User for color index. Starting at 1.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer rank = thing.GetRank();
```

## GetSale()

```crmscript theme={null}
NSSale GetSale()
```

**Returns:** [CRMScript.NetServer.NSSale](CRMScript.NetServer.NSSale) - Sale the session is connected to. Could be empty if we don't know exactly.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSSale sale = thing.GetSale();
```

## GetSessionKey()

```crmscript theme={null}
String GetSessionKey()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - Key used to authenticate the session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String sessionKey = thing.GetSessionKey();
```

## GetStatus()

```crmscript theme={null}
Integer GetStatus()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The status for the session. See \<xref href="CRMScript.NetServer.ChatSessionStatus" data-throw-if-not-resolved="false">\</xref>.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer status = thing.GetStatus();
```

## GetTicket()

```crmscript theme={null}
NSTicket GetTicket()
```

**Returns:** [CRMScript.NetServer.NSTicket](CRMScript.NetServer.NSTicket) - Ticket the session is connected to. Could be empty if we don't know exactly.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSTicket ticket = thing.GetTicket();
```

## GetTopicId()

```crmscript theme={null}
Integer GetTopicId()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The reference to the associated chat topic.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer topicId = thing.GetTopicId();
```

## GetTransferTo()

```crmscript theme={null}
NSAssociate GetTransferTo()
```

**Returns:** [CRMScript.NetServer.NSAssociate](CRMScript.NetServer.NSAssociate) - User agent that has a pending transfer of the chat session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSAssociate transferTo = thing.GetTransferTo();
```

## GetUser()

```crmscript theme={null}
NSAssociate GetUser()
```

**Returns:** [CRMScript.NetServer.NSAssociate](CRMScript.NetServer.NSAssociate) - User agent handling this session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSAssociate user = thing.GetUser();
```

## GetWhenEnded()

```crmscript theme={null}
DateTime GetWhenEnded()
```

**Returns:** [CRMScript.Global.DateTime](CRMScript.Global.DateTime) - When the session was ended.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenEnded = thing.GetWhenEnded();
```

## GetWhenFetched()

```crmscript theme={null}
DateTime GetWhenFetched()
```

**Returns:** [CRMScript.Global.DateTime](CRMScript.Global.DateTime) - The last time the customer's client re-fetched the data. Used to detect dead session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenFetched = thing.GetWhenFetched();
```

## GetWhenIdle()

```crmscript theme={null}
DateTime GetWhenIdle()
```

**Returns:** [CRMScript.Global.DateTime](CRMScript.Global.DateTime) - The last time anyone sent a message for this session.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenIdle = thing.GetWhenIdle();
```

## GetWhenRequested()

```crmscript theme={null}
DateTime GetWhenRequested()
```

**Returns:** [CRMScript.Global.DateTime](CRMScript.Global.DateTime) - When the session was requested by the customer.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenRequested = thing.GetWhenRequested();
```

## GetWhenStarted()

```crmscript theme={null}
DateTime GetWhenStarted()
```

**Returns:** [CRMScript.Global.DateTime](CRMScript.Global.DateTime) - When the session was accepted by a user.

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenStarted = thing.GetWhenStarted();
```

## SetAlertLevel(Integer)

```crmscript theme={null}
Void SetAlertLevel(Integer alertLevel)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer alertLevel;
thing.SetAlertLevel(alertLevel);
```

## SetChatbotIsActive(Bool)

```crmscript theme={null}
Void SetChatbotIsActive(Bool chatbotIsActive)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Bool chatbotIsActive;
thing.SetChatbotIsActive(chatbotIsActive);
```

## SetChatSessionId(Integer)

```crmscript theme={null}
Void SetChatSessionId(Integer chatSessionId)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer chatSessionId;
thing.SetChatSessionId(chatSessionId);
```

## SetContact(NSContact)

```crmscript theme={null}
Void SetContact(NSContact contact)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSContact contact;
thing.SetContact(contact);
```

## SetCustomerAlias(String)

```crmscript theme={null}
Void SetCustomerAlias(String customerAlias)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerAlias;
thing.SetCustomerAlias(customerAlias);
```

## SetCustomerCompanyName(String)

```crmscript theme={null}
Void SetCustomerCompanyName(String customerCompanyName)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerCompanyName;
thing.SetCustomerCompanyName(customerCompanyName);
```

## SetCustomerConsented(Bool)

```crmscript theme={null}
Void SetCustomerConsented(Bool customerConsented)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Bool customerConsented;
thing.SetCustomerConsented(customerConsented);
```

## SetCustomerEmail(String)

```crmscript theme={null}
Void SetCustomerEmail(String customerEmail)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerEmail;
thing.SetCustomerEmail(customerEmail);
```

## SetCustomerHost(String)

```crmscript theme={null}
Void SetCustomerHost(String customerHost)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerHost;
thing.SetCustomerHost(customerHost);
```

## SetCustomerName(String)

```crmscript theme={null}
Void SetCustomerName(String customerName)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerName;
thing.SetCustomerName(customerName);
```

## SetCustomerPhone(String)

```crmscript theme={null}
Void SetCustomerPhone(String customerPhone)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String customerPhone;
thing.SetCustomerPhone(customerPhone);
```

## SetFirstMessage(String)

```crmscript theme={null}
Void SetFirstMessage(String firstMessage)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String firstMessage;
thing.SetFirstMessage(firstMessage);
```

## SetFlags(Integer)

```crmscript theme={null}
Void SetFlags(Integer flags)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  n
</Note>

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer flags;
thing.SetFlags(flags);
```

## SetInitialQueuePos(Integer)

```crmscript theme={null}
Void SetInitialQueuePos(Integer initialQueuePos)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer initialQueuePos;
thing.SetInitialQueuePos(initialQueuePos);
```

## SetLastMessage(String)

```crmscript theme={null}
Void SetLastMessage(String lastMessage)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String lastMessage;
thing.SetLastMessage(lastMessage);
```

## SetPerson(NSPerson)

```crmscript theme={null}
Void SetPerson(NSPerson person)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSPerson person;
thing.SetPerson(person);
```

## SetProject(NSProject)

```crmscript theme={null}
Void SetProject(NSProject project)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSProject project;
thing.SetProject(project);
```

## SetRank(Integer)

```crmscript theme={null}
Void SetRank(Integer rank)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer rank;
thing.SetRank(rank);
```

## SetSale(NSSale)

```crmscript theme={null}
Void SetSale(NSSale sale)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSSale sale;
thing.SetSale(sale);
```

## SetSessionKey(String)

```crmscript theme={null}
Void SetSessionKey(String sessionKey)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
String sessionKey;
thing.SetSessionKey(sessionKey);
```

## SetStatus(Integer)

```crmscript theme={null}
Void SetStatus(Integer status)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer status;
thing.SetStatus(status);
```

## SetTicket(NSTicket)

```crmscript theme={null}
Void SetTicket(NSTicket ticket)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSTicket ticket;
thing.SetTicket(ticket);
```

## SetTopicId(Integer)

```crmscript theme={null}
Void SetTopicId(Integer topicId)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
Integer topicId;
thing.SetTopicId(topicId);
```

## SetTransferTo(NSAssociate)

```crmscript theme={null}
Void SetTransferTo(NSAssociate transferTo)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSAssociate transferTo;
thing.SetTransferTo(transferTo);
```

## SetUser(NSAssociate)

```crmscript theme={null}
Void SetUser(NSAssociate user)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
NSAssociate user;
thing.SetUser(user);
```

## SetWhenEnded(DateTime)

```crmscript theme={null}
Void SetWhenEnded(DateTime whenEnded)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenEnded;
thing.SetWhenEnded(whenEnded);
```

## SetWhenFetched(DateTime)

```crmscript theme={null}
Void SetWhenFetched(DateTime whenFetched)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenFetched;
thing.SetWhenFetched(whenFetched);
```

## SetWhenIdle(DateTime)

```crmscript theme={null}
Void SetWhenIdle(DateTime whenIdle)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenIdle;
thing.SetWhenIdle(whenIdle);
```

## SetWhenRequested(DateTime)

```crmscript theme={null}
Void SetWhenRequested(DateTime whenRequested)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenRequested;
thing.SetWhenRequested(whenRequested);
```

## SetWhenStarted(DateTime)

```crmscript theme={null}
Void SetWhenStarted(DateTime whenStarted)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSChatSessionEntity thing;
DateTime whenStarted;
thing.SetWhenStarted(whenStarted);
```


## Related topics

- [NSChatAgent](/en/automation/crmscript/reference/CRMScript.NetServer.NSChatAgent.md)
- [Namespace CRMScript.NetServer](/en/automation/crmscript/reference/CRMScript.NetServer.md)
- [Delete Chat Session Entity](/en/api/reference/restful/rest/chatsession/delete-chat-session-entity.md)
- [Get Chat Session Entity](/en/api/reference/restful/rest/chatsession/get-chat-session-entity.md)
- [Post Chat Session Entity](/en/api/reference/restful/rest/chatsession/post-chat-session-entity.md)
- [Default Chat Session Entity](/en/api/reference/restful/rest/chatsession/default-chat-session-entity.md)
