Exemplo n.º 1
0
    def set_music(self, enable=True, string=''):
        """Enable / disable music on hold generator.

        :param enable:

        :type enable:
            bool

        :param string:

        :type string:
            str

        :returns:
            bool
        """
        tmp = 'on'

        if not enable:
            tmp = 'off'
        cmd = 'SET MUSIC %s' % tmp

        if string != '':
            cmd += ' %s' % string
        utils.agi_send(cmd)

        return True
Exemplo n.º 2
0
    def asyncagi_break(self):
        """Interrupt Async AGI.

        :returns:
            bool
        """

        cmd = 'ASYNCAGI BREAK'
        utils.agi_send(cmd)

        return True
Exemplo n.º 3
0
    def noop(self):
        """Do nothing.

        This function does nothing.

        :returns:
            bool
        """
        cmd = 'NOOP'
        utils.agi_send(cmd)

        return True
Exemplo n.º 4
0
    def set_extension(self, string):
        """Sets dialplan extension.

        :param string:

        :type string:
            str

        :returns:
            bool
        """
        cmd = 'SET EXTENSION %s' % string
        utils.agi_send(cmd)

        return True
Exemplo n.º 5
0
    def set_caller_id(self, number):
        """Sets caller id for the current channel.

        :param number:

        :type number:
            str

        :returns:
            bool
        """
        cmd = 'SET CALLERID %s' % number
        utils.agi_send(cmd)

        return True
Exemplo n.º 6
0
    def set_priority(self, string):
        """Sets dialplan priority.

        :param string:

        :type string:
            str

        :returns:
            bool
        """
        cmd = 'SET PRIORITY %s' % string
        utils.agi_send(cmd)

        return True
Exemplo n.º 7
0
    def set_context(self, string):
        """Sets dialplan context.

        :param string:

        :type string:
            str

        :returns:
            bool
        """
        cmd = 'SET CONTEXT %s' % string
        utils.agi_send(cmd)

        return True
Exemplo n.º 8
0
    def get_full_variable(self, name, channel=''):
        """Evaluates a channel expression.

        :param name:
            Variable name.

        :type name:
            str

        :param channel:

        :type options:
            str

        :returns:
            bool, string
        """
        cmd = 'GET FULL VARIABLE %s' % name
        if channel != '':
            cmd += ' %s' % channel

        res, args = utils.agi_send(cmd)[1:]
        if res != '1':
            return False, ''

        return True, args[1:-1]
Exemplo n.º 9
0
    def execute(self, application, options=''):
        """Execute a given application.

        :param application:
            Name of the Asterisk application.

        :type application:
            str

        :param options:
            A comma delimited string of your applications options.

        :type options:
            str

        :returns:
            bool, string
        """
        cmd = 'EXEC %s' % application
        if options != '':
            cmd += ' %s' % options

        res = utils.agi_send(cmd)[1]
        if res == '-2':
            return False, ''
        return True, res
Exemplo n.º 10
0
    def database_put(self, family, key, value):
        """Adds / updates database value.

        :param family:

        :type family:
            str

        :param key:

        :type key:
            str

        :param value:

        :type value:
            str

        :returns:
            bool
        """
        cmd = 'DATABASE PUT %s %s %s' % (family, key, value)
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False
        return True
Exemplo n.º 11
0
    def set_auto_hangup(self, time):
        """Hangup the current channel some time in the future.

        :param time:
            Amount of seconds in the future.

        :type time:
            str

        :returns:
            bool
        """
        cmd = 'SET AUTOHANGUP %s' % (time)
        utils.agi_send(cmd)

        return True
Exemplo n.º 12
0
    def set_variable(self, name, value):
        """Set channel variable.

        :param name:

        :type name:
            str

        :param value:

        :type value:
            str

        :returns:
            bool
        """
        cmd = 'SET VARIABLE %s %s' % (name, value)
        utils.agi_send(cmd)

        return True
Exemplo n.º 13
0
    def answer(self):
        """Answers the channel.

        :returns:
            bool
        """
        cmd = 'ANSWER'
        res = utils.agi_send(cmd)[1]
        if res != '0':
            return False
        return True
Exemplo n.º 14
0
    def _parse_digit_response(self, cmd):
        result = True
        digit = ''

        res = utils.agi_send(cmd)[1]

        if res == '-1':
            result = False
        elif res > '0':
            digit = chr(int(res))

        return result, digit
Exemplo n.º 15
0
    def speech_destroy(self):
        """Destroys a speech object.

        :returns:
            bool
        """
        cmd = 'SPEECH DESTROY'
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False

        return True
Exemplo n.º 16
0
    def verbose(self, level, message):
        """Log a message to the asterisk verbose log.

        :param level:
            Verbosity level.

        :type level:
            int

        :param message:
            Output text message.

        :type message:
            str

        :returns:
            bool
        """
        cmd = 'VERBOSE "%s" %s' % (message, level)
        utils.agi_send(cmd)

        return True
