当前位置: 首页>>代码示例>>Python>>正文


Python Tropo.hangup方法代码示例

本文整理汇总了Python中tropo.Tropo.hangup方法的典型用法代码示例。如果您正苦于以下问题:Python Tropo.hangup方法的具体用法?Python Tropo.hangup怎么用?Python Tropo.hangup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tropo.Tropo的用法示例。


在下文中一共展示了Tropo.hangup方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sms_in

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
def sms_in(request):
    """
    Handles tropo messaging requests
    """
    if request.method == "POST":
        data = json.loads(request.body)
        session = data["session"]
        # Handle when Tropo posts to us to send an SMS
        if "parameters" in session:
            params = session["parameters"]
            if ("_send_sms" in params) and ("numberToDial" in params) and ("msg" in params):
                numberToDial = params["numberToDial"]
                msg = params["msg"]
                t = Tropo()
                t.call(to = numberToDial, network = "SMS")
                t.say(msg)
                return HttpResponse(t.RenderJson())
        # Handle incoming SMS
        phone_number = None
        text = None
        if "from" in session:
            phone_number = session["from"]["id"]
        if "initialText" in session:
            text = session["initialText"]
        if phone_number is not None and len(phone_number) > 1:
            if phone_number[0] == "+":
                phone_number = phone_number[1:]
        incoming_sms(phone_number, text, SQLTropoBackend.get_api_id())
        t = Tropo()
        t.hangup()
        return HttpResponse(t.RenderJson())
    else:
        return HttpResponseBadRequest("Bad Request")
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:35,代码来源:views.py

示例2: tropo_view

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
def tropo_view(request):
    if request.method == "POST":
        data = json.loads(request.raw_post_data)
        session = data["session"]
        if "parameters" in session:
            params = session["parameters"]
            if ("_send_sms" in params) and ("numberToDial" in params) and ("msg" in params):
                numberToDial = params["numberToDial"]
                msg = params["msg"]
                t = Tropo()
                t.call(to = numberToDial, network = "SMS")
                t.say(msg)
                log("OUT", "TEXT", numberToDial, "TROPO", request.raw_post_data, msg)
                return HttpResponse(t.RenderJson())
        if "from" in session:
            caller_id = session["from"]["id"]
            channel = session["from"]["channel"]
            msg = None
            if "initialText" in session:
                msg = session["initialText"]
            log("IN", channel, caller_id, "TROPO", request.raw_post_data, msg)
            if channel == "VOICE":
                send_sms_tropo(caller_id, "Callback received.")
        t = Tropo()
        t.hangup()
        return HttpResponse(t.RenderJson())
    else:
        return HttpResponseBadRequest()
开发者ID:gcapalbo,项目名称:flashback_test,代码行数:30,代码来源:views.py

示例3: do_voice

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
    def do_voice(self):
        t = Tropo()

        caller_id = models.votes.caller_id_if_valid(self.call_id())
        web.debug("starting to handle voice call from %s" % caller_id)

        if models.votes.caller_id_can_vote(caller_id):
            t.on(event="continue", next="/webapi/vote/menu")
        elif not caller_id:
            t.say("Oops, you need to have caller eye dee enabled to vote. Goodbye.")
            t.hangup()
        else:
            t.say("Oops, it looks like you have voted already. Goodbye.")
            t.hangup()

        return t.RenderJson()
开发者ID:imclab,项目名称:tropo-voting-app,代码行数:18,代码来源:voting_webapi.py

示例4: do_voice

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
    def do_voice(self):
        t = Tropo()
        t.say("Roses are red, violets are blue.")
        t.say("Please vote for the startup that most disrupts you.")

        caller_id = models.caller_id_if_valid(self.call_id())
        if models.caller_id_can_vote(caller_id):
            t.on(event="continue", next="/vote/menu")
        elif not caller_id:
            t.say("Oops, you need to have caller eye dee enabled to vote. Goodbye.")
            t.hangup()
        else:
            t.say("Oops, it looks like you have voted already. Goodbye.")
            t.hangup()

        return t.RenderJson()
开发者ID:ananelson,项目名称:tropo-vote,代码行数:18,代码来源:vote.py

示例5: test_hangup

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
    def test_hangup(self):
        """
        Test the "hangup" Tropo class method.
        """

        tropo = Tropo()
        tropo.hangup()
        rendered = tropo.RenderJson()
        pretty_rendered = tropo.RenderJson(pretty=True)
        print "===============test_hangup================="
        print "render json: %s" % pretty_rendered

        # print "test_hangup: %s" % tropo.RenderJson()
        rendered_obj = jsonlib.loads(rendered)
        wanted_json = '{"tropo": [{"hangup": {}}]}'
        wanted_obj = jsonlib.loads(wanted_json)
        self.assertEqual(rendered_obj, wanted_obj)
开发者ID:JustinDupree,项目名称:tropo-webapi-python,代码行数:19,代码来源:test.py

