def description(bot, update):
    """Gets brief description of the issue"""
    send_to_backlog_group(bot, update)
    user = update.message.from_user
    main.ISSUE_DICT['issue'] = update.message.text
    main.ISSUE_DICT['time_open'] = dt.now().strftime("%d.%m.%y %H:%M:%S")
    main.ISSUES_QUEUE.put(main.ISSUE_DICT)

    main.logger.info("Issue of {} submitted. "
                     "Given issue: {}".format(user.first_name,
                                              update.message.text))
    update.message.reply_text(
        'An expert user will help you shortly. Thanks for'
        ' your patience!\nReference number for the '
        'issue: {}'.format(main.ISSUE_DICT['issue_id']))

    # Sends the issue to the experts' group
    bot.send_message(
        chat_id=main.EXPERT_GROUP_CHAT_ID,
        text=("{} has requested help! If you're available to "
              "assist, please reply /accept\n"
              "*Note:* if you accept an issue (that has not been "
              "taken already), ExpertEaseBot will "
              "send you a private message with further details.".format(
                  user.first_name)),
        parse_mode=telegram.ParseMode.MARKDOWN)
    main.logger.info(
        "The issue of user {} has been sent to experts group.".format(
            user.first_name))
    return ConversationHandler.END
Esempio n. 2
0
def non_link_from_expert(bot, update):
    backlog.send_to_backlog_group(bot, update)
    if not main.check_if_has_open_issue(update):
        return ConversationHandler.END
    update.message.reply_text("This is not a valid link to a video. Try "
                              "sending in the following format:\n"
                              "https://www.useloom.com/share/example")
    return ConversationHandler.END
Esempio n. 3
0
def send_msg_to_group_command(bot, update, args):
    backlog.send_to_backlog_group(bot, update)
    message = " ".join(args)
    main.logger.info(
        "Admin {} has sent a message to experts' group: {}".format(
            update.message.from_user.first_name, message))
    bot.send_message(chat_id=main.EXPERT_GROUP_CHAT_ID, text=message)
    return ConversationHandler.END
Esempio n. 4
0
def cancel(bot, update):
    backlog.send_to_backlog_group(bot, update)
    user = update.message.from_user
    global ISSUE_DICT
    main.logger.info("User {} canceled submission of issue {}.".format(
        user.first_name, ISSUE_DICT['issue_id']))
    update.message.reply_text('Bye!', reply_markup=ReplyKeyboardRemove())

    # Deleting the issue.
    ISSUE_DICT = dict()
    main.BLOCKED_USERS_UNTIL_FEEDBACK.remove(update.message.chat_id)

    return ConversationHandler.END
def start(bot, update):
    """Initiated by user"""
    send_to_backlog_group(bot, update)
    if update.message.chat_id in main.BLOCKED_USERS_UNTIL_FEEDBACK:
        main.logger.info(
            "User {} tried to send another issue while a feedback "
            "for previous issue was not submitted.".format(
                update.message.from_user.first_name))
        text = "New issues cannot be submitted right now.\n"
        try:
            issue = main.ISSUES_WAITING_FOR_FEEDBACK[update.message.chat_id]
            text += "Please reply 'Yes' if the assistance you " \
                    "received was helpful and 'No' otherwise."
        except KeyError:
            text += "Please wait for an expert to respond to your " \
                    "previous issue."

        update.message.reply_text(text)
        return ConversationHandler.END

    # global ISSUE_ID
    main.ISSUE_ID += 1

    user = update.message.from_user
    main.ISSUE_DICT = {
        'name': user.first_name,
        'chat_id': update.message.chat_id,
        'issue_id': main.ISSUE_ID
    }
    main.BLOCKED_USERS_UNTIL_FEEDBACK.append(main.ISSUE_DICT['chat_id'])

    main.logger.info(
        "A new user has connected. First name: {}, last name: {}, "
        "username: {}. Assigned issue ID: {}".format(user.first_name,
                                                     user.last_name,
                                                     user.username,
                                                     main.ISSUE_ID))
    reply_keyboard = [['Video', 'Text']]

    update.message.reply_text(
        'Hi! We are Expert-Ease, and we will find you an expert that can '
        'help you with whatever it is you need on Wordpress.\n'
        'Do you want to send us a description of the issue using '
        'video or text?',
        reply_markup=ReplyKeyboardMarkup(reply_keyboard,
                                         one_time_keyboard=True))

    return main.METHOD
