Exemplo n.º 1
0
    def Play(self, resource_type, resource_id, audio_file):
        payload = {'appid': self.app}
        path = '/default/'
        if resource_type == 'call':
            path += 'calls/'
        elif resource_type == 'conference':
            path += 'conferences/'
        else:
            raise Exception('Unknown resource_type')
        path += resource_id
        # print '===================', path

        play_source = xmsrest.play_source(audio_uri=audio_file,
                                          audio_type='audio/x-wav')
        play = xmsrest.play(play_source=play_source)
        web_service = None
        if resource_type == 'call':
            call_action = xmsrest.call_action(play=play)
            call = xmsrest.call(call_action=call_action)
            web_service = xmsrest.web_service(call=call)
        elif resource_type == 'conference':
            conf_action = xmsrest.conf_action(play=play)
            conference = xmsrest.conference(conf_action=conf_action)
            web_service = xmsrest.web_service(conference=conference)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()

        response = requests.put(self.url + path, params=payload, data=data)
        print '===== Play on %s =====' % resource_type
        print response.status_code, response.reason
        print response.text
Exemplo n.º 2
0
    def Speak(self,
              resource_type,
              resource_id,
              call_type,
              call_id,
              content,
              content_type='text/plain'):
        payload = {'appid': self.app}
        path = '/default/mrcps/' + resource_id

        speak = xmsrest.speak(call_id=call_id,
                              content=content,
                              content_type=content_type)
        mrcp_action = xmsrest.mrcp_action(speak=speak)
        mrcp = xmsrest.mrcp(mrcp_action=mrcp_action)
        web_service = xmsrest.web_service(mrcp=mrcp)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()

        response = requests.put(self.url + path, params=payload, data=data)
        print '===== Speak on %s =====' % call_type
        print response.status_code, response.reason
        print response.text
Exemplo n.º 3
0
    def Create_MRCP(self, asr=False, tts=True):
        path = '/default/mrcps'
        payload = {'appid': self.app}

        mrcp = xmsrest.mrcp(asr=("yes" if asr else "no"),
                            tts=("yes" if tts else "no"))
        web_service = xmsrest.web_service(mrcp=mrcp)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()
        print '-------------'
        print data
        print '-------------'
        headers = {'Content-Type': 'application/xml'}
        http_response = requests.post(self.url + path,
                                      params=payload,
                                      data=data,
                                      headers=headers)
        print '===== Create_MRCP ===='
        print http_response.status_code, http_response.reason
        print http_response.text
        mrcp_href = None
        mrcp_identifier = None
        response = xmsrest.parseString(http_response.text)
        if response.mrcp_response is not None:
            mrcp_href = response.mrcp_response.href
            mrcp_identifier = response.mrcp_response.identifier
            print '-' * 10
            print "href:" + mrcp_href
            print "identifier:" + mrcp_identifier
        return (http_response.status_code, http_response.reason, mrcp_href,
                mrcp_identifier)
Exemplo n.º 4
0
    def Create_Conf(self, max_parties=60):
        path = '/default/conferences'
        payload = {'appid': self.app}

        conference = xmsrest.conference(max_parties=str(max_parties))
        web_service = xmsrest.web_service(conference=conference)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()
        print '-------------'
        print data
        print '-------------'
        http_response = requests.post(self.url + path,
                                      params=payload,
                                      data=data)
        print '===== Create_Conf ===='
        print http_response.status_code, http_response.reason
        print http_response.text
        conf_href = None
        conf_identifier = None
        response = xmsrest.parseString(http_response.text)
        if response.conference_response is not None:
            conf_href = response.conference_response.href
            conf_identifier = response.conference_response.identifier
            print '-' * 10
            print "href:" + conf_href
            print "identifier:" + conf_identifier
        return (http_response.status_code, http_response.reason, conf_href,
                conf_identifier)
Exemplo n.º 5
0
    def Create_EventHandler(self):
        path = '/default/eventhandlers'
        payload = {'appid': self.app}

        eventsubscribe = xmsrest.eventsubscribe()
        eventsubscribe.set_action("add")
        eventsubscribe.set_type("any")
        eventsubscribe.set_resource_id("any")
        eventsubscribe.set_resource_type("any")
        eventhandler = xmsrest.eventhandler(eventsubscribe=[eventsubscribe])
        web_service = xmsrest.web_service(eventhandler=eventhandler)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()
        print '===== Create_EventHandler Post Body===='
        print data
        print '=' * 10

        response = requests.post(self.url + path, params=payload, data=data)

        print '===== Create_EventHandler ===='
        print response.status_code, response.reason
        print response.text
        print '=' * 10
        if response.status_code == 201 and len(response.text) > 0:
            print '-' * 10
            response_body = xmsrest.parseString(response.text)
            print "identifier:" + \
                response_body.eventhandler_response.identifier
            print "href:" + \
                response_body.eventhandler_response.href
            self.eventhandlerhref = response_body.eventhandler_response.href
Exemplo n.º 6
0
    def Play_Collect(self, resource_type, resource_id, audio_file, digit_num):
        payload = {'appid': self.app}
        path = '/default/'
        if resource_type == 'call':
            path += 'calls/'
        elif resource_type == 'conference':
            path += 'conferences/'
        else:
            raise Exception('Unknown resource_type')
        path += resource_id

        timeout = 2

        play_source = xmsrest.play_source(audio_uri=audio_file,
                                          audio_type='audio/x-wav')
        playcollect = xmsrest.playcollect(
            play_source=play_source,
            cleardigits='yes',
            max_digits=str(digit_num),
            timeout=str(int(timeout * digit_num * 1.5)) + 's',
            interdigit_timeout=str(timeout) + 's')
        web_service = None
        if resource_type == 'call':
            call_action = xmsrest.call_action(playcollect=playcollect)
            call = xmsrest.call(call_action=call_action)
            web_service = xmsrest.web_service(call=call)
        elif resource_type == 'conference':
            conf_action = xmsrest.conf_action(playcollect=playcollect)
            conference = xmsrest.conference(conf_action=conf_action)
            web_service = xmsrest.web_service(conference=conference)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()
        print '-------------'
        print data
        print '-------------'
        response = requests.put(self.url + path, params=payload, data=data)
        print '===== Play_Collect on %s =====' % resource_type
        print response.status_code, response.reason
        print response.text
Exemplo n.º 7
0
    def Answer_Call(self, resource_type, resource_id):
        path = '/default/calls/' + resource_id
        payload = {'appid': self.app}

        call = xmsrest.call(answer="yes")
        web_service = xmsrest.web_service(call=call)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()

        response = requests.put(self.url + path, params=payload, data=data)
        print '===== Answer_Call ===='
        print response.status_code, response.reason
        print response.text
Exemplo n.º 8
0
    def Remove_Party(self, resource_type, resource_id, conf_identifier):
        path = '/default/calls/' + resource_id
        payload = {'appid': self.app}

        remove_party = xmsrest.remove_party(conf_id=conf_identifier)
        call_action = xmsrest.call_action(remove_party=remove_party)
        call = xmsrest.call(call_action=call_action)
        web_service = xmsrest.web_service(call=call)
        web_service.set_version("1.0")
        output = StringIO.StringIO()
        web_service.export(output, 0)
        data = output.getvalue()

        response = requests.put(self.url + path, params=payload, data=data)
        print '===== Remove_Party ===='
        print response.status_code, response.reason
        print response.text