示例6: handle_request

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
    def handle_request(self, request):
	if request.method != 'POST':
		return HttpResponse('Not a post!')
        self.debug('This is the tropo Request (raw): %s' % request.raw_post_data)
	s = Session(request.raw_post_data)
	if not s.callId:
                t = Tropo()
                t.message(s.parameters['msg'], to="tel:+%s" %  s.parameters['numberToDial'], network="SMS")
                return HttpResponse(t.RenderJson())
	else:
	        message = self.message(request.POST)
        	if message:
            		self.route(message)

	        t = Tropo()
        	t.hangup()
	        return HttpResponse(t.RenderJson())
开发者ID:hartfordr,项目名称:rapidsms-core-dev,代码行数:19,代码来源:tropobackend.py

示例7: index

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
def index(request):

    t = Tropo()
    t.say("A B C song")
    recordURLobj1 = RecordUrlTuple(url = "http://192.168.26.88:8080/FileUpload/uploadFile1", username = "fakename1", password="fakepassword", method="POST").json
    recordURLobj2 = RecordUrlTuple(url = "http://192.168.26.88:8080/FileUpload/uploadFile", username = "fakename2", password="fakepassword", method="POST").json
    recordURLobj3 = RecordUrlTuple(url = "http://192.168.26.88:8080/FileUpload/uploadFile3", username = "fakename3", password="fakepassword", method="POST").json
    recordURLobj4 = RecordUrlTuple(url = "http://192.168.26.88:8080/FileUpload/uploadFile4", username = "fakename4", password="fakepassword", method="POST").json
    
    t.startRecording([recordURLobj1, recordURLobj2, recordURLobj3, recordURLobj4], formamt = 'audio/wav', transcriptionID = "20170601startRecording", transcriptionEmailFormat = "plain", transcriptionLanguage = "en-usa", transcriptionOutURI = "http://12b12d1b.ngrok.io/FileUpload/receiveJson") 
    t.say("a b c d e f g h i j k l m n o p q r s t u v w x y z now you know your a b c start sing with me ")
    t.say("Merry Christmas and happy new year")
    t.say("1 2 3 4 5 6 7 8 9 0 A B C D E F G")
    t.say("today is Thursday 2017-12-25")
    t.stopRecording()
    t.hangup()
    return t.RenderJson()
开发者ID:tropo,项目名称:tropo-webapi-python,代码行数:19,代码来源:startRecordingMultiUrl_test.py

