Example #1
0
def changeGreeting():
    """
        record a greeting and put it in users greetings directory
    """
    ibs_agi.getSelectedLanguage().sayPrompt("pre_change_greeting")
    filename = "%s%s" % (ibs_agi.getConfig().getValue("user_greetings_root"),
                         ibs_agi.getConfig().getValue("username"))
    ibs_agi.getAGI().appexec("Record", "%s.gsm|7|60" % filename)
    ibs_agi.getSelectedLanguage().sayPrompt("change_greeting_success")
Example #2
0
def setSessionVariables():
    caller_id = filter_caller_id_match.sub(
        "",
        ibs_agi.getAGI().env["agi_callerid"])
    ibs_agi.getConfig().setValue("caller_id", caller_id)
    ibs_agi.getConfig().setValue("unique_id",
                                 ibs_agi.getAGI().env["agi_uniqueid"])
    ibs_agi.getConfig().setValue("channel",
                                 ibs_agi.getAGI().env["agi_channel"])
Example #3
0
 def sayFile(self, filename, escape=ibs_agi.ALL_ESCAPE):
     """
         say file "filename". can be esacped by "escape" digits.
         return the digit pressed for escape or empty string if no digit pressed
     """
     return ibs_agi.getAGI().stream_file(self._getFilePath(filename),
                                         escape)
Example #4
0
def dial(destination):
    duration = 0
    status = "HANGUP"
    do_call_end = True
    authorized = False
    try:
        remaining_time = ibs_agi.getStateMachine().gotoState(
            "AUTHORIZE", destination)

        if ibs_agi.getConfig().getValue("authorized"):
            ibs_agi.getStateMachine().gotoState("SAY_REMAINING_TIME",
                                                remaining_time)
            (duration, status) = ibs_agi.getStateMachine().gotoState(
                "DIAL_DESTINATION", destination, remaining_time)
        else:
            do_call_end = False
            return
    finally:
        if do_call_end:
            (duration, used_credit) = ibs_agi.getStateMachine().gotoState(
                "CALL_END", duration, status)

            ch_status = ibs_agi.getAGI().channel_status()
            if ibs_agi.getConfig().getValue("debug"):
                toLog("AferDial ChannelStatus: " + str(ch_status))

            ibs_agi.getStateMachine().gotoState("SAY_USED_CREDIT", duration,
                                                used_credit)
Example #5
0
def getFastDialDigits(_index,retry=0):
    for f in [lambda:ibs_agi.getSelectedLanguage().sayPrompt("pre_get_fast_dial_destination"),
              lambda:ibs_agi.getSelectedLanguage().sayDigit(_index),
              lambda:ibs_agi.getSelectedLanguage().sayPrompt("post_get_fast_dial_destination")]:
        digit=f()
        if digit:
            break
    
    end_of_collect="#"
    request_recollect="*"
    max_digits=ibs_agi.getConfig().getValue("max_destination_digits")
    timeout=4000
    
    digits=""
    
    while len(digits)<max_digits:
        digits+=digit
        digit=ibs_agi.getAGI().wait_for_digit(timeout)
        if not digit: #timeout
            if digits:
                break
            else:
                retry+=1
                if retry<ibs_agi.getConfig().getValue("retry"):
                    return getFastDialDigits(_index,retry)
                else:
                    return ""
        elif digits=="" and digit=="*":
            return "*"
        elif digit==request_recollect:
            return getFastDialDigits(_index)
        elif digit==end_of_collect:
            break
                
    return digits
Example #6
0
def chooseLanguage():
    if ibs_agi.getConfig().getValue(
            "language") != "":  #language already selected
        return
    elif len(ibs_agi.getLangManager().getAllLanguages()) == 1:
        lang_obj = ibs_agi.getLangManager().getLanguageByIndex(0)
    else:
        digit = ''
        while not digit:
            i = 0
            for lang_code, lang_obj in ibs_agi.getLangManager(
            ).getAllLanguages():
                digit = lang_obj.sayLanguageOption(i + 1)
                if digit:
                    break
                i += 1

            if not digit:
                digit = ibs_agi.getAGI().wait_for_digit(5000)

            if not digit:
                ibs_agi.getLangManager().getLanguageByIndex(0).sayPrompt(
                    "no_digit_entered")
                continue
            else:
                try:
                    lang_obj = ibs_agi.getLangManager().getLanguageByIndex(
                        int(digit) - 1)
                except IndexError:
                    continue

                break

    ibs_agi.getConfig().setValue("language", lang_obj.getLanguageCode())
Example #7
0
def sayUserGreeting():
    """
        say user greeting if available
        return True if greeting was not available for user
        return False if greeting was played
    """
    if ibs_agi.getConfig().getValue("authenticated"):
        filename = "%s%s" % (ibs_agi.getConfig().getValue(
            "user_greetings_root"), ibs_agi.getConfig().getValue("username"))
        try:
            os.stat("%s.gsm" % filename)
        except OSError:
            return True
        else:
            ibs_agi.getAGI().stream_file(filename, ibs_agi.ALL_ESCAPE)
            return False

    return True
