def create_articles(title, type, content, account_id=None, attention_period_in_days=None): """ Create articles. reference - `Common Message Property <https://developers.worksmobile.com/jp/document/100180301?lang=en>`_ """ headers = { "charset": "UTF-8", "consumerKey": OPEN_API["consumerKey"] } board_no = get_value("{type}board".format(type=type), None) if board_no is None: logging.error("create articles. board no is None.") raise HTTPError(500, "create articles. board no is None.") body = { "title": title, "body": content, "boardNo": board_no, "domainId": DOMAIN_ID, "sendCreatedNotify": True, "useComment": True } if account_id is not None: body["accountId"] = account_id if attention_period_in_days is not None: body["attentionPeriodInDays"] = attention_period_in_days multi1 = MultipartEncoder( fields={"article":(None, json.dumps(body))} ) headers['content-type'] = multi1.content_type boards_url = API_BO["home"]["create_articles_url"] response = auth_post(boards_url, data=multi1, headers=headers) if response.status_code != 200 or response.content is None: logging.error( "create articles failed. url:%s text:%s headers:%s body:%s", boards_url, response.text, json.dumps(headers), multi1.to_string()) if response.status_code == 507: return storage_lack() else: return create_articles_failed() tmp_req = json.loads(response.content) article_no = tmp_req.get("articleNo", None) if article_no is None: logging.error("create articles failed. url:%s text:%s", boards_url, response.text) raise HTTPError(500, "create articles. article no is None.") return None
def replace_url_bot_no(url): bot_no = get_value("bot_no", None) if bot_no is None: logging.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
def register_rich_menun(account_id): """ Set up rich menu for chat with users. Check also: faq_bot/model/data.py reference - `Common Message Property <https://developers.worksmobile.com/jp/document/1005040?lang=en>`_ :param account_id: user account id """ if account_id is None: logging.error("account_id is None.") return False rich_menu_id = get_value("rich_menu", None) if rich_menu_id is None: logging.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)