Asterisk AMI incoming calls returns no calls
<p>I have the following function with the aim is to get incoming calls from my Python web interface from the Asterisk server.</p>

<pre><code>def fetch_events(event, manager):

with app.app_context():

    if event.name == 'CoreShowChannel':
        id = event.message['accountcode']
        data = {
                'user_id': id,
                'caller_id': event.message['CallerIDnum'],
                'channel': event.message['Channel'],
                'duration': event.message['Duration'],
                'context': event.message['Context'],
                'extension': event.message['Extension'],
                'line': event.message['ConnectedLineNum'],
                #'channel_state': event.message['ChannelState'],
                'channel_state': event.message['ChannelStateDesc'],
                }
        user = System().getUserById(id)
        if user:
            profile = {
                        'firstname': user['firstname'],
                        'lastname': user['lastname']
                        'email': user['email']
                    }

        else:
            profile = {
                        'first_name': "No firstname",
                        'last_name': "No lastname"
                    }
        data.update(profile)   
        g.channels.append(data)
    if event.name == 'CoreShowChannelsComplete':
        g.complete = True

    if not event.name:
        data = {
            "connectivity":"Not connected",
            "event-name":"No event name"
        }
        g.channels.append(data)
        g.complete = True


    @app.route('/incoming-calls')
    def incoming_calls():
   /**** I have already login and connect *****/
   g.channels = []
   g.complete = False
    manager.register_event('*', fetch_events)
    res = manager.send_action({'Action':'CoreShowChannels'})

    try:

        while not g.complete:

            time.sleep(0.5)
        manager.close()
        return json.dumps(g.channels)
</code></pre>

<p>But when I try getting incoming calls events after registering the handle_event method I get an empty array. It seems there is something wrong with the handle_event method but I can't get to find it.</p>

<p>You should use (listen) 'Newexten' event and extract 'context' from that event ,and then look up if the calls come from incoming context if it true ,then use other variables from that event. Don't use action 'CoreShowChannel' because it will list current active channels.</p>

python asterisk