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_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)