def originate(self, dest_url=None, uuid_func=utils.uuid, app_id=None, listener=None, bgapi_kwargs={}, **orig_kwargs): # TODO: add a 'block' arg to determine whether api or bgapi is used '''Originate a call using FreeSWITCH 'originate' command. A non-blocking bgapi call is used by default. Parameters ---------- see :func:`build_originate_cmd` orig_kwargs: additional originate cmd builder kwargs forwarded to :func:`build_originate_cmd` call Returns ------- instance of `Job` a background job ''' listener = self._assert_alive(listener) # gen originating session uuid for tracking call uuid_str = uuid_func() if dest_url: # generate the cmd now origkwds = {self.id_var: app_id or self._id} origkwds.update(orig_kwargs) cmd_str = build_originate_cmd( dest_url, uuid_str, xheaders={listener.call_corr_xheader: uuid_str, self.id_xh: app_id or self._id}, # extra_params={self.id_var: app_id or self._id}, **origkwds ) else: # accept late data insertion for the uuid_str and app_id cmd_str = self.originate_cmd.format( uuid_str=uuid_str, app_id=app_id or self._id ) return self.bgapi( cmd_str, listener, sess_uuid=uuid_str, client_id=app_id, **bgapi_kwargs )
def set_orig_cmd(self, *args, **kwargs): '''Build and cache an originate cmd string for later use as the default input for calls to `originate` ''' user_xh = kwargs.pop('xheaders', {}) # currently this puts a couple placeholders which can be replaced # at run time by a format(uuid_str='blah', app_id='foo') call if self.listener: user_xh[self._listener.call_corr_xheader] = '{uuid_str}' user_xh[self.id_xh] = '{app_id}' origparams = {self.id_var: '{app_id}'} origparams.update(kwargs) # build a reusable command string self._orig_cmd = build_originate_cmd( *args, xheaders=user_xh, **origparams )
def originate(self, dest_url=None, uuid_func=utils.uuid, app_id=None, bgapi_kwargs={}, listener=None, **orig_kwargs): # TODO: add a 'block' arg to determine whether api or bgapi is used '''Originate a call using FreeSWITCH 'originate' command. A non-blocking bgapi call is used by default. Parameters ---------- see :func:`build_originate_cmd` orig_kwargs: additional originate cmd builder kwargs forwarded to :func:`build_originate_cmd` call Returns ------- instance of `Job` a background job ''' listener = self._assert_alive(listener) # gen originating session uuid for tracking call uuid_str = uuid_func() if dest_url: # generate the cmd now origkwds = {self.id_var: app_id or self._id} origkwds.update(orig_kwargs) cmd_str = build_originate_cmd( dest_url, uuid_str, xheaders={listener.call_corr_xheader: uuid_str, self.id_xh: app_id or self._id}, # extra_params={self.id_var: app_id or self._id}, **origkwds ) else: # accept late data insertion for the uuid_str and app_id cmd_str = self.originate_cmd.format( uuid_str=uuid_str, app_id=app_id or self._id ) return self.bgapi(cmd_str, listener, sess_uuid=uuid_str, **bgapi_kwargs)