diff --git a/scripts/plivo_install.sh b/scripts/plivo_install.sh index f2b223c0..a888c44a 100755 --- a/scripts/plivo_install.sh +++ b/scripts/plivo_install.sh @@ -5,8 +5,8 @@ # Copyright (c) 2011 Plivo Team. See LICENSE for details. -PLIVO_GIT_REPO=git://github.com/plivo/plivo.git -PLIVO_SETUP_SCRIPT=https://github.com/plivo/plivo/raw/master/scripts/ez_setup.py +PLIVO_GIT_REPO=git://github.com/digination/plivo.git +PLIVO_SETUP_SCRIPT=https://github.com/digination/plivo/raw/master/scripts/ez_setup.py BRANCH=$2 diff --git a/src/plivo/rest/freeswitch/api.py b/src/plivo/rest/freeswitch/api.py index 051c7b60..31967e95 100644 --- a/src/plivo/rest/freeswitch/api.py +++ b/src/plivo/rest/freeswitch/api.py @@ -2205,3 +2205,150 @@ def send_digits(self): result = True return self.send_response(Success=result, Message=msg) + @auth_protect + def bridge(self): + """Creates a bridge between 2 calls given their uuids. + In order To bridge two calls, make an HTTP POST request to a + resource URI. + + POST Parameters + --------------- + + Required Parameters - You must POST the following parameters: + + CallUUID1: Unique Call ID of the first call to bridge. + CallUUID2: Unique Call ID of the second call to bridge. + + """ + self._rest_inbound_socket.log.debug("RESTAPI Bridge with %s" \ + % str(request.form.items())) + msg = "" + result = False + + calluuid1 = get_post_param(request, 'callUUID1') + calluuid2 = get_post_param(request, 'callUUID2') + + if not calluuid1 or not calluuid2: + msg = "CallUUID Parameter Missing" + return self.send_response(Success=result, Message=msg) + + cmd = "uuid_bridge %s %s" % (calluuid1,calluuid2) + res = self._rest_inbound_socket.bgapi(cmd) + job_uuid = res.get_job_uuid() + if not job_uuid: + self._rest_inbound_socket.log.error("Calls bridging failed -- JobUUID not received" % job_uuid) + msg = "Bridging failed" + return self.send_response(Success=result, Message=msg) + + msg = "Bridge executed" + result = True + return self.send_response(Success=result, Message=msg) + + @auth_protect + def command_exec(self): + """Executes an arbitrary command through Event Socket + + POST Parameters + --------------- + + Required Parameters - You must POST the following parameters: + + command: the command string with its arguments. + bg: tells if the command must in run through bgapi or not + """ + self._rest_inbound_socket.log.debug("RESTAPI Command with %s" \ + % str(request.form.items())) + msg = "" + result = False + + cmd = get_post_param(request, 'command') + bg = get_post_param(request, 'bg') + + if not cmd: + msg = "command Parameter Missing" + return self.send_response(Success=result, Message=msg) + if not bg: + msg = "command Parameter Missing" + return self.send_response(Success=result, Message=msg) + + + if (bg == "true"): + + res = self._rest_inbound_socket.bgapi(cmd) + job_uuid = res.get_job_uuid() + if not job_uuid: + self._rest_inbound_socket.log.error("command '%s' failed -- JobUUID not received" % (cmd,job_uuid)) + msg = "Command failed" + return self.send_response(Success=result, Message=msg) + + msg = job_uuid + result = True + return self.send_response(Success=result, Message=msg) + + else: + res = self._rest_inbound_socket.api(cmd) + msg = res.get_response() + result = True + return self.send_response(Success=result, Message=msg) + + + @auth_protect + def get_var(self): + """Get Contextual variables given UUID + + POST Parameters + --------------- + + Required Parameters - You must POST the following parameters: + + UUID: the call/bridge uuid + varName: name of the variable to retrieve + """ + self._rest_inbound_socket.log.debug("RESTAPI Command with %s" \ + % str(request.form.items())) + msg = "" + result = False + + uuid = get_post_param(request, 'UUID') + var_name = get_post_param(request, 'varName') + + if not uuid: + msg = "UUID Parameter Missing" + return self.send_response(Success=result, Message=msg) + if not var_name: + msg = "varName Parameter Missing" + return self.send_response(Success=result, Message=msg) + + cmd="uuid_getvar %s %s" % (uuid,var_name) + res = self._rest_inbound_socket.api(cmd) + #job_uuid = res.get_job_uuid() + #if not job_uuid: + #self._rest_inbound_socket.log.error("command '%s' failed -- JobUUID not received" % (cmd,job_uuid)) + #msg = "Command failed" + #return self.send_response(Success=result, Message=msg) + + msg = res.get_response() + result = True + return self.send_response(Success=result, Message=msg) + + @auth_protect + def create_uuid(self): + """Creates and return an uuid + + POST Parameters + --------------- + + Required Parameters - You must POST the following parameters: + None + """ + self._rest_inbound_socket.log.debug("RESTAPI Command with %s" \ + % str(request.form.items())) + msg = "" + result = False + + cmd="create_uuid" + res = self._rest_inbound_socket.api(cmd) + msg = res.get_response() + result = True + return self.send_response(Success=result, Message=msg) + diff --git a/src/plivo/rest/freeswitch/urls.py b/src/plivo/rest/freeswitch/urls.py index 4e48e3a0..50637ca6 100644 --- a/src/plivo/rest/freeswitch/urls.py +++ b/src/plivo/rest/freeswitch/urls.py @@ -82,4 +82,12 @@ '/' + PLIVO_VERSION + '/ConferenceListMembers/': (PlivoRestApi.conference_list_members, ['POST']), # API to list all conferences with members '/' + PLIVO_VERSION + '/ConferenceList/': (PlivoRestApi.conference_list, ['POST']), + # API to execute a raw ESL command + '/' + PLIVO_VERSION + '/Command/': (PlivoRestApi.command_exec, ['POST']), + # API to create a bridge between two calls given their uuids + '/' + PLIVO_VERSION + '/Bridge/': (PlivoRestApi.bridge, ['POST']), + # API to get contextual variables given UUID + '/' + PLIVO_VERSION + '/GetVar/': (PlivoRestApi.get_var, ['POST']), + # API to create a new uuid + '/' + PLIVO_VERSION + '/CreateUUID/': (PlivoRestApi.create_uuid, ['POST']), }