예제 #1
0
파일: bot.py 프로젝트: Olamyy/Norman
    def post(self):
        data = request.get_data()
        request_type = get_request_type(data)
        print(data)

        if request_type == 'postback':
            for recipient_id, postback_payload, referral_load in postback_events(
                    data):
                print(recipient_id)
                if referral_load:
                    self.normanuser.update_ref_id(referral_load, recipient_id)
                    payloadhandler = PayloadConversationHandler(
                        registered=True, recipient_id=recipient_id)
                    return payloadhandler.handleconversation(postback_payload)
                payloadhandler = PayloadConversationHandler(
                    registered=False, recipient_id=recipient_id)
                return payloadhandler.handleconversation(postback_payload)
            return response.response_ok('success')

        elif request_type == "message":
            print('Got a me')
            for recipient_id, message in messaging_events(data):
                print(message, recipient_id)
                if not message:
                    return response.response_ok('Success')
                message = decode_data(message.get('data'))
                processor = Processor(sentence=message,
                                      recipient_id=recipient_id)
                return processor.process()
            return response.response_ok('success')

        else:
            return response.response_ok('success')
예제 #2
0
파일: bot.py 프로젝트: Olamyy/Norman
    def post(self):
        data = request.get_data()
        request_type = get_request_type(data)
        print(data)

        if request_type == 'postback':
            for recipient_id, postback_payload, referral_load in postback_events(data):
                print(recipient_id)
                if referral_load:
                    self.normanuser.update_ref_id(referral_load, recipient_id)
                    payloadhandler = PayloadConversationHandler(registered=True, recipient_id=recipient_id)
                    return payloadhandler.handleconversation(postback_payload)
                payloadhandler = PayloadConversationHandler(registered=False, recipient_id=recipient_id)
                return payloadhandler.handleconversation(postback_payload)
            return response.response_ok('success')

        elif request_type == "message":
            print('Got a me')
            for recipient_id, message in messaging_events(data):
                print(message, recipient_id)
                if not message:
                    return response.response_ok('Success')
                message = decode_data(message.get('data'))
                processor = Processor(sentence=message, recipient_id=recipient_id)
                return processor.process()
            return response.response_ok('success')

        else:
            return response.response_ok('success')
예제 #3
0
 def good_to_go(self):
     print('i got to good help')
     message_text = "Awesome {0}".format(
         MessageConfig.EMOJI_DICT['HAPPY_SMILE'])
     self.send_message("text", message_text=message_text)
     response.response_ok('Success')
     return self.beyondGetStarted()
예제 #4
0
 def handle_help(self):
     print('i got to get help')
     message_text = MessageConfig.GET_HELP_MESSAGE.replace(
         '<username>', self.user_details['first_name'])
     quick_replies = [{
         "content_type": "text",
         "title": "Tell Me About You",
         "payload": "NORMAN_GET_STARTED_PAYLOAD"
     }, {
         "content_type": "text",
         "title": "Leave a Message",
         "payload": "NORMAN_LEAVE_MESSAGE"
     }, {
         "content_type": "text",
         "title": "Set Reminder",
         "payload": "NORMAN_SET_REMINDER"
     }, {
         "content_type": "text",
         "title": "Request Urgent Help",
         "payload": "NORMAN_REQUEST_URGENT_HELP"
     }, {
         "content_type": "text",
         "title": "Book an Appointment",
         "payload": "NORMAN_BOOK_APPOINTMENT"
     }]
     self.send_message("text",
                       message_text=message_text,
                       quick_replies=quick_replies)
     response.response_ok('Success')
     return response.response_ok('Success')
예제 #5
0
 def get_started_service_list(self):
     print('i got')
     # self.send_message("text", message_text="Here are the services we offer")
     self.send_template_message(template_type='list',
                                list_info=[
                                    ServiceListConfig.messaging,
                                    ServiceListConfig.reminder,
                                    ServiceListConfig.emergency,
                                    ServiceListConfig.scheduling
                                ])
     message_text = MessageConfig.GET_ALL_SERVICE_LIST.replace(
         '<username>', self.user_details['first_name'])
     quick_replies = [{
         "content_type": "text",
         "title": "Nice",
         "payload": "GOOD_TO_GO"
     }, {
         "content_type": "text",
         "title": "I'm still confused",
         "payload": "NORMAN_GET_HELP"
     }]
     self.send_message("text",
                       message_text=message_text,
                       quick_replies=quick_replies)
     response.response_ok('Success')
     return response.response_ok('Success')
예제 #6
0
    def handle_api_ai_message(self, message):
        test = AI()
        test.parse(message)
        if test.match_successful:
            reply = test.text
            return self.send_message('text', message_text=reply)
        else:
            reply = "Sure, give me a few seconds... B-)"
            self.send_message('text', message_text=reply)
            quick_replies = [{
                "content_type": "text",
                "title": "Drug Use Reminder",
                "payload": "GOOD_TO_GO_FREE"
            }, {
                "content_type": "text",
                "title": "Emergency Service",
                "payload": "GET_NEARBY_HOSPITAL"
            }, {
                "content_type": "text",
                "title": "Drug Purchase",
                "payload": "GET_NEARBY_HOSPITAL"
            }]
            return self.send_message(
                'text',
                message_text="Sorry I didn't get that, let's try again",
                quick_replies=quick_replies)

        return response.response_ok('Success')
