How to Hangup a call in Asterisk AMI
<p>Hello I'm using Python Asterisk to work on my asterisk server. I have been able to listen to current calls using the following code.</p>

<pre><code>     def handle_event(event, manager):
     with ctx:

        if event.name == 'CoreShowChannel':
            user_id = event.message['AccountCode']
            user_id = int(user_id)
            data = {
            "channel":event.message['Channel'],
            "channel_state":event.message['ChannelStateDesc'],
            "duration":event.message['Duration'],
            'extension': event.message['Exten'],
            'line': event.message['ConnectedLineNum'],
            'user_id': user_id,
            'context': event.message['Context'],
            'caller_id': event.message['CallerIDNum']
            }

            system = System()
            user = system.getUserById(user_id)
            if user:
                profile = {"first_name":user.first_name,    "last_name":user.last_name}

            data.update(profile)
            g.channels.append(data)
        if event.name == 'CoreShowChannelsComplete':
            g.complete = True
    @app.route('/live-calls')
    def live_calls():
        g.complete = False
        g.channels = []
        manager = asterisk.manager.Manager()
        manager.connect(hostname)
        manager.login(username, secret)
        manager.register_event('*', handle_event)
        res = manager.send_action({'Action':'CoreShowChannels'})

        while not g.complete:

            time.sleep(0.1)
            manager.close()
            if len(g.channels) &lt; 1:
                return json.dumps({"response":g.complete})
            return json.dumps(g.channels)
</code></pre>

<p>This code serves it purpose and works as expected, now how do I accomplish a hangup method where when I click a hangup button, the current call hangs up. The problem is I know there is an Hangup event but I do not even know the object or variables to check or where to listen to.</p>

<p>I just called the hangup method which takes the channel name as an argument.</p>

<p>I didn't know there is method for that</p>

<p>manager.hangup(channel)</p>

python asterisk