diff --git a/chatopera.js b/chatopera.js index 5f1f943..4fd6c7e 100644 --- a/chatopera.js +++ b/chatopera.js @@ -1,5 +1,6 @@ const debug = require('debug')('chatopera:sdk:chatopera'); const request = require('superagent'); +const utils = require('./lib/utils'); const BASE_PATH = '/api/v1'; @@ -86,6 +87,8 @@ class Chatopera { } ); } + + static utils = utils; } module.exports = exports = Chatopera; diff --git a/lib/utils.js b/lib/utils.js index 6336531..2d96291 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -10,6 +10,7 @@ */ const archiver = require("archiver"); const fs = require("fs"); +const yaml = require('js-yaml'); /** * [getTimestamp description] @@ -47,3 +48,38 @@ exports.zipDirectory = function (source, out) { archive.finalize(); }); }; + +exports.mapFaqFromYaml = function (yamlSource) { + const data = yaml.load(yamlSource); + + const result = {}; + + for (const repoFullName in data) { + const repoFaq = data[repoFullName]; + + const questions = []; + for (const post in repoFaq) { + const value = repoFaq[post]; + const categoryTexts = value.categories && value.categories.split('/'); + const replies = value.answers.map((a) => { + return { + rtype: 'plain', + content: a, + enabled: true, + }; + }); + + questions.push({ + post, + categoryTexts, + replies, + extends: value.extends, + enabled: true, + }); + } + + result[repoFullName] = questions; + } + + return result; +}; diff --git a/package.json b/package.json index fc4e1ec..8d51714 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chatopera/sdk", - "version": "2.6.0", + "version": "2.7.0", "description": "低代码或无代码方式定制智能对话机器人,https://bot.chatopera.com", "main": "index.js", "bin": { @@ -33,6 +33,7 @@ "dotenv": "^8.2.0", "inquirer": "^7.3.3", "inquirer-command-prompt": "0.0.28", + "js-yaml": "^4.1.0", "moment-timezone": "^0.5.31", "superagent": "^5.3.1" },