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>When someone call the Asterisk example incoming call to trunk num ,Asterisk fired 'Newexten' event. The data structure of that event is:</p>

<pre><code>`{ event: 'Newexten',
   privilege: 'call,all',
   channel: 'SIP/NameOfyourSIPprovider-0000ae7d',//channel that will be bridged
   channelstate: '0',
   channelstatedesc: 'Down',//the channel is currently down because no one is answered
   calleridnum: '060444333',// num of calling party
   calleridname: '&lt;unknown&gt;',
   connectedlinenum: '+34312345678',//your trunk num
   connectedlinename: '&lt;unknown&gt;',
   language: 'en',
   accountcode: '',
   context: 'from-trunk',//context(extensions.conf) for incoming calls
   exten: '060444333',//num of calling party
   priority: '1',
   uniqueid: '1471265139.357602',//unique id of channel
   linkedid: '1471265138.357596',//linked id of channel that will be bridged
   extension: '060444333',//num of calling party
   application: 'AppDial',
   appdata: '(Outgoing Line)' }`
</code></pre>

python asterisk