Skip to content

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

FieldTypeRequiredDescription
typestringYesAlways "session_end"
session.idstring (UUID)YesSession identifier
session.account_idstringYesAccount identifier
session.phone_numberstringYesPhone 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 Content

Examples

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 '', 204

Node.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

  1. Always cleanup - Remove session state
  2. Log the session - Save for analytics
  3. Don't return actions - No actions are processed
  4. Handle errors - Don't fail silently

Next Steps