Appearance
Session End Event
Triggered when the call session ends.
Event Structure
json
{
"type": "session_end",
"session": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"account_id": "account-123",
"phone_number": "+1234567890"
}
}Fields
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Always "session_end" |
session.id | string (UUID) | Yes | Session identifier |
session.account_id | string | Yes | Account identifier |
session.phone_number | string | Yes | Phone number for this flow session |
Response
No action is allowed for session_end events. Always return 204 No Content.
http
HTTP/1.1 204 No ContentExamples
Python
python
@app.route('/webhook', methods=['POST'])
def webhook():
event = request.json
if event['type'] == 'session_end':
# Cleanup session state
cleanup_session(event['session']['id'])
return '', 204Node.js
javascript
app.post('/webhook', (req, res) => {
const event = req.body;
if (event.type === 'session_end') {
// Cleanup session state
cleanupSession(event.session.id);
res.status(204).send();
return;
}
});Go
go
func webhook(w http.ResponseWriter, r *http.Request) {
var event map[string]interface{}
json.NewDecoder(r.Body).Decode(&event)
if event["type"] == "session_end" {
session := event["session"].(map[string]interface{})
cleanupSession(session["id"].(string))
w.WriteHeader(http.StatusNoContent)
return
}
}Use Cases
- Cleanup state - Remove session data
- Save logs - Store conversation history
- Send analytics - Track session metrics
- Close connections - Clean up resources
Best Practices
- Always cleanup - Remove session state
- Log the session - Save for analytics
- Don't return actions - No actions are processed
- Handle errors - Don't fail silently
Next Steps
- Session Start Event - When calls begin
- Event Flow - Understand the complete flow
- Action Types - Actions you can send