---
# System prepended metadata

title: End sesison message

---

# End sesison message
## Schema
```javascript=
{
    settings:{
        endSessionMessage:{
            isEnabled: Boolean,
            default: String,
            platforms:[
               { platformId: Number, text: String } 
            ]
        }
    }
}
```

## Algorithm

By default, a session is created with the following settings:

```javascript=
{
    settings:{
        endSessionMessage:{
            isEnabled: false
        }
    }
}
```

In this case, if the session ends with session listenear, the end session message will not be sent. And the session will be closed properly.

If one of the participants initiates a session closure, then the end session message will not be sent either.

In order to enable end sesion message in a session, you need to use the API with the appropriate settings.If the functionality is enabled, but the other fields are empty, then the messages will be taken from the platforms and systemConfig collections.

At the end of the session, we will check if the settings in the platforms field have a message for the entity on its platform, if there is no such field, then in this case the value of the default field is used

| field | requried | description
| ----- | -------- | -----------
| sendEndSessionMessage | true | Enable or disable functionality for session
| default | false | Setup default end session message in session
| platforms | false | Object where key is platformId, and value is end session message for this platform

## API

method: PATCH
url: ```/modules/:moduleFullName/sessions/:sessionId/end-session-message```
body:
```javascript=
{
    sendEndSessionMessage: String,
    default: String,
    platforms: {
        [platformId:Number]: String
    }
}
```

Result:
Status: 200
Response:
```javascript=
{
    sessionId: Number,
    endSessionMessage:{
        isEnabled: Boolean,
        default: String,
        platforms:[
           { platformId: Number, text: String } 
        ]
    }
}
```
### Validations

1. moduleFullName - must exists in DB and related to botId, what we have in session
2. sessionId - must exists in DB and be active and conversation flow of this session related to moduleFullName
3. sendEndSessionMessage - is required and type is Boolean
4. default - must be not empty string or null
5. platforms - must be object with string values. After validation we use just  keys which exists in DB