Exemple #1
0
def get_account_info(account_id):
    """
    Get account information.

        reference
            - `Common Message Property <https://developers.worksmobile.com/kr/document/1006004/v1?lang=en>`_

    :param account_id: user account id.
    :return: name(user name), department(user department).
    """

    contacts_url = API_BO["contacts_url"]
    contacts_url = contacts_url.replace("_USER_ACCOUNT_ID_", account_id)

    headers = {
        "content-type": "application/x-www-form-urlencoded",
        "charset": "UTF-8",
        "consumerKey": OPEN_API["consumerKey"]
    }

    response = auth_get(contacts_url, headers=headers)
    if response.status_code != 200 or response.content is None:
        logging.error("get account info failed. url:%s text:%s body:%s",
                      contacts_url, response.text, response.content)
        raise Exception("get account info. http return code error.")
    tmp_req = json.loads(response.content)
    name = tmp_req.get("name", None)
    department = tmp_req.get("groupName", None)
    return name, department
def get_message_bot_from_remote():
    """
    get a message bot.

        reference
        - `Common Message Property <https://developers.worksmobile.com/jp/document/1005006?lang=en>`_

    :return: bot no
    """
    url = API_BO["bot"]
    response = auth_get(url, headers=headers())
    if response.status_code != 200:
        logging.info("register bot domain field: code:%d content:%s" % (
            response.status_code, response.text))
        return None

    content = json.loads(response.content)
    bots = content.get("bots", None)
    if bots is None:
        return None
    for bot in bots:
        name = bot.get("name", None)
        photo_url = bot.get("photoUrl", None)
        if name == BOT_NAME and photo_url == PHOTO_URL:
            return bot.get("botNo", None)
    return None
Exemple #3
0
def get_boards(title=None):
    """
    Create boards.

        reference
        - `Common Message Property <https://developers.worksmobile.com/jp/document/100180202?lang=en>`_

    :return: If boards have been created, the information of boards no will be returned;
            otherwise, none will be returned.
    """

    headers = {
        "content-type": "application/x-www-form-urlencoded",
        "charset": "UTF-8",
        "consumerKey": OPEN_API["consumerKey"]
    }

    boards_url = "%s?domainId=%d" % (API_BO["home"]["boards_url"], DOMAIN_ID)
    response = auth_get(boards_url, headers=headers)

    if response.status_code != 200 or response.content is None:
        logging.error("get boards failed. url:%s text:%s headers:%s ",
                    boards_url, response.text, json.dumps(headers))
        raise Exception("get boards. http return code error.")

    tmp_req = json.loads(response.content)
    boards = tmp_req.get("boards", None)
    if boards is None:
        return None

    board_nos = {}
    for board in boards:
        if board is not None:
            bord_title = board.get("title", None)
            bord_no = board.get("boardNo", None)
            if bord_title is not None and bord_no is not None:
                if title is not None and bord_title == title:
                    return bord_no
                board_nos[bord_title] =  bord_no
    if title is not None:
        return None
    return board_nos
Exemple #4
0
def get_rich_menus(name=None):
    """
    Get rich menus

        reference
        - `Common Message Property <https://developers.worksmobile.com/jp/document/100504004?lang=en>`_

    :return: rich menu list
    """
    headers = API_BO["headers"]
    headers["consumerKey"] = OPEN_API["consumerKey"]
    url = API_BO["rich_menu_url"]
    url = utils.replace_url_bot_no(url)

    logging.info("push message begin. url:%s", url)
    response = auth_get(url, headers=headers)
    if response.status_code != 200:
        logging.info("push message failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        return None

    logging.info("push message success. url:%s txt:%s body:%s", url,
                 response.text, response.content)

    tmp = json.loads(response.content)
    menus = tmp.get("richmenus", None)

    if menus is None:
        return None

    menu_ids = {}
    for menu in menus:
        if menu is not None:
            menu_name = menu.get("name", None)
            menu_id = menu.get("richMenuId", None)
            if menu_name is not None and menu_id is not None:
                if name is not None and menu_name == name:
                    return menu_id
                menu_ids[menu_name] = menu_id
        return menu_ids
    return None