Example #8
0
def getFastDialIndex():
    _index = ""
    counter = 0
    while _index == "" and counter < ibs_agi.getConfig().getValue("retry"):
        counter += 1
        _index = ibs_agi.getSelectedLanguage().sayPrompt(
            "enter_fast_dial_index")
        if not _index:
            _index = ibs_agi.getAGI().wait_for_digit(3000)

    return _index
Example #9
0
 def sayFilesAndCollect(self,
                        file_list,
                        max_digits,
                        timeout=4000,
                        end_of_collect="#",
                        escape=ibs_agi.ALL_ESCAPE):
     digit = self.sayFiles(file_list, escape)
     digits = digit
     while len(digits) < max_digits:
         digit = ibs_agi.getAGI().wait_for_digit(timeout)
         if not digit or digit == end_of_collect:  #timeout
             break
         digits += digit
     return digits
Example #10
0
def confirmFastDial(_index, destination):
    for f in [
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "pre_confirm_fast_dial"),
            lambda: ibs_agi.getSelectedLanguage().sayDigit(_index),
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "mid_confirm_fast_dial"),
            lambda: ibs_agi.getSelectedLanguage().sayDigits(destination),
            lambda: ibs_agi.getSelectedLanguage().sayPrompt(
                "post_confirm_fast_dial"),
    ]:
        digit = f()
        if digit:
            return digit

    return ibs_agi.getAGI().wait_for_digit(3000)
Example #11
0
def dialDestination(destination, remaining_time):
    """
        dial destination and return duration of call
        if call was unsuccessful say the error
    """
    dial_str = ibs_agi.getConfig().getDialString(destination)
    if remaining_time > 0:
        dial_str += "L(%s:30000)" % (int(remaining_time) * 1000)
        ibs_agi.getAGI().set_variable(
            "LIMIT_WARNING_FILE",
            ibs_agi.getSelectedLanguage()._getFilePath("disconnect_30"))
        ibs_agi.getAGI().set_variable(
            "LIMIT_TIMEOUT_FILE",
            ibs_agi.getSelectedLanguage()._getFilePath(
                "you_have_been_disconnected"))

    if ibs_agi.getConfig().getValue("debug"):
        toLog("Dial: Destination %s DialString %s" % (destination, dial_str))

    ibs_agi.getAGI().appexec("Dial", dial_str)

    duration = 0
    status = ibs_agi.getAGI().get_variable("DIALSTATUS")

    if status in ["CHANUNAVAIL", "CONGESTION"]:
        ibs_agi.getSelectedLanguage().sayPrompt("destination_out_of_service")
    elif status in ["BUSY"]:
        ibs_agi.getSelectedLanguage().sayPrompt("destination_busy")
    elif status in ["NOANSWER"]:
        ibs_agi.getSelectedLanguage().sayPrompt("destination_noanswer")
    elif status in ["ANSWER"]:
        duration = ibs_agi.getAGI().get_variable("ANSWEREDTIME")
    elif status in ["CANCEL"]:
        pass

    if ibs_agi.getConfig().getValue("debug"):
        toLog("Dial: Status %s AnsweredTime %s" % (status, duration))

    ibs_agi.getConfig().setValue("authorized", False)

    return duration, status
Example #12
0
def getDestination(repeat=False, retry=0):
    """
        get destination and return it. return '*' if user requested to goto the menu
    """
    end_of_collect = "#"
    request_redial = "*"
    max_digits = ibs_agi.getConfig().getValue("max_destination_digits")
    timeout = 4000

    destination = ""
    if repeat:  #are we trying to redial?
        digit = ibs_agi.getSelectedLanguage().sayPrompt(
            "get_destination_again")
    else:
        digit = ibs_agi.getSelectedLanguage().sayPrompt("get_destination")
    if digit == "*":
        return digit
    else:
        while len(destination) < max_digits:
            destination += digit
            digit = ibs_agi.getAGI().wait_for_digit(timeout)
            if not digit:  #timeout
                if destination:
                    break
                else:
                    retry += 1
                    if retry < ibs_agi.getConfig().getValue("retry"):
                        return getDestination(repeat, retry)
                    else:
                        return ""
            elif destination == "" and digit == "*":
                return "*"
            elif digit == request_redial:
                return getDestination(True)
            elif digit == end_of_collect:
                break

        return destination
Example #13
0
def menu():
    while True:
        selection = ibs_agi.getStateMachine().gotoState("SAY_MENU")

        if selection == "":  #timeout
            selection = ibs_agi.getAGI().wait_for_digit(5000)
            if selection == "":
                ibs_agi.getSelectedLanguage().sayPrompt("no_digit_entered")
                continue

        if ibs_agi.getConfig().getValue("debug"):
            toLog("Menu: Selected %s" % selection)

        if selection in "*#":  #go and ask for destination again
            return

        try:
            new_state = ibs_agi.getSelectedLanguage().getMenuIndexState(
                int(selection))
        except (KeyError, ValueError):
            ibs_agi.getStateMachine().gotoState("BAD_MENU_SELECTION")
            continue

        ibs_agi.getStateMachine().gotoState(new_state)
Example #14
0
 def sayDigit(self, digit, escape=ibs_agi.ALL_ESCAPE):
     """
         Say Digit
     """
     return ibs_agi.getAGI().stream_file(self._getFilePath(digit), escape)
Example #15
0
def hangup():
    return ibs_agi.getAGI().hangup()