Exemple #1
0
def call(to_number, from_number, gateway, answered=ANSWERED,extra_dial_string=EXTRA_DIAL_STRING):
    plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)
    call_params = {
        'From': from_number, # Caller Id
        'To' : to_number, # User Number to Call
        'Gateways' : gateway, # Gateway string to try dialing separated by comma. First in list will be tried first
        'GatewayCodecs' : "", # Codec string as needed by FS for each gateway separated by comma
        'GatewayTimeouts' : "20,20",      # Seconds to timeout in string for each gateway separated by comma
        'GatewayRetries' : "2,1", # Retry String for Gateways separated by comma, on how many times each gateway should be retried
        'ExtraDialString' : extra_dial_string,
        'AnswerUrl' : answered+'answered/',
        'HangupUrl' : answered+'hangup/',
        'RingUrl' : answered+'ringing/',
        #'TimeLimit' : '15',
    	#'HangupOnRing': '0',
    }
    request_uuid = ""

    #Perform the Call on the Rest API
    try:
        result = plivo.call(call_params)
        logger.info(str(result))
        return result
    except Exception, e:
        print str(e)
        return "Error"
Exemple #2
0
 def __init__(self, argument, start_time, duration, is_streamed, program):
     self.__argument = argument
     self.start_time = start_time
     self.duration = duration
     self.__is_streamed = is_streamed
     self.__program = program
     self.__plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN,
                                     API_VERSION)
 def teardown(self):
     logger.info("In TEARDOWN of news report {}".format(self.conference))
     #hang up calls if they have not been hung up
     plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)
     hangup_call_params = {'RequestUUID' : self.RequestUUID} # CallUUID for Hangup
     try:
         result = plivo.hangup_call(hangup_call_params)
         logger.info(str(result))
     except Exception, e:
         logger.error('Failed to hangup in new_report', exc_info=True)
    def report(self):
        logger.info("In REPORT of news report {}".format(self.conference))
        #play report sound
        if self.is_master == True:
            logger.info("In conference: {}".format(self.conference))
            # Create a REST object
            plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)
            call_params = {'ConferenceName':'plivo', 'MemberID':'all', 'FilePath':'/home/csik/public_html/sounds/programs/5/current.mp3'}
            try:
                result = plivo.conference_play(call_params)
		logger.info("Result of conference play: {}".format(result))
            except Exception, e:
                logger.info("Exception in news_report REPORT: {},{}".format(Exception, e))    
Exemple #5
0
def group_call(gateway, phone_numbers, answered): 
    print "gateway = "+gateway
    print "phone_numbers = "+phone_numbers
    print "answered = "+answered

    # Define Channel Variable - http://wiki.freeswitch.org/wiki/Channel_Variables
    extra_dial_string = "bridge_early_media=true,hangup_after_bridge=true"
    
    # Create a REST object
    plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)
    
    # Initiate a new outbound call to user/1000 using a HTTP POST
    # All parameters for bulk calls shall be separated by a delimeter
    call_params = {
        'Delimiter' : '>', # Delimter for the bulk list
        'From': SHOW_HOST, # Caller Id
        'To' : phone_numbers, # User Numbers to Call separated by delimeter
        'Gateways' : gateway, # Gateway string for each number separated by delimeter
        'GatewayCodecs' : "", # Codec string as needed by FS for each gateway separated by delimeter
        'GatewayTimeouts' : "20>20", # Seconds to timeout in string for each gateway separated by delimeter
        'GatewayRetries' : "2>1", # Retry String for Gateways separated by delimeter, on how many times each gateway should be retried
        'ExtraDialString' : extra_dial_string,
        'AnswerUrl' : answered+'answered/',
        'HangupUrl' : answered+'hangup/',
        'RingUrl' : answered+'ringing/',
    #    'ConfirmSound' : "test.wav",
    #    'ConfirmKey' : "1",
    #    'RejectCauses': 'NO_USER_RESPONSE,NO_ANSWER,CALL_REJECTED,USER_NOT_REGISTERED',
    #    'ConfirmSound': '/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-requested_wakeup_call_for.wav',
    #    'ConfirmKey': '9'
    #    'TimeLimit' : '10>30',
    #    'HangupOnRing': '0>0',
    }

    request_uuid = ""

    #Perform the Call on the Rest API
    try:
        result = plivo.call(call_params)
        print result
    except Exception, e:
        print e
        raise
Exemple #6
0
def bulk_call(to_numbers, from_number, gateway, answered=ANSWERED,extra_dial_string=EXTRA_DIAL_STRING): 

    # Create a REST object
    plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)
    
    # Initiate a new outbound call using a HTTP POST
    # All parameters for bulk calls shall be separated by a delimeter
    call_params = {
        'Delimiter' : '>', # Delimter for the bulk lst
        'From': from_number, # Caller Id
        'To' : to_numbers, # User Numbers to Call separated by delimeter
        'Gateways' : gateway, # Gateway string for each number separated by delimeter
        'GatewayCodecs' : "", # Codec string as needed by FS for each gateway separated by delimeter
        'GatewayTimeouts' : "20>20", # Seconds to timeout in string for each gateway separated by delimeter
        'GatewayRetries' : "2>1", # Retry String for Gateways separated by delimeter, on how many times each gateway should be retried
        'ExtraDialString' : extra_dial_string,
        'AnswerUrl' : answered_URL+'answered/',
        'HangupUrl' : answered_URL+'hangup/',
        'RingUrl' : answered_URL+'ringing/',
    #    'ConfirmSound' : "test.wav",
    #    'ConfirmKey' : "1",
    #    'RejectCauses': 'NO_USER_RESPONSE,NO_ANSWER,CALL_REJECTED,USER_NOT_REGISTERED',
    #    'ConfirmSound': '/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-requested_wakeup_call_for.wav',
    #    'ConfirmKey': '9'
    #    'TimeLimit' : '10>30',
    #    'HangupOnRing': '0>0',
    }

    request_uuid = ""

    #Perform the Call on the Rest API
    try:
        result = plivo.bulk_call(call_params)
        logger.info(str(result))
        return [result.get('Success'),result.get('RequestUUID')]
    except Exception, e:
        logger.error('Failed to make utils.bulkcall', exc_info=True)
        pass