Exemplo n.º 17
0
    def _parse_get_option_or_stream_file(self, cmd):
        result = True
        dtmf = ''

        res, args = utils.agi_send(cmd)[1:]
        endpos = args.replace('endpos=', '')

        if res == '-1':
            result = False
        elif res == '0' and endpos == '0':
            result = False
        if res > '0':
            dtmf = chr(int(res))

        return result, dtmf, endpos
Exemplo n.º 18
0
    def _parse_timeout_response(self, cmd):
        ret_timeout = False
        result = True

        res, args = utils.agi_send(cmd)[1:]
        dtmf = res

        if res == '-1':
            dtmf = ''
            result = False

        if args[1:-1] == 'timeout':
            ret_timeout = True

        return result, dtmf, ret_timeout
Exemplo n.º 19
0
    def send_image(self, filename):
        """Sends images to channels supporting it.

        :param filename:

        :type filename:
            str

        :returns:
            bool
        """
        cmd = 'SEND IMAGE %s' % filename
        res = utils.agi_send(cmd)[1]
        if res != '0':
            return False
        return True
Exemplo n.º 20
0
    def send_text(self, message):
        """Sends text to channels supporting it.

        :param message:

        :type message:
            str

        :returns:
            bool
        """
        cmd = 'SEND TEXT "%s"' % message
        res = utils.agi_send(cmd)[1]
        if res != '0':
            return False
        return True
Exemplo n.º 21
0
    def tdd_mode(self, string):
        """Toggles telecommunications device for the deaf support.

        :param string:

        :type string:
            str

        :returns:
            bool
        """
        cmd = 'TDD MODE %s' % string
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False
        return True
Exemplo n.º 22
0
    def speech_deactivate_grammar(self, name):
        """Deactivates a grammar.

        :param name:

        :type name:
            str

        :returns:
            bool
        """
        cmd = 'SPEECH DEACTIVATE GRAMMAR %s' % name
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False

        return True
Exemplo n.º 23
0
    def speech_unload_grammar(self, name):
        """Loads a grammar.

        :param name:

        :type name:
            str

        :returns:
            bool
        """
        cmd = 'SPEECH UNLOAD GRAMMAR %s' % name
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False

        return True
Exemplo n.º 24
0
    def speech_create(self, engine):
        """Creates a speech object.

        :param engine:

        :type engine:
            str

        :returns:
            bool
        """
        cmd = 'SPEECH CREATE %s' % engine
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False

        return True
Exemplo n.º 25
0
    def get_variable(self, name):
        """Gets a channel variable.

        :param name:
            Channel name

        :type name:
            str

        :returns:
            bool, string
        """
        cmd = 'GET VARIABLE %s' % name
        res, args = utils.agi_send(cmd)[1:]

        if res != '1':
            return False, ''

        return True, args[1:-1]
Exemplo n.º 26
0
    def receive_text(self, timeout):
        """Receives text from channels supporting it.

        :param timeout:
            The amount of time, in milliseconds, to wait for DTMF.

        :type timeout:
            str

        :returns:
            bool, str
        """
        cmd = 'RECEIVE TEXT %s' % timeout
        res, args = utils.agi_send(cmd)[1:]

        if res != '1':
            return False, ''

        return True, args[1:-1]
Exemplo n.º 27
0
    def channel_status(self, name):
        """Returns the status of the connected channel.

        :param name:

        :type name:
            str

        :returns:
            bool, string
        """
        result = True

        cmd = 'CHANNEL STATUS %s' % (name)
        res = utils.agi_send(cmd)[1]

        if res == '-1':
            result = False

        return result, res
Exemplo n.º 28
0
    def database_deltree(self, family, keytree):
        """Remove database keytree / value.

        :param family:

        :type family:
            str

        :param keytree:

        :type keytree:
            str

        :returns:
            bool
        """
        cmd = 'DATABASE DELTREE %s %s' % (family, keytree)
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False
        return True
Exemplo n.º 29
0
    def speech_set(self, name, value):
        """Sets a speech engine setting.

        :param name:

        :type name:
            str

        :param value:

        :type value:
            str

        :returns:
            bool
        """
        cmd = 'SPEECH SET %s %s' % (name, value)
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False

        return True
Exemplo n.º 30
0
    def speech_load_grammar(self, name, path):
        """Loads a grammar.

        :param name:

        :type name:
            str

        :param path:

        :type path:
            str

        :returns:
            bool
        """
        cmd = 'SPEECH LOAD GRAMMAR %s %s' % (name, path)
        res = utils.agi_send(cmd)[1]
        if res != '1':
            return False

        return True