Skip to content

Commit

Permalink
kaiyuanshe/osschat#175 faq yaml convert
Browse files Browse the repository at this point in the history
  • Loading branch information
mukaiu committed Oct 22, 2021
1 parent 3195524 commit 6a0e269
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions chatopera.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -86,6 +87,8 @@ class Chatopera {
}
);
}

static utils = utils;
}

module.exports = exports = Chatopera;
36 changes: 36 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
const archiver = require("archiver");
const fs = require("fs");
const yaml = require('js-yaml');

/**
* [getTimestamp description]
Expand Down Expand Up @@ -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;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chatopera/sdk",
"version": "2.6.0",
"version": "2.7.0",
"description": "低代码或无代码方式定制智能对话机器人,https://bot.chatopera.com",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -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"
},
Expand Down

0 comments on commit 6a0e269

Please sign in to comment.