Esempio n. 6
0
def expert_accepts(bot, update):
    backlog.send_to_backlog_group(bot, update)
    expert = update.message.from_user
    if main.ISSUES_QUEUE.empty():  # No users to assist
        bot.send_message(chat_id=main.EXPERT_GROUP_CHAT_ID,
                         text="There is no user that needs assistance"
                         " at the moment, but thank you!")
        main.logger.info(
            "Expert {} wished to assist, but queue is empty.".format(
                expert.first_name))
        return ConversationHandler.END

    # Updating expert's current issue
    current_issue = main.ISSUES_QUEUE.get()
    current_issue['expert_name'] = expert.first_name
    current_issue['expert_chat_id'] = expert.id
    current_issue['time_expert_accepts'] = dt.now().strftime(
        "%d.%m.%y %H:%M:%S")
    main.EXPERT_ISSUES_DICT[expert.id] = current_issue

    global ISSUE_DICT
    ISSUE_DICT = dict()

    # Notifying the expert that he's taking an issue
    bot.send_message(chat_id=expert.id,
                     text=("Thank you {}! You will help {} on issue {}.\n"
                           "After making the Loom video, please share the "
                           "link here. Thanks!\n"
                           "The issue, as submitted: {}".format(
                               expert.first_name, current_issue['name'],
                               current_issue['issue_id'],
                               current_issue['issue'])))
    main.logger.info("Expert {} has received issue {}.".format(
        expert.first_name, current_issue['issue_id']))

    # Updating the user that an expert is connected to him
    bot.send_message(
        chat_id=current_issue['chat_id'],
        text="Hey {}! Our expert {} is making a personalized video "
        "response just for you, as we speak!".format(current_issue['name'],
                                                     expert.first_name))
    main.logger.info(
        "User {} has been updated that {} has taken the issue.".format(
            current_issue['name'], expert.first_name))
    return ConversationHandler.END
def method(bot, update):
    """Supposed to get 'video' or 'text' methods from user"""
    send_to_backlog_group(bot, update)
    user = update.message.from_user
    main.logger.info("Method chosen by {}: {}".format(user.first_name,
                                                      update.message.text))
    text = 'Great! Please send us a '

    if update.message.text == 'Video':
        text += 'link to a video (possibly with sound) describing the issue.' \
                ' Please shoot the video using the extension Loom, which will ' \
                'best demonstrate the issue.'
        main.ISSUE_DICT['method'] = 'video'
    elif update.message.text == 'Text':
        text += 'detailed walkthrough of the issue.'
        main.ISSUE_DICT['method'] = 'text'

    update.message.reply_text(text, reply_markup=ReplyKeyboardRemove())
    return main.DESCRIPTION
Esempio n. 8
0
def collect_message_from_expert_command(bot, update, args):
    backlog.send_to_backlog_group(bot, update)
    message = " ".join(args)
    main.logger.info(
        "Expert {} has requested to use the following message: {}".format(
            update.message.from_user.first_name, message))
    main.dbCur.execute("""DELETE FROM experts WHERE expertchatid = %s;""",
                       (str(update.message.chat_id), ))
    main.dbCur.execute(
        """INSERT INTO experts VALUES (%s, %s, %s);""",
        (update.message.from_user.first_name, update.message.chat_id, message))
    main.dbConn.commit()
    update.message.reply_text("Thank you {}! The message will be saved in "
                              "our database and sent to users you help in "
                              "the future.\n"
                              "*Note*: at the moment, we allow messages with "
                              "up to 100 characters.".format(
                                  update.message.from_user.first_name),
                              parse_mode=telegram.ParseMode.MARKDOWN)
    return ConversationHandler.END
