def test_assemble_caller_id_with_extension(self): fullname = 'User 1' number = '2345' result = caller_id.assemble_caller_id(fullname, number) assert_that(result, equal_to('"%s" <%s>' % (fullname, number)))
def test_assemble_caller_id_without_extension(self): fullname = 'User 1' number = None result = caller_id.assemble_caller_id(fullname, number) assert_that(result, equal_to('"%s"' % fullname))
def answer_queued_call(self, switchboard_uuid, queued_call_id, user_uuid): if not Switchboard(switchboard_uuid, self._confd).exists(): raise NoSuchSwitchboard(switchboard_uuid) try: queued_channel = self._ari.channels.get(channelId=queued_call_id) except ARINotFound: raise NoSuchCall(queued_call_id) endpoint = User(user_uuid, self._confd).main_line().interface() caller_id = assemble_caller_id( queued_channel.json['caller']['name'], queued_channel.json['caller']['number']).encode('utf-8') channel = self._ari.channels.originate( endpoint=endpoint, app=DEFAULT_APPLICATION_NAME, appArgs=[ 'switchboard', 'switchboard_answer', switchboard_uuid, queued_call_id ], callerId=caller_id, originator=queued_call_id, ) return channel.id
def originate_recipient(self, initiator_call, context, exten, transfer_id, variables, timeout): initiator_channel = self.ari.channels.get(channelId=initiator_call) caller_id = assemble_caller_id(initiator_channel.json['caller']['name'], initiator_channel.json['caller']['number']).encode('utf-8') recipient_endpoint = 'Local/{exten}@{context}'.format(exten=exten, context=context) app_args = ['transfer', 'transfer_recipient_called', transfer_id] originate_variables = dict(variables) originate_variables['XIVO_TRANSFER_ROLE'] = 'recipient' originate_variables['XIVO_TRANSFER_ID'] = transfer_id originate_variables['CHANNEL(language)'] = initiator_channel.getChannelVar(variable='CHANNEL(language)')['value'] try: originate_variables['XIVO_USERID'] = initiator_channel.getChannelVar(variable='XIVO_USERID')['value'] except ARINotFound: pass try: originate_variables['XIVO_USERUUID'] = initiator_channel.getChannelVar(variable='XIVO_USERUUID')['value'] except ARINotFound: pass timeout = -1 if timeout is None else timeout new_channel = self.ari.channels.originate(endpoint=recipient_endpoint, app=DEFAULT_APPLICATION_NAME, appArgs=app_args, callerId=caller_id, variables={'variables': originate_variables}, timeout=timeout, originator=initiator_call) recipient_call = new_channel.id try: ari_helpers.set_bridge_variable(self.ari, transfer_id, 'XIVO_HANGUP_LOCK_SOURCE', recipient_call) except ARINotFound: raise TransferCreationError('bridge not found') return recipient_call
def originate_recipient(self, initiator_call, context, exten, transfer_id, variables): try: app_instance = self.call_states.get(initiator_call).app_instance except KeyError: raise TransferCreationError('{call}: no app_instance found'.format(call=initiator_call)) initiator_channel = self.ari.channels.get(channelId=initiator_call) caller_id = assemble_caller_id(initiator_channel.json['caller']['name'], initiator_channel.json['caller']['number']).encode('utf-8') recipient_endpoint = 'Local/{exten}@{context}'.format(exten=exten, context=context) app_args = [app_instance, 'transfer_recipient_called', transfer_id] originate_variables = dict(variables) originate_variables['XIVO_TRANSFER_ROLE'] = 'recipient' originate_variables['XIVO_TRANSFER_ID'] = transfer_id new_channel = self.ari.channels.originate(endpoint=recipient_endpoint, app=APPLICATION_NAME, appArgs=app_args, callerId=caller_id, variables={'variables': originate_variables}) recipient_call = new_channel.id try: ari_helpers.set_bridge_variable(self.ari, transfer_id, 'XIVO_HANGUP_LOCK_SOURCE', recipient_call) except ARINotFound: raise TransferCreationError('bridge not found') return recipient_call
def originate_recipient(self, initiator_call, context, exten, transfer_id, variables): try: app_instance = self.call_states.get(initiator_call).app_instance except KeyError: raise TransferCreationError( '{call}: no app_instance found'.format(call=initiator_call)) initiator_channel = self.ari.channels.get(channelId=initiator_call) caller_id = assemble_caller_id( initiator_channel.json['caller']['name'], initiator_channel.json['caller']['number']).encode('utf-8') recipient_endpoint = 'Local/{exten}@{context}'.format(exten=exten, context=context) app_args = [app_instance, 'transfer_recipient_called', transfer_id] originate_variables = dict(variables) originate_variables['XIVO_TRANSFER_ROLE'] = 'recipient' originate_variables['XIVO_TRANSFER_ID'] = transfer_id new_channel = self.ari.channels.originate( endpoint=recipient_endpoint, app=APPLICATION_NAME, appArgs=app_args, callerId=caller_id, variables={'variables': originate_variables}) recipient_call = new_channel.id try: ari_helpers.set_bridge_variable(self.ari, transfer_id, 'XIVO_HANGUP_LOCK_SOURCE', recipient_call) except ARINotFound: raise TransferCreationError('bridge not found') return recipient_call
def answer_queued_call(self, tenant_uuid, switchboard_uuid, queued_call_id, user_uuid, line_id=None): logger.debug( 'Answering queued call %s in tenant %s for switchboard %s with user %s line %s', queued_call_id, tenant_uuid, switchboard_uuid, user_uuid, line_id, ) if not SwitchboardConfd(tenant_uuid, switchboard_uuid, self._confd).exists(): raise NoSuchSwitchboard(switchboard_uuid) try: queued_channel = self._ari.channels.get(channelId=queued_call_id) except ARINotFound: raise NoSuchCall(queued_call_id) try: user = User(user_uuid, self._confd, tenant_uuid=tenant_uuid) if line_id: line = user.line(line_id) else: line = user.main_line() endpoint = line.interface_autoanswer() except InvalidUserUUID as e: raise NoSuchConfdUser(e.details['user_uuid']) caller_id = assemble_caller_id( queued_channel.json['caller']['name'], queued_channel.json['caller']['number'], ).encode('utf-8') channel = self._ari.channels.originate( endpoint=endpoint, app=DEFAULT_APPLICATION_NAME, appArgs=[ 'switchboard', 'switchboard_answer', tenant_uuid, switchboard_uuid, queued_call_id, ], callerId=caller_id, originator=queued_call_id, variables={'variables': AUTO_ANSWER_VARIABLES}, ) return channel.id
def update_caller_id(main_user, line, extension=None): exten = extension.exten if extension else None line.callerid = caller_id.assemble_caller_id(main_user.fullname, exten) line_dao.edit(line)
def update_caller_id(main_user, line, extension=None): exten = extension.exten if extension else None line.callerid = caller_id.assemble_caller_id(main_user.fullname, exten) line_dao.edit(line)