Example #1
0
def main():
    # get new message from queue
    events = queue.get_queue('IngressQueue')
    for event in events:
        d = event.get_body()
        d = json.loads(d)
        uid = d['from']
        message = d['message']

        # lookup user

        try:
            curr_user = users.get_user(uid)
        except ItemNotFound:
            curr_user = users.EndUser(uid)
            curr_user.write()

        print curr_user
        print curr_user.last_question
        # process question
        if curr_user.last_question is None:
            send_first_question(uid, event, curr_user)
            break
        else:
            question = questions.get_question(curr_user.last_question)

        for q, v in question.answers.iteritems():

            v_json = json.loads(v)

            print v[1].lower()
            if message.lower() == v_json.values()[0].lower():
                print "response match found"
                next_question_id = json.loads(question.child_questions[q])
                print next_question_id.values()[0]
                # create response message & publish to queue
                next_question = questions.get_question(
                    next_question_id.values()[0])
                queue.put_queue(
                    json.dumps({
                        'to': uid,
                        'message': next_question.qstring
                    }), 'EgressQueue')
                queue.delete_from_queue(event, 'IngressQueue')
            else:
                print "unable to find a response match"
                # invalid response
                queue.put_queue(
                    json.dumps({
                        'to': uid,
                        'message': "Sorry, that wasn't a valid response"
                    }), 'EgressQueue')
                queue.delete_from_queue(event, 'IngressQueue')
                break
Example #2
0
def main():
    events = queue.get_queue(egressQueue)
    print 'Processing EgressQueue...'
    for event in events:
        d = event.get_body()
        d = json.loads(d)

        client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

        client.messages.create(
            to=d['to'],
            from_=send_sms_from,
            body=d['message'],
        )
        queue.delete_from_queue(event, egressQueue)
Example #3
0
def main():
    events = queue.get_queue(egressQueue)
    print 'Processing EgressQueue...'
    for event in events:
        d = event.get_body()
        d = json.loads(d)


        client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

        client.messages.create(
                to= d['to'],
                from_= send_sms_from,
                body= d['message'],
        )
        queue.delete_from_queue(event,egressQueue)
def main():
    # get new message from queue
    events = queue.get_queue('IngressQueue')
    for event in events:
        d = event.get_body()
        d = json.loads(d)
        uid = d['from']
        message = d['message']

        # lookup user

        try:
            curr_user = users.get_user(uid)
        except ItemNotFound:
            curr_user = users.EndUser(uid)
            curr_user.write()

        print curr_user
        print curr_user.last_question
        # process question
        if curr_user.last_question is None:
            send_first_question(uid, event, curr_user)
            break
        else:
            question = questions.get_question(curr_user.last_question)

        for q, v in question.answers.iteritems():

            v_json = json.loads(v)

            print v[1].lower()
            if message.lower() == v_json.values()[0].lower():
                print "response match found"
                next_question_id = json.loads(question.child_questions[q])
                print next_question_id.values()[0]
                # create response message & publish to queue
                next_question = questions.get_question(next_question_id.values()[0])
                queue.put_queue(json.dumps({'to': uid,
                                            'message': next_question.qstring}), 'EgressQueue')
                queue.delete_from_queue(event, 'IngressQueue')
            else:
                print "unable to find a response match"
                # invalid response
                queue.put_queue(json.dumps({'to': uid,
                 'message': "Sorry, that wasn't a valid response"}), 'EgressQueue')
                queue.delete_from_queue(event, 'IngressQueue')
                break
Example #5
0
 def post(self, *args, **kwargs):
     data = parse_xml(self.request.body)
     if data.MsgType != 'voice':
         return
     q = get_queue()
     q.enqueue(download_media, media_id=data.MediaId, media_format=data.Format)
     msg = '''
     <xml>
     <ToUserName><![CDATA[{}]]></ToUserName>
     <FromUserName><![CDATA[{}]]></FromUserName>
     <CreateTime>{}</CreateTime>
     <MsgType><![CDATA[text]]></MsgType>
     <Content><![CDATA[will play]]></Content>
     </xml>
     '''.format(data.FromUserName, data.ToUserName, int(time.time()))
     self.set_header('Content-Type', 'application/xml')
     self.write(msg)
Example #6
0
def view_queue(request):
    return queue.get_queue()