Esempio n. 9
0
def link_from_expert(bot, update):
    backlog.send_to_backlog_group(bot, update)
    if not main.check_if_has_open_issue(update):
        return ConversationHandler.END

    # Check if this is a Loom video:
    if "useloom.com" not in update.message.text.lower():
        update.message.reply_text("This is indeed a link, but not to a Loom "
                                  "video. Please send one!")
        return ConversationHandler.END

    issue = main.EXPERT_ISSUES_DICT[update.message.chat_id]
    issue['time_solution_submitted'] = dt.now().strftime("%d.%m.%y %H:%M:%S")
    issue['full_solution'] = update.message.text
    expert = update.message.from_user
    bot.send_message(chat_id=issue['chat_id'],
                     text="Our expert {} is finished, and sent you the "
                     "following link on issue {}:\n"
                     "{}".format(expert.first_name, issue['issue_id'],
                                 issue['full_solution']))

    # Thanks to expert
    update.message.reply_text("Thank you for helping {} out!".format(
        issue['name']))

    main.logger.info(
        "User {} has received link from expert {}. Link: {}".format(
            issue['name'], expert.first_name, update.message.text))
    del main.EXPERT_ISSUES_DICT[update.message.chat_id]

    # Feedback phase
    main.ISSUES_WAITING_FOR_FEEDBACK[issue['chat_id']] = issue
    time.sleep(30)
    reply_keyboard = [['Yes', 'No']]
    bot.send_message(chat_id=issue['chat_id'],
                     text="Was the help from {} helpful?".format(
                         expert.first_name),
                     reply_markup=ReplyKeyboardMarkup(reply_keyboard,
                                                      one_time_keyboard=True))
    return ConversationHandler.END
Esempio n. 10
0
def user_sent_feedback(bot, update):
    backlog.send_to_backlog_group(bot, update)
    user = update.message.from_user
    if update.message.chat_id not in main.BLOCKED_USERS_UNTIL_FEEDBACK:
        return ConversationHandler.END

    main.logger.info("User {} has sent feedback: {}.".format(
        user.first_name, update.message.text))
    issue = main.ISSUES_WAITING_FOR_FEEDBACK[update.message.chat_id]

    text = 'Thank you for sending feedback!\n'

    # When replying, we also need to return the expert's message if exists
    main.dbCur.execute(
        """SELECT message FROM experts WHERE expertchatid = %s;""",
        (str(issue['expert_chat_id']), ))
    fetched = main.dbCur.fetchone()
    if fetched is not None:
        expert_message = fetched['message']
        text += expert_message + "\n\n"

    text += 'If you wish to send another issue, click /start.'
    update.message.reply_text(text, reply_markup=ReplyKeyboardRemove())

    # Now we can enter all data into the database
    main.dbCur.execute(
        """
        INSERT INTO issues VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 
        %s, %s);
        """, (issue['issue_id'], issue['name'], issue['chat_id'],
              issue['expert_name'], issue['expert_chat_id'], issue['method'],
              issue['time_open'], issue['time_expert_accepts'],
              issue['time_solution_submitted'], update.message.text,
              issue['issue'], issue['full_solution']))
    main.dbConn.commit()

    main.BLOCKED_USERS_UNTIL_FEEDBACK.remove(update.message.chat_id)
    del main.ISSUES_WAITING_FOR_FEEDBACK[update.message.chat_id]
    return ConversationHandler.END
Esempio n. 11
0
def current_issues_command(bot, update):
    backlog.send_to_backlog_group(bot, update)
    main.logger.info("Admin {} has asked for current issues.".format(
        update.message.from_user.first_name))

    if main.ISSUES_QUEUE.qsize() == 0:
        text = "There are no issues waiting for experts."
    else:
        text = "There are currently {} issues waiting for experts."\
            .format(main.ISSUES_QUEUE.qsize())

    text += "\n"
    if not main.EXPERT_ISSUES_DICT:
        text += "No issues are taken care of by experts at the moment.\n"
    else:
        text += "Those are the current issues that are taken care of " \
               "by experts right now:\n"
        for expert, issue in main.EXPERT_ISSUES_DICT.items():
            text += "Issue {} of user {} is taken care of by expert {}.\n"\
                .format(issue['issue_id'], issue['name'], issue['expert_name'])

    bot.send_message(chat_id=update.message.chat_id, text=text)
    return ConversationHandler.END