示例#1
0
    def __send_responses_with_delay(cls, contents, sender_id, user_id,
                                    cluster_id, response_type):
        try:
            delay = 0

            for idx, content in enumerate(contents):
                try:
                    if idx == 0:
                        send_message(sender_id, content)
                        models.Response.save_response_data(user_id,
                                                           cluster_id,
                                                           content,
                                                           response_type,
                                                           has_sent=True)
                    else:
                        delay = cls.__update_delay(delay, len(content))
                        models.Response.save_response_data(user_id,
                                                           cluster_id,
                                                           content,
                                                           response_type,
                                                           has_sent=False,
                                                           delay=delay)

                    send_typing_on(sender_id)
                except:
                    logging.exception('')
        except:
            logging.exception('')
示例#2
0
    def __call__(self, message_dicts: List[Dict[str, str]], sender_id, from_preprocessor=True):
        try:
            if from_preprocessor:
                message_dicts = self.__convert_attachment(message_dicts)

                message_dicts = self.__normalize_apostrophe(message_dicts)

                w_toks = WordFormatter.MsgDict2WToks(message_dicts)
            else:
                w_toks = message_dicts

            print('\nword_tokenized\n', w_toks)

            normalized_w_toks = self.normalize_message_by_w_toks(w_toks)

            send_typing_on(sender_id)

            # make original_df with sidx, widx, word, pos tag
            df = OriginalDFGenerator.create_original_df_by_w_toks(normalized_w_toks)

            df = self.normalize_message_by_df(df)

            return df
        except:
            logging.exception('')
            return None
示例#3
0
    def reply(self):
        send_typing_on(self.user.sender_id)

        response_data = self.create_response()

        self.send_responses(response_data)

        send_typing_off(self.user.sender_id)
示例#4
0
    def reply(self):
        try:
            send_typing_on(self.user.sender_id)

            response_data = self.create_response()

            self.send_responses(response_data)

            send_typing_off(self.user.sender_id)
        except:
            logging.exception('')
示例#5
0
    def reply(self):
        try:
            if self.therapy_session.status == SessionStatus.prepared.value:
                self.therapy_session.activate()

            send_typing_on(self.user.sender_id)

            self.message = self.preprocess_message()

            send_typing_on(self.user.sender_id)

            UsersFeeling.save_feelings(self.message.text_kw_df, self.user.id)

            message_types = self.analyze_message_type()

            send_typing_on(self.user.sender_id)

            response_data = self.create_response(message_types)

            send_typing_on(self.user.sender_id)

            self.send_responses(response_data, message_types)
            print("\nBot finished sending responses")
        except:
            logging.exception('')
            print(
                '\n*********************** Bot couldnt make responses ***********************'
            )
示例#6
0
文件: cct_bot.py 项目: hirokig/CBT
    def reply(self):
        """
        Here bot sends typing indicator on constantly because nlp processing takes long.
        :return:
        """
        if self.therapy_session.status == SessionStatus.prepared.value:
            self.therapy_session.activate()

        send_typing_on(self.user.sender_id)

        self.message = self.__preprocess_message()

        send_typing_on(self.user.sender_id)

        UsersFeeling.save_feelings(self.message.text_kw_df, self.user.id)

        message_types = self.__analyze_message_type()

        send_typing_on(self.user.sender_id)

        response_data = self.create_response(message_types)

        send_typing_on(self.user.sender_id)

        self.send_responses(response_data, message_types)
        print("\nBot finished sending responses")
示例#7
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('')