def replace_url_bot_no(url):
    bot_no = get_value("bot_no", None)
    if bot_no is None:
        LOGGER.info("internal error. bot no is None")
        raise HTTPError(500, "internal error. bot no is None")

    url = url.replace("_BOT_NO_", bot_no)
    return url
Пример #2
0
def create_schedule(current, end, begin, account_id, title):
    """
    create schedule.

        reference
        - https://developers.worksmobile.com/jp/document/100702703?lang=en

    :return: schedule id.
    """

    uid = str(uuid.uuid4()) + account_id
    schedule_data = make_icalendar_data(uid, title, current, end, begin,
                                        account_id, True)
    body = {"ical": schedule_data}

    calendar_id = get_value(API_BO["calendar"]["name"], None)
    if calendar_id is None:
        LOGGER.error("get calendar from cached failed.")
        raise HTTPError(500, "internal error. get calendar is failed.")

    headers = create_headers()
    url = API_BO["calendar"]["create_schedule_url"]
    url = url.replace("_ACCOUNT_ID_", ADMIN_ACCOUNT)
    url = url.replace("_CALENDAR_ID_", calendar_id)

    print(url)

    response = auth_post(url, data=json.dumps(body), headers=headers)
    if response.status_code != 200:
        LOGGER.error("create schedules failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500,
                        "internal error. create schedule http code error.")

    tmp_req = json.loads(response.content)
    if tmp_req["result"] != "success":
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. http response error.")

    LOGGER.info("create schedule. url:%s text:%s body:%s", url, response.text,
                response.content)

    return_value = tmp_req.get("returnValue", None)
    if return_value is None:
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. create schedule content error.")

    schedule_uid = return_value.get("icalUid", None)
    if schedule_uid is None:
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. create schedule content error.")
    return schedule_uid
def sign(account_id):
    """
    Set up rich menu for chat with users.
    Check also: attendance_management_bot/model/data.py

        reference
        - https://developers.worksmobile.com/jp/document/1005040?lang=en

    :param account_id: user account id
    """
    if account_id is None:
        LOGGER.error("account_id is None.")
        return False
    rich_menu_id = get_value(DEFAULT_LANG, None)
    if rich_menu_id is None:
        LOGGER.error("get rich_menu_id failed.")
        raise Exception("get rich_menu_id failed.")

    return set_user_specific_rich_menu(rich_menu_id, account_id)
def get_token():
    return get_value("token", None)