Пример #1
0
    def answer_queued_call(self,
                           tenant_uuid,
                           switchboard_uuid,
                           queued_call_id,
                           user_uuid,
                           line_id=None):
        if not Switchboard(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
Пример #2
0
    def create_from_user(self, initiator_call, destination, location,
                         completions, timeout, user_uuid):
        if Channel(initiator_call, self.ari).user() != user_uuid:
            raise UserPermissionDenied(user_uuid, {'call': initiator_call})

        if destination == 'line':
            try:
                destination_interface = User(
                    user_uuid,
                    self.confd_client).line(location['line_id']).interface()
            except (InvalidUserUUID, InvalidUserLine):
                raise RelocateCreationError('invalid line for user',
                                            details={
                                                'user_uuid': user_uuid,
                                                'line_id': location['line_id']
                                            })
            destination = 'interface'
            location['interface'] = destination_interface
            variables = {}
        elif destination == 'mobile':
            try:
                user = User(user_uuid, self.confd_client)
                mobile = user.mobile_phone_number()
                line_context = user.main_line().context()
            except (InvalidUserUUID, InvalidUserLine):
                details = {'user_uuid': user_uuid}
                raise RelocateCreationError(
                    'invalid user: could not find main line', details=details)
            destination = 'extension'
            location = {'exten': mobile, 'context': line_context}
            variables = {'WAZO_DEREFERENCED_USERUUID': user_uuid}

        relocate = Relocate(self.state_factory)
        relocate.initiator = user_uuid
        relocate.recipient_variables = variables

        return self.create(initiator_call,
                           destination,
                           location,
                           completions,
                           timeout,
                           relocate=relocate)