Exemple #7
0
def call(to_number, from_number, gateway, answered=ANSWERED,extra_dial_string=EXTRA_DIAL_STRING):
    """
    Make a call, using (gateway, phone_number)
    TODO: actually make the other parameters correspond
    """
    logger.info("gateway = "+gateway)
    logger.info("from {0}, to {1}".format(from_number, to_number))
    logger.info("answered = "+answered)
    # Define Channel Variable - http://wiki.freeswitch.org/wiki/Channel_Variables

    # Create a REST object
    plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)
    call_params = {
        'From': from_number, # Caller Id
        'To' : to_number, # User Number to Call
        'Gateways' : gateway, # Gateway string to try dialing separated by comma. First in list will be tried first
        'GatewayCodecs' : "", # Codec string as needed by FS for each gateway separated by comma
        'GatewayTimeouts' : "20,20",      # Seconds to timeout in string for each gateway separated by comma
        'GatewayRetries' : "2,1", # Retry String for Gateways separated by comma, on how many times each gateway should be retried
        'ExtraDialString' : extra_dial_string,
        'AnswerUrl' : answered+'answered/',
        'HangupUrl' : answered+'hangup/',
        'RingUrl' : answered+'ringing/',
        #'TimeLimit' : '15',
    	#'HangupOnRing': '0',
    }
    request_uuid = ""

    #Perform the Call on the Rest API
    try:
        result = plivo.call(call_params)
        logger.info(str(result))
        return result
    except Exception, e:
        logger.error('Failed to make utils.call', exc_info=True)
        pass
#!/usr/bin/env python
import plivohelper
import sys

try:
    room = sys.argv[1]
    memberid = sys.argv[2]
except IndexError:
    print "Need ConferenceName and MemberID args"
    sys.exit(1)

# URL of the Plivo REST Service
REST_API_URL = 'http://127.0.0.1:8088'
API_VERSION = 'v0.1'

# Sid and AuthToken
SID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
AUTH_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'

# Create a REST object
plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)

call_params = {'ConferenceName': room, 'MemberID': memberid}

try:
    print plivo.conference_unmute(call_params)
except Exception, e:
    print e
def call_plivo(callerid=None,
               phone_number=None,
               Gateways=None,
               GatewayCodecs="'PCMA,PCMU'",
               GatewayTimeouts="60",
               GatewayRetries='1',
               ExtraDialString=None,
               AnswerUrl=None,
               HangupUrl=None,
               TimeLimit="3600"):
    # URL of the Plivo REST service

    # Define Channel Variable -
    # http://wiki.freeswitch.org/wiki/Channel_Variables
    extra_dial_string = "bridge_early_media=true,hangup_after_bridge=true"
    if len(ExtraDialString) > 0:
        extra_dial_string = extra_dial_string + ',' + ExtraDialString

    if not phone_number:
        print "Error : Phone Number needs to be defined!"
        return False

    if not callerid:
        callerid = '8888888888'

    if not GatewayCodecs:
        GatewayCodecs = "'PCMA,PCMU'"

    if not GatewayTimeouts:
        GatewayTimeouts = "1800"

    if not GatewayRetries:
        GatewayRetries = "1"

    if not TimeLimit:
        TimeLimit = "3600"

    # Create a REST object
    plivo = plivohelper.REST(REST_API_URL, SID, AUTH_TOKEN, API_VERSION)

    # Initiate a new outbound call to user/1000 using a HTTP POST
    call_params = {
        'From': callerid,  # Caller Id
        'To': phone_number,  # User Number to Call
        'Gateways':
        Gateways,  # Gateway string to try dialing separated by comma. First in list will be tried first
        'GatewayCodecs':
        GatewayCodecs,  # Codec string as needed by FS for each gateway separated by comma
        'GatewayTimeouts':
        GatewayTimeouts,  # Seconds to timeout in string for each gateway separated by comma
        'GatewayRetries':
        GatewayRetries,  # Retry String for Gateways separated by comma, on how many times each gateway should be retried
        'ExtraDialString': extra_dial_string,
        #TODO : Remove this
        #'AnswerUrl' : 'http://localhost/~areski/django/MyProjects/plivohelper-php/examples/test.php',
        #'AnswerUrl' : 'http://192.168.1.11:8000/api/dialer_cdr/answercall/',
        'AnswerUrl': AnswerUrl,
        'HangupUrl': HangupUrl,
        #TODO : Fix TimeLimit on Plivo
        #'TimeLimit' : TimeLimit,
    }

    print call_params

    #Perform the Call on the Rest API
    try:
        result = plivo.call(call_params)
        if result:
            print "RESULT FROM PLIVO HELPER : " + result['RequestUUID']
            return result
    except Exception, e:
        print e
        raise