def get_question_id_message(self, message): if message.is_replier_message: question_replier = QuestionReplier.get_by_message_id( self._session, message.id) question = Question.get_question_id(self._session, question_replier.question_id) else: question = Question.get_question(self._session, message.id) return question.id
def reply_question(self, event): """Handle messages that are sent to existing thread""" message = Message.get_message(self._session, event.thread_id, event.user) if self._is_resolved(message): self.send_closed_message(event, message) return if message.is_replier_message: question_replier = QuestionReplier.get_by_message_id( self._session, message_id=message.id) question = Question.get_question_id( self._session, question_id=question_replier.question_id) if not self.is_correct_replier(event.bot, message): return channel_id, message_id, replier_question_id = self.get_user_info_to_reply( message) self.delete_previous_scheduled_messages(event.bot, event.channel, replier_question_id, 3) event.bot.delete_message_in_history( event.channel, event.thread_id, [ WANT_ANSWER_QUESTION, WANT_CONTINUE_RESPONDING, M_ASKS_REPLIER_CLOSE_QUESTION ]) attachments_type = '' else: question = Question.get_question(self._session, message_id=message.id) channel_id, message_id, _ = self.get_expert_info_to_reply(message) attachments_type = ATTACHMENTS_keep_answering_or_not event.bot.delete_message_in_history(event.channel, event.thread_id, [QUESTION_ANSWERED]) message_txt = WANT_CONTINUE_RESPONDING # if this question has continous messages if question.new_message_user == 1: # add some text as alert in order to avoid this behaviour again event.bot.post_message( channel_id, USER_ALERT + question.message_text + '\n\n' + USER_ALERT_2, message_id, attachments_type) self._session.query(Question).filter_by(id=question.id).update( {'new_message_user': 0}) event.bot.post_message(channel_id, event.message_text, message_id) if attachments_type != '': event.bot.post_message(channel_id, message_txt, message_id, attachments_type) self.handle_scheduled_message(event, message)
def save_message_history(self, bot, question_replier_id, next_level=False): """Save history of messages to database just when it will go to the next level. :type question_replier_id: int :type next_level: bool :rtype: str """ question_id = self._session.query(QuestionReplier).filter( QuestionReplier.id == question_replier_id).first().question_id question = Question.get_question_id(self._session, question_id) original_message = question.message slack_response = bot.get_history(original_message.slack_user_id, original_message.slack_message_id) history_list = self.handle_thread_messages(slack_response) history_text = self.handle_history(history_list, next_level=next_level) if not next_level: save_message = HistoryMessages(question_id=question_id, history_text=history_text) self._session.add(save_message) return history_text