def make_call(): channel = request.args.get('channel', '') exten = request.args.get('exten', '') channel = '304' exten = '8' + exten[1:] user_client = AMIClient(address=ami_ip, port=ami_port) future = user_client.login(username=ami_user, secret=ami_secret) time.sleep(0.5) user_adapter = AMIClientAdapter(user_client) res = user_adapter.Originate(Channel='SIP/' + channel, Context='local', Exten=exten, ActionID=exten, Priority=1, CallerID=exten, CallerIDName=exten, Timeout='') time.sleep(0.2) user_client.logoff() return 'ok', 200, HEADERS
def main(client, number, command): global channel def actionMute(): result = adapter.ConfbridgeMute(Conference=confName, Channel="%s" % channel) print(result.response) def actionUnmute(): result = adapter.ConfbridgeUnmute(Conference=confName, Channel="%s" % channel) print(result.response) def actionKick(): #print(channel) result = adapter.ConfbridgeKick(Conference=confName, Channel="%s" % channel) print(result.response) def actionLock(): result = adapter.ConfbridgeLock(Conference=confName, ) print(result.response) def actionUnlock(): result = adapter.ConfbridgeUnlock(Conference=confName, ) print(result.response) def actionStartRecord(): result = adapter.ConfbridgeStartRecord(Conference=confName, Channel="%s" % channel) print(result.response) #the record file should be /var/spool/asterisk/monitor/confbridge-confName-queId.wav def actionStopRecord(): result = adapter.ConfbridgeStopRecord(Conference=confName, Channel="%s" % channel) print(result.response) command_option = { "mute": actionMute, "unmute": actionUnmute, "kick": actionKick, "lock": actionLock, "unlock": actionUnlock, "startRecord": actionStartRecord, "stopRecord": actionStopRecord } adapter = AMIClientAdapter(client) result = adapter.ConfbridgeList(Conference=confName) future = result.response time.sleep(0.01) command_option[command]()
def make_call(): client = AMIClient(address=AMI_ADDRESS, port=AMI_PORT) future = client.login(username=AMI_USER, secret=AMI_SECRET) id = request.args.get('id', '') channel = request.args.get('channel', '') exten = request.args.get('exten', '') caller_id = request.args.get('caller_id', '') caller_id_name = request.args.get('caller_id_name', '') user = request.args.get('user', '') action_id = request.args.get('action_id', '') d = {} exten = '8' + exten id_ext = uuid.uuid4() id_ext = str(id_ext) if future.response.is_error(): d['status'] = 'failed' d['error'] = str(future.response) res = json.dumps(d, default=json_serial) return res, 200, HEADERS adapter = AMIClientAdapter(client) res_call = do_call_with_oper(adapter, channel, exten, caller_id, caller_id_name, action_id) client.logoff() d['status'] = 'ok' d['id_ext'] = id_ext res = json.dumps(d, default=json_serial) USER_EVENTS[user] = { 'id_ext': id_ext, 'id': id, 'user': user, 'channel': channel, 'exten': exten, 'caller_id': caller_id } return res, 200, HEADERS
def make_call_auto(param): tel = kwargs_get(param, 'tel') file = kwargs_get(param, 'file') client = AMIClient(address=AMI_ADDRESS, port=AMI_PORT) future = client.login(username=AMI_USER, secret=AMI_SECRET) if future.response.is_error(): raise Exception(str(future.response)) adapter = AMIClientAdapter(client) channel = f'Local/{tel}@ng_ext_autodial' d['channel'] = channel action_id = tel variable = FILE_NAMES[file] client.add_event_listener(event_listener) #res_call = simple_call_without_oper(channel, data) res_call = simple_call_without_oper(adapter, channel, DATA, APP, action_id, variable, tel) while True: if d['status'] == 'Error': break elif d['status'] == 'ANSWER': break elif d['status'] == 'BUSY': break elif d['status'] == 'Success': break if not res_call.response is None: d['status'] = res_call.response.status time.sleep(0.2) client.logoff() #print(d['DTMF']) #print(d['status']) return d
command_option[command]() if __name__ == '__main__': #init ami client client = AMIClient(address='127.0.0.1', port=5038) client.login(username='******', secret='for-confbridge') #get vars confNum = sys.argv[1] command = sys.argv[2] numbers = [] if len(sys.argv) == 4: number = sys.argv[3] numbers = number.split(',') else: numbers.append(confNum) adapter = AMIClientAdapter(client) options = optionTool.Option(confNum) confName = options.basic["Name"] #print(future) for num in numbers: #get channel from event event = EventListener(getChannel, white_list=['ConfbridgeList'], CallerIDNum=num) client.add_event_listener(event) #call main main(client, num, command) client.remove_event_listener(event)
def make_call_auto(): client = AMIClient(address=AMI_ADDRESS, port=AMI_PORT) future = client.login(username=AMI_USER, secret=AMI_SECRET) id = request.args.get('id', '') exten = request.args.get('exten', '') file = request.args.get('file', '') action_id = request.args.get('action_id', '') exten = '8' + exten d = {} id_ext = uuid.uuid4() id_ext = str(id_ext) if future.response.is_error(): d['status'] = 'failed' d['error'] = str(future.response) res = json.dumps(d, default=json_serial) return res, 200, HEADERS adapter = AMIClientAdapter(client) channel = f'Local/{exten}@ng_ext_autodial_speech_to_text' d['channel'] = channel variable = FILE_NAMES[file] res_call = do_call_without_oper(adapter, channel, DATA, APP, action_id, variable, exten) client.logoff() d = {} d['Действия'] = 'Asterisk_AutoCall_Event' d['Данные'] = {} d['Данные']['name'] = 'init' d['Данные']['id_ext'] = id_ext d['Данные']['event_date'] = datetime.now() d['Данные']['status'] = 'ok' d['Данные']['callerid'] = exten d['Данные']['id'] = id.upper() jdata = json.dumps(d, default=json_serial) auto_call_event(jdata) AUTO_CALLS[channel] = { 'id_ext': id_ext, 'id': id, 'channel': channel, 'exten': exten, 'callerid': exten } #period = datetime.now() #source = id.upper() #status = 'init' #value = id_ext #comment = res #var = Statuses_AutoCall.create(period=period, source=source, status=status, value=value, comment=comment) return jdata, 200, HEADERS
from asterisk.ami import AMIClient, AMIClientAdapter client = AMIClient(address='127.0.0.1', port=5038) client.login(username='******', secret='root') adapter = AMIClientAdapter(client) # originate = adapter.Originate( # Channel='Local/100@incoming-callfile', # Exten='100', # Priority=1, # Context='outgoing-customer', # CallerID='Testing' # ) originate = adapter.Originate(Channel='DAHDI/g2/09690402936', Exten='911204022601', Priority=1, Context='engine_incoming', CallerID='Testing') response = originate.response print(response)