예제 #7
0
 def handle_first_time_temp_user(self):
     print('i got to ftu')
     for statement in MessageConfig.FIRST_TIME_TEMP_USER:
         self.send_message('text', statement)
     text = "While you can enjoy some of my services as a free user," + \
            "to enjoy the best of my features, you need to be registered to an hospital."
     self.send_message("text", message_text=text)
     quick_replies = [{
         "content_type": "text",
         "title": "Continue as a free user",
         "payload": "GOOD_TO_GO_FREE"
     }, {
         "content_type": "text",
         "title": "Inform your hospital about Norman",
         "payload": "GET_NEARBY_HOSPITAL"
     }, {
         "content_type": "text",
         "title": "View registered hospitals",
         "payload": "GET_NEARBY_HOSPITAL"
     }]
     second_text = "As a free user, you can go on and"
     self.send_message("text",
                       message_text=second_text,
                       quick_replies=quick_replies)
     return response.response_ok('Success')
예제 #8
0
 def handle_get_started_meaning(self):
     message_text = MessageConfig.GET_STARTED_MEANING
     quick_replies = [{
         "content_type": "text",
         "title": "How do you do that?",
         "payload": "NORMAN_GET_STARTED_HOW"
     }, {
         "content_type": "text",
         "title": "What services do you offer?",
         "payload": "NORMAN_GET_ALL_SERVICE_LIST"
     }]
     self.send_message("text",
                       message_text=message_text,
                       quick_replies=quick_replies)
     response.response_ok('Success')
     return response.response_ok('Success')
예제 #9
0
파일: sendAPI.py 프로젝트: Olamyy/Norman
 def show_typing(recipient_id, action='typing_on'):
     r = requests.post("https://graph.facebook.com/v2.6/me/messages",
                       params={"access_token": settings.FBConfig.FACEBOOK_SECRET_KEY},
                       data=json.dumps({
                           "recipient": {"id": recipient_id},
                           "sender_action": action
                       }),
                       headers={'Content-type': 'application/json'})
     if r.status_code != requests.codes.ok:
         return response.response_ok('Success')
예제 #10
0
 def handle_get_started_how(self):
     print('i got st ho')
     message_text = MessageConfig.GET_STARTED_HOW
     quick_replies = [{
         "content_type": "text",
         "title": "What services do you offer?",
         "payload": "NORMAN_GET_ALL_SERVICE_LIST"
     }, {
         "content_type": "text",
         "title": "Nice",
         "payload": "GOOD_TO_GO"
     }, {
         "content_type": "text",
         "title": "I'm still confused",
         "payload": "NORMAN_GET_HELP"
     }]
     self.send_message("text",
                       message_text=message_text,
                       quick_replies=quick_replies)
     response.response_ok('Success')
     return response.response_ok('Success')
예제 #11
0
 def show_typing(recipient_id, action='typing_on'):
     r = requests.post(
         "https://graph.facebook.com/v2.6/me/messages",
         params={"access_token": settings.FBConfig.FACEBOOK_SECRET_KEY},
         data=json.dumps({
             "recipient": {
                 "id": recipient_id
             },
             "sender_action": action
         }),
         headers={'Content-type': 'application/json'})
     if r.status_code != requests.codes.ok:
         return response.response_ok('Success')
예제 #12
0
 def beyondGetStarted(self):
     print('i got to beyond')
     if self.current_user.is_from_ref_id:
         message_text = MessageConfig.COMING_FROM_HOSPITAL
         self.show_typing('typing_on')
         self.show_typing('typing_off')
         self.send_message('text', message_text)
         self.show_typing('typing_on')
         self.show_typing('typing_off')
         self.send_message('text', MessageConfig.TIME_TO_SET_UP)
         return response.response_ok('Success')
     else:
         return self.handle_first_time_temp_user()
예제 #13
0
 def handle_messaging_service(self):
     message_text = "Who would you like to leave a message for?"
     self.send_message("text", message_text=message_text)
     """
         Hey lekan my laptop is about to go off,
         @Todo: Here is what i am trying to do here
         1. Create a boolean field 'awaiting_message' in the user model
         1. At this point, update field to true
         2. When  a new message comes in from the same user, check if the user's
           awaiting_message is true
         3. take the message as continuation of the previous message
     """
     MessagingService.add_previous_message()
     return response.response_ok('Success')
예제 #14
0
    def handle_awaited_message(self, message_type='messaging_service'):
        if message_type == 'messaging_service':
            if 'users_last_message was a response to who?':
                message_text = "What message would you like to leave a message?"
                self.send_message("text", message_text=message_text)
            elif 'users_last_message_was a response to what':
                MessagingService().send_notification(who='previous_message',
                                                     what='this_message')
                message_text = "Your message was successfully sent"
                return self.send_message("text", message_text=message_text)
        else:
            message_text = "Sure, give me a few seconds... B-)"
            return self.send_message("text", message_text=message_text)

        return response.response_ok('Success')
예제 #15
0
 def handle_get_started(self):
     print('i got to started')
     self.temp_user = TempUser(self.recipient_id)
     message_text = MessageConfig.GET_STARTED_MESSAGE.replace(
         '<username>', self.user_details['first_name'])
     quick_replies = [
         {
             "content_type": "text",
             "title": "What does that mean?",
             "payload": "NORMAN_GET_STARTED_MEANING"
         },
         {
             "content_type": "text",
             "title": "How do you do that?",
             "payload": "NORMAN_GET_STARTED_HOW"
         },
     ]
     return self.send_message("text",
                              message_text=message_text,
                              quick_replies=quick_replies)
     return response.response_ok('Success')
예제 #16
0
파일: services.py 프로젝트: Olamyy/Norman
 def getResponse(self):
     if self.user.has_hospital:
         return response.response_ok('VBJKBV')
     else:
         return response.response_ok('VBJKBV')