Asterisk course

Asterisk Hangup Application: Ending Calls in the Dialplan

Learn how to use Asterisk Hangup() to terminate an active call, finish dialplan branches, and prevent unintended call-flow continuation.

Hangup() is an Asterisk dialplan application that disconnects the active call or channel being processed. It is commonly the final application in a call-flow path: after Asterisk has completed an announcement, menu branch, or other service, Hangup() makes the end of processing explicit.

This lesson assumes you understand the basic structure of an Asterisk dialplan, including contexts, extensions, and priorities.

What Hangup() Does

When Asterisk reaches Hangup(), it terminates the active channel or call leg being handled by that dialplan path. The current call is disconnected, and execution of that call's current dialplan path ends.

Hangup() is useful when the intended call processing is complete. For example, a short service extension might answer, play an informational recording, and then disconnect. A menu branch might complete its final action and use Hangup() so the caller does not continue into unrelated priorities or fallback logic.

Basic Hangup() Syntax

The basic form requires no arguments:

Hangup()

In a modern dialplan, place it as a priority in an extension using same => n. The n means “next priority,” so Asterisk assigns the next sequential priority automatically.

[service-notice]
exten => 999,1,Answer()
same => n,Playback(service-unavailable)
same => n,Hangup()

The context is service-notice, the extension is 999, and the applications run in the order shown. Hangup() is the final priority in this path.

Explicit priority numbering

The same sequence can use explicit priority numbers:

[service-notice]
exten => 999,1,Answer()
exten => 999,2,Playback(service-unavailable)
exten => 999,3,Hangup()

Both styles describe the same execution order. Automatic numbering with same => n reduces errors when you insert or remove steps.

Complete Example: Answer, Play a Notice, and Disconnect

Put the following in extensions.conf, or in the dialplan configuration source used by your installation:

[service-notice]
exten => 999,1,Answer()
same => n,Playback(service-unavailable)
same => n,Hangup()

A caller who reaches extension 999 in the service-notice context follows this sequence:

  1. Answer() answers the inbound call.
  2. Playback(service-unavailable) plays the named audio prompt.
  3. Hangup() disconnects the caller.

Hangup() is the concluding application. Once the prompt has finished, the call does not need another dialplan operation, so the explicit termination makes the intended endpoint clear.

Applications in the Basic Call Flow

ApplicationRoleTypical position in flowArguments needed for basic use
Answer()Answers an inbound call so media and subsequent handling can proceed.Usually first when the call should be answered before media is delivered.None
Playback()Plays a specified sound file or prompt to the caller.After answering and before the call is terminated.A prompt name, such as service-unavailable
Hangup()Disconnects the active call or channel.Final step after the last prompt or interaction.None for basic use

Execution Order in the Example

PriorityApplicationWhat happens to the call
Initial answer stepAnswer()Asterisk answers the inbound call.
Prompt playback stepPlayback(service-unavailable)The caller hears the informational recording.
Final hangup stepHangup()The active channel is disconnected and this call-flow path ends.

Why Explicit Call Termination Matters

A dialplan is made of ordered applications. If a completed branch does not have a deliberate endpoint, later priorities, pattern matches, transfers, or fallback logic may be reached depending on the rest of the configuration and how control entered the branch.

Adding Hangup() at a deliberate endpoint provides predictable behavior:

  • A short announcement ends immediately after the final recording.
  • A completed menu branch does not fall through into unrelated processing.
  • A service extension clearly communicates that its work is finished.
  • Operators can identify the intended end of a call path while reading or troubleshooting the dialplan.

Compare an incomplete branch:

exten => 999,1,Answer()
same => n,Playback(service-unavailable)

With an explicit endpoint:

exten => 999,1,Answer()
same => n,Playback(service-unavailable)
same => n,Hangup()

The second version makes it clear that the call should end after the prompt. If the call is transferred or sent to another location before Hangup(), then that other destination controls the next part of the call flow; Hangup() must be placed at the endpoint that is actually intended to disconnect the caller.

Relationship to Answer()

Answer() answers an inbound call. Answering is important when the call flow needs to establish the call before delivering media or performing subsequent handling. In a basic example, Answer() also takes no arguments.

The common beginner pattern is:

  1. Answer the call.
  2. Deliver the announcement or other media.
  3. Hang up after the interaction is complete.

Whether Answer() is required depends on the call flow and channel behavior, but the pattern is clear and useful for a simple inbound announcement. See The Answer Application for more detail.

Relationship to Playback() and Other Media Applications