示例8: CallResponse

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
class CallResponse(object):
    '''
    A response to a request from a voip provider such as twilio or tropo.  
    Abstracts common verbs such as .say() and .ask() and .conference() and provides the appropriate command for the provider.
    '''
    
    def __init__(self, provider, *args, **kwargs):
        '''
        Takes a PhoneProvider object, sets the provider for this response to that provider.
        '''
        self.provider = provider
        if provider.name == "Twilio":
            self.response_object = twiml.Response()
        if provider.name == "Tropo":
            self.response_object = Tropo()
        super(CallResponse, self).__init__()
        
    def render(self):
        if self.provider.name == "Twilio":
            return HttpResponse(self.response_object, mimetype='text/xml')
        if self.provider.name == "Tropo":
            return HttpResponse(self.response_object.RenderJson(), mimetype='text/json')
    
    def say(self, *args, **kwargs):
        if self.provider.name == "Twilio":
            if kwargs['voice'] == 'Allison' or kwargs['voice'] == 'Susan' or kwargs['voice'] == 'Vanessa':
                kwargs['voice'] = 'woman'
            else:
                kwargs['voice'] = 'man'
            return self.response_object.addSay(*args, **kwargs)
        if self.provider.name == "Tropo":
            return self.response_object.say(*args, **kwargs)

    def transfer(self, *args, **kwargs):
        if self.provider.name == "Twilio":
            return self.response_object.addDial(*args, **kwargs)
        if self.provider.name == "Tropo":
            return self.response_object.transfer(*args, **kwargs)
        
    def conference(self, start_recording=False, *args, **kwargs):
        if self.provider.name == "Twilio":
            if start_recording:
                dial = self.response_object.addDial(record=True, action='%s/comm/recording_handler/call/%s/' % (resources.COMM_DOMAIN, kwargs['conference_id']))
            else:
                dial = self.response_object.addDial()
            startConferenceOnEnter = True if 'start_now' in kwargs and kwargs['start_now'] else False #Sometimes we want this joiner to start the conference.  Sometimes not.
            command = dial.addConference(kwargs['conference_id'], startConferenceOnEnter=startConferenceOnEnter)
            comm_logger.info('Telling Twilio: %s' % dial)
            return command
        if self.provider.name == "Tropo":
            self.response_object.on("hangup", next="/comm/handle_hangup/%s/%s/" % (kwargs['conference_id'], kwargs['number'].id))
            if 'record' in kwargs and kwargs['record']:
                self.response_object.startRecording('%s/comm/recording_handler/call/%s/' % (resources.COMM_DOMAIN, kwargs['conference_id']), format="audio/mp3")
            return self.response_object.conference(kwargs['conference_id'], allowSignals=['leaveConference',], *args, **kwargs)
    
    def conference_holding_pattern(self, conference_id, number_object, hold_music):
        '''
        Put someone on hold, perparing them for a conference.  During their hold, play the hold music.
        '''
        if self.provider.name == "Twilio":
            dial = self.response_object.addDial()
            reactor.callFromThread(twilio_deferred_voicemail_determination, conference_id, 30)
            return dial.addConference(conference_id)#TODO: waitUrl=hold_music)
         
        if self.provider.name == "Tropo":
            #First we add the hold music, allowing for the "exithold" signal to end it.
            self.response_object.say(hold_music, allowSignals=["joinConference", "goToVoiceMail", "incomplete"])
            self.response_object.on("hangup", next="/comm/handle_hangup/%s/%s/" % (conference_id, number_object.id))
            self.response_object.on('joinConference', next="/comm/simply_join_conference/%s/%s/" % (conference_id, number_object.id))
            self.response_object.on('goToVoiceMail', next="/comm/voicemail/")
            reactor.callFromThread(send_deferred_tropo_signal, conference_id, 'goToVoiceMail', 40) #How to test this?

    def join_and_begin_conference(self, conference_id, number, *args, **kwargs):
        '''
        Join the user to a conference that started with a holding pattern and begin the conference.
        '''
        comm_logger.info('%s is beginning conference %s', number, conference_id)
        conference_kwargs = {'conference_id':conference_id, 'number':number}
        if self.provider.name == "Twilio":
            conference_kwargs['start_now'] = True
        if self.provider.name == "Tropo":
            reactor.callFromThread(send_deferred_tropo_signal, conference_id, 'joinConference', 0)
            
        self.conference(start_recording=True, **conference_kwargs)
        return True #We can't know anything meaningful because we aren't going to wait around for the signal.
    
    def on(self, *args, **kwargs):
        if self.provider.name == "Twilio":
            raise NotImplementedError("Twilio does not offer an equivalent to Tropo's .on() method.")
        if self.provider.name == "Tropo":
            return self.response_object.on(*args, **kwargs)
        
    def call(self, *args, **kwargs):
        if self.provider.name == "Twilio":
            raise NotImplementedError("Twilio does not offer an equivalent to Tropo's .call() method.")
        if self.provider.name == "Tropo":
            if 'caller_id' in kwargs:
                kwargs['from'] = kwargs['caller_id'] #Why Tropo, do you think it's acceptable to use a python command (from) in your lib?
            return self.response_object.call(*args, **kwargs)
    
#.........这里部分代码省略.........
开发者ID:SlashRoot,项目名称:WHAT,代码行数:103,代码来源:response.py

示例9: Tropo

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
    if (0):
        TO = "8005551212"

        ID = "foo"
        URL = "http://s3.amazonaws.com/xxx_s3_bucket/hello.wav"



        tropo = Tropo()

        tropo.ask("[5 digits]",
                  say = Say("Please enter a 5 digit zip code").json)

        tropo.call (TO)
        tropo.conference(ID)
        tropo.hangup()
        tropo.message ("Hello, World", TO)
        tropo.on(event="continue", 
             next="http://example.com/weather.py",
             say="Please hold.")

        tropo.record(say="Please say something for posterity", 
                     url=URL, 
                     choices = Choices("", terminator="#").json)
        tropo.redirect(ID)
        tropo.reject(ID)
        tropo.startRecording(URL)
        tropo.stopRecording()
        tropo.transfer(TO)

        tropo.message("Hello, World",
开发者ID:JustinDupree,项目名称:tropo-webapi-python,代码行数:33,代码来源:test.py

示例10: HttpResponse

# 需要导入模块: from tropo import Tropo [as 别名]
# 或者: from tropo.Tropo import hangup [as 别名]
                    return HttpResponse(j)
                except Exception, e:
                    logger.exception(e)
                    return HttpResponseServerError()

        # Must have received a message
        logger.debug("@@Got a text message")
        try:
            from_address = s['from']['id']
            text = s['initialText']

            logger.debug("@@Received message from %s: %s" % (from_address, text))

            # pass the message to RapidSMS
            incoming(backend_name, from_address, text)

            # Respond nicely to Tropo
            t = Tropo()
            t.hangup()
            logger.debug("@@responding to tropo with hangup")
            return HttpResponse(t.RenderJson())
        except Exception, e:
            logger.exception(e)
            logger.debug("@@responding to tropo with error")
            return HttpResponseServerError()
    else:
        # What?  We don't expect any GET to our URL because
        # our Tropo app should be a Web API app.
        logger.error("@@Unexpected GET to tropo URL")
        return HttpResponseServerError()
开发者ID:bauli2000,项目名称:rapidsms-tropo,代码行数:32,代码来源:views.py


注:本文中的tropo.Tropo.hangup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。