Appearance
Hangup Action
End the call.
Action Structure
json
{
"type": "hangup",
"session_id": "550e8400-e29b-41d4-a716-446655440000"
}Fields
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Always "hangup" |
session_id | string (UUID) | Yes | Session identifier from event |
Examples
Python
python
@app.route('/webhook', methods=['POST'])
def webhook():
event = request.json
if event['type'] == 'user_speak':
user_text = event['text'].lower()
if 'goodbye' in user_text or 'bye' in user_text:
return jsonify({
'type': 'hangup',
'session_id': event['session']['id']
})Node.js
javascript
app.post('/webhook', (req, res) => {
const event = req.body;
if (event.type === 'user_speak') {
const userText = event.text.toLowerCase();
if (userText.includes('goodbye') || userText.includes('bye')) {
return res.json({
type: 'hangup',
session_id: event.session.id
});
}
}
});Go
go
if strings.Contains(text, "goodbye") || strings.Contains(text, "bye") {
action := map[string]interface{}{
"type": "hangup",
"session_id": session["id"],
}
json.NewEncoder(w).Encode(action)
}Use Cases
- User says goodbye - End call politely
- Task complete - After completing a task
- Error handling - When something goes wrong
- Timeout - After inactivity
Best Practices
- Say goodbye first - Optionally speak before hanging up
- Clean up state - Session will end, but cleanup in
session_end - Log the reason - Track why calls ended
- Handle gracefully - Don't hang up abruptly
Next Steps
- Transfer Action - Transfer to another number
- Event Types - What triggers actions
- Event Flow - Understand the complete flow