Example #1
0
    def send_responses(self, response_data):
        message_ids = [i['id'] for i in self.message.message_dicts]

        quick_reply_data = response_data['quick_reply']

        should_send_responses_at_once = len(quick_reply_data) != 0

        MyDB.send_responses(
            response_data['regular'],
            self.message.cluster_id,
            self.user.sender_id,
            self.user.id,
            'return_visit',
            should_send_responses_at_once=should_send_responses_at_once)

        print('\nSended regular response\n', response_data['regular'])

        if quick_reply_data:
            models.Response.save_response_data(self.user.id,
                                               self.message.cluster_id,
                                               quick_reply_data[0],
                                               [quick_reply_data[2]],
                                               has_sent=True)
            send_quick_replies(self.user.sender_id, quick_reply_data[0],
                               quick_reply_data[1], quick_reply_data[2])

            print('\nSended quick replies\n', quick_reply_data)

        models.Message.change_message_status(message_ids)
Example #2
0
    def send_responses(self, response_data: Dict[str, List[str]], message_types: List[str]):
        try:
            message_ids = [i['id'] for i in self.message.message_dicts]

            is_session_active = self.therapy_session.status == SessionStatus.active.value
            exists_new_message = models.Message.has_user_sent_new_message(self.user.id, message_ids)
            is_user_suicidal = self.user.status == UserStatus.SUICIDE_IN_SESSION.value

            if not is_user_suicidal and is_session_active and exists_new_message:
                self.__restart_msg_processing(message_ids)
                return

            quick_reply_data = response_data['quick_reply']

            should_send_responses_at_once = len(quick_reply_data) != 0
            MyDB.send_responses(response_data['regular'], self.message.cluster_id, self.user.sender_id,
                                self.user.id, message_types,
                                should_send_responses_at_once=should_send_responses_at_once)

            print('\nSended regular response\n', response_data['regular'])

            if quick_reply_data:
                models.Response.save_response_data(self.user.id, self.message.cluster_id, quick_reply_data[0],
                                                   [quick_reply_data[2]], has_sent=True)

                send_quick_replies(self.user.sender_id, quick_reply_data[0], quick_reply_data[1],
                                   quick_reply_data[2])
                print('\nSended quick replies\n', quick_reply_data)
        except:
            logging.exception('')
Example #3
0
 def send_responses(self, response_data, user_id):
     try:
         sender_id = models.User.find_sender_id_by_id(user_id)
         MyDB.send_responses(response_data['regular'],
                             None,
                             sender_id,
                             user_id,
                             MessageType.ASK_FEED_BACK.value,
                             should_send_responses_at_once=True)
     except:
         logging.exception('')
Example #4
0
    def send_responses(self, response_data):
        try:
            message_ids = [i['id'] for i in self.message.message_dicts]

            MyDB.send_responses(response_data['regular'],
                                self.message.cluster_id,
                                self.user.sender_id,
                                self.user.id,
                                'admin',
                                should_send_responses_at_once=True)

            print('\nSended regular response\n', response_data['regular'])

            models.Message.change_message_status(message_ids)
        except:
            logging.exception('')
Example #5
0
    def __send_remind(cls, remind_users):
        for user_id in remind_users:
            user = User(user_id)
            MyDB.send_responses(StringConstant.remind_text.value, None,
                                user.sender_id, user_id, ['REMIND'])
            send_quick_replies(user.sender_id,
                               StringConstant.remind_quick_replies_title.value,
                               StringConstant.remind_quick_replies.value,
                               "REMIND_ASK_MOOD")

            latest_session_id = models.Session.find_latest_id_by_user_id(
                user_id)
            models.Session.update_status(latest_session_id,
                                         SessionStatus.ended.value)

            models.Remind.register_remind(user_id)
Example #6
0
def send_response_regularly():
    try:
        responses = get_unsent_responses()

        if len(responses) == 0:
            return None

        print("\nSending response_generator >>>>>")
        pprint(responses)

        for i in responses:
            send_message(sender_id=i[2], content=i[1])
            send_typing_on(sender_id=i[2])

        user_ids_list = set(map(tuple, [[i[0], i[2]] for i in responses]))

        MyDB.control_typing_indicator(user_ids_list)
    except:
        logging.exception('')