Playback() plays an audio file or prompt. It should occur before Hangup() when the caller must hear a final message. Hangup() does not play an announcement, wait for input, or provide audio; it only performs call termination.

exten => 999,1,Answer()
same => n,Playback(service-unavailable)
same => n,Hangup()

In this sequence, Playback() is the final media operation and Hangup() is the final call-control operation. Review The Playback Application for prompt behavior and media configuration. For interactive announcements that collect input, related applications such as Background() may be part of a larger flow, with Hangup() still placed at branches that should terminate.

Contexts, Extensions, and Priorities

Hangup() is written wherever the relevant dialplan path is defined, usually in extensions.conf or an equivalent included configuration file.

  • Context: A named dialplan section that groups extensions and controls which routes are available.
  • Extension: A number or matching pattern that selects a sequence of call-processing steps.
  • Priority: The ordered position of an application within that extension's sequence.
  • Channel: Asterisk's representation of an active communications path, such as an inbound or outbound call leg.

For example:

[service-notice]                 ; context
exten => 999,1,Answer()          ; extension 999, priority 1
same => n,Playback(service-unavailable) ; next priority
same => n,Hangup()               ; final priority

When a call reaches extension 999 in service-notice, Asterisk processes the priorities in order. The incoming endpoint must actually use or reach this context for the example to run.

Call-Flow Scope

Hangup() affects the active call or channel being processed. In the simple inbound example, that means the caller's current call is disconnected and the current dialplan execution path ends.

More advanced applications can create or control multiple channels, such as an outbound call leg connected to an inbound caller. In those designs, administrators must deliberately determine which channel a call-control operation affects. That complexity does not change the basic lesson: place termination at the endpoint of the channel and branch you intend to end.

End-of-Branch Cleanup

Hangup() is especially useful after a branch has completed its intended action:

[service-menu]
exten => 1,1,Answer()
same => n,Playback(option-one-complete)
same => n,Hangup()

Each branch has its own explicit final priority. If a branch instead uses Goto(), a menu result, or another transfer, follow that destination and place Hangup() at the destination's intended endpoint. See The Goto Application when tracing transferred call paths.

Verify and Test the Dialplan

After saving the configuration, connect to the Asterisk CLI and reload the dialplan:

dialplan reload

Inspect the example extension with:

dialplan show 999@service-notice

The output should show the context, extension, and priorities, including the priority containing Hangup(). Increase CLI verbosity before placing a test call:

core set verbose 4

Place a call to extension 999 through the endpoint and context that can reach service-notice. CLI output should show the call reaching Answer(), Playback(), and then Hangup(). The caller should hear the prompt and be disconnected when playback and the final call step are complete.

Troubleshooting

The call does not disconnect after the announcement

  • Hangup() may be missing from the extension or branch.
  • Hangup() may be in a different extension or an unreachable priority.
  • A transfer or jump may send the call elsewhere before it reaches Hangup().

Run dialplan show 999@service-notice, enable CLI verbosity, and place a test call. Confirm that execution reaches the priority containing Hangup(). Trace any Goto, menu result, or transfer that occurs first.

Asterisk cannot find the requested extension or priority

  • The context name, extension number, or priority sequence may be incorrect.
  • The edited dialplan may not have been reloaded.
  • The incoming endpoint may be assigned to a different context.

Check the endpoint's incoming context, review the configuration syntax and priority order, run dialplan reload, and confirm the extension with dialplan show.

The caller hears no prompt before disconnection

  • The sound file name may be unavailable or incorrect.
  • The call may not have been answered before playback in a scenario that requires Answer().
  • The dialplan may reach Hangup() before Playback().

Confirm that Playback() precedes Hangup(), verify the prompt name and installed sound files, and inspect the CLI for playback-related errors.

The dialplan continues into unexpected processing

  • The intended path may lack an explicit final Hangup().
  • Additional priorities, patterns, or fallback logic may be reached.
  • A Goto, menu result, or transfer may send the call to another location.

Trace the complete path in the CLI, inspect every branch endpoint, and add Hangup() wherever a branch should deliberately terminate.

Exam-Relevant Notes

  • Hangup() disconnects the active call or channel and normally has no arguments in a basic use.
  • It is commonly the last priority in a completed dialplan path.
  • Answer() answers the call; Playback() plays audio; Hangup() ends the call.
  • same => n continues the previous extension at the next automatically assigned priority.
  • Explicit termination prevents unintended continuation into later call-flow logic.
  • After editing the dialplan, reload it and use dialplan show plus CLI verbosity to verify the path.