Exemplo n.º 1
0
def remove_command(message):
    """
    /remove telegram command handler
    remove a case from the monitoring of the bot
    expect to get: case number
    next step: process_removecase_step
    """
    chat_id = str(message.chat.id)
    if not db.checkuserconfiguration(chat_id, db.dictdb):
        msg = bot.reply_to(
            message,
            "Proceed with /setup first, your account is not configured for id "
            + str(message.chat.id))
        logger.exception("db: " + repr(db.dictdb))
        return
    msg = bot.reply_to(
        message, """\
Specify the case number that you want to remove to monitoring (only the case number, not the URL)
""")
    bot.register_next_step_handler(msg, process_removecase_step)
Exemplo n.º 2
0
def notification_command(message):
    """
    /notification telegram command handler
    change the notifiaction Type for the current user
    expect to get: Type to be monitored (Associate, Customer or Both)
    next step: process_notification_step
    """
    chat_id = str(message.chat.id)
    if not db.checkuserconfiguration(chat_id, db.dictdb):
        msg = bot.reply_to(
            message,
            "Proceed with /setup first, your account is not configured for id "
            + str(message.chat.id))
        logger.exception("db: " + repr(db.dictdb))
        return
    msg = bot.reply_to(
        message, """\
This setting let you define which kind of update you want to receive.
Please pick between 'Both', 'Associate' and 'Customer' (default: Associate)
""")
    bot.register_next_step_handler(msg, process_notification_step)
Exemplo n.º 3
0
def casesiterator(chat_id_tuple):
    """
    Per user thread.
    The thread will be evaluated and for every case the parsing will be started
    """
    # the tuple must be splittted between the chat_id (user id in telegram) and the associated configuration dict
    chat_id, user_dict = chat_id_tuple
    logging.info("chatid: " + chat_id + ", parsing the following database\n" +
                 pformat(chat_id_tuple, depth=3))
    # verify that the user has a valid configuration
    if not db.checkuserconfiguration(chat_id, db.dictdb):
        logging.info("chatid: " + chat_id +
                     ", no valid configuration for the user")
    else:
        # if notify index is not set, assign the default value
        if not "notify" in user_dict:
            user_dict["notify"] = ["Associate"]
        # start the real parsing, checking if cases index is set
        # once a user add himself, the index is *not* set
        if "cases" in user_dict and user_dict["cases"] is not None:
            # extract the case number and the relative hash (xml dump) associated
            for casenumber, casedump in user_dict["cases"].items():
                logging.info(
                    "chatid: " + chat_id + ", case " + casenumber +
                    ", a valid configuration has been found. The case parsing is going to be executed."
                )
                # case is an hash, the key is the case number, the value is an hash.
                # the hash has None value once added, the case xml afterward
                # parsecase function will be called for every case
                user_dict["cases"][casenumber] = parsecase(
                    chat_id, casenumber, casedump, user_dict["credentials"],
                    user_dict["notify"])
        else:
            logging.info("chatid: " + chat_id +
                         ", no cases hash has been found for the user")

    # always return a value, which can be the original one or the modified one
    return str(chat_id), user_dict
Exemplo n.º 4
0
def listcase_command(message):
    """
    /list telegram command handler
    list the cases monitored by the bot
    expect to get: nothing
    next step: nothing
    """
    chat_id = str(message.chat.id)
    if not db.checkuserconfiguration(chat_id, db.dictdb):
        msg = bot.reply_to(
            message,
            "Proceed with /setup first, your account is not configured for id "
            + str(message.chat.id))
        logger.exception("db: " + repr(db.dictdb))
        return
    if not "cases" in db.dictdb[chat_id] or len(
            db.dictdb[chat_id]["cases"]) == 0:
        msg = bot.reply_to(message, "No cases are monitored, add it via /add")
        return
    cases = "\n".join(db.dictdb[chat_id]["cases"])
    msg = bot.reply_to(
        message,
        "The following cases are monitored by the tool for you:\n" + cases)