litnimax / astconfman

Asterisk ConfBridge Manager
GNU Lesser General Public License v3.0
45 stars 36 forks source link

Callerid name on Conference view #48

Open vlad-dc opened 5 years ago

vlad-dc commented 5 years ago

How to set callerid name to participants buttom on conference view?

greemag commented 5 years ago

Hello, you can update view.py:


@asterisk.route('/online_participants.json/<int:conf_number>')
def online_participants_json(conf_number):
    if not asterisk_is_authenticated():
        return 'NOTAUTH'

    conf = Conference.query.filter_by(number=conf_number).first()

    if not conf:
        return 'NOCONF'

    ret = []

    ret2 = confbridge_list_participants(conf_number)

    online_participants = [
        k['callerid'] for k in ret2]

    partici = [
        k.phone for k in conf.participants]

    for p in conf.participants:
                if (p.phone in online_participants):
                        online = True
                        for i in ret2:
                                if (i['callerid'] == p.phone):
                                        flag = i['flags']
                                        channel = i['channel']
                else:
                        online = False
                        flag = ''
                        channel = ''
                ret.append({
                'id': p.id,
                'name': p.name,
                'phone': p.phone,
                'callerid': p.phone,
                'is_invited': p.is_invited,
                'flags': flag,
                'channel': channel,
                'is_online': online
                }
                )

    for i in ret2:
        if (i['callerid'] not in partici):
                contac = Contact.query.filter_by(phone=i['callerid']).first()
                if ( contac ):
                    name=contac.name
                else:
                    name=''
                ret.append ({
                'id': '',
                'name': name,
                'phone': i['callerid'],
                'callerid': i['callerid'],
                'is_invited': False,
                'flags': i['flags'],
                'channel': i['channel'],
                'is_online': True
                }
                )

    return Response(response=json.dumps(ret),
                    status=200, mimetype='application/json')