@chatopera/sdk
Advanced tools
Comparing version 1.1.2 to 1.2.0
var Authing = require('../index.js'); | ||
var email = "xxx@memect.co"; | ||
var password = "123456"; | ||
var secret = '427e24d3b7e289ae9469ab6724dc7ff0'; | ||
var clientId = '5a9fa26cf8635a000185528c'; | ||
var email = 'xxx@memect.co'; | ||
var password = '123456'; | ||
var secret = 'b5287df035e815b59546077f4eea705f'; | ||
var clientId = '5c134649aa257e67b216c6a5'; | ||
var auth = new Authing({ | ||
clientId: clientId, | ||
secret: secret | ||
clientId: clientId, | ||
secret: secret, | ||
}); | ||
auth.then(function(auth) { | ||
auth.readOAuthList().then(function(list) { | ||
console.log('获取OAuth列表成功!'); | ||
console.log(list); | ||
}).catch(function(error) { | ||
console.log('获取OAuth列表失败!'); | ||
console.log(error); | ||
}); | ||
auth | ||
.readOAuthList() | ||
.then(function(list) { | ||
console.log('获取OAuth列表成功!'); | ||
console.log(list); | ||
}) | ||
.catch(function(error) { | ||
console.log('获取OAuth列表失败!'); | ||
console.log(error); | ||
}); | ||
}); |
{ | ||
"name": "@chatopera/sdk", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Official sdk of Chatopera", | ||
"main": "dist/main.js", | ||
"bin": { | ||
"bot": "bin/connect-bot.js" | ||
}, | ||
"browser": "dist/main.min.js", | ||
@@ -27,4 +30,6 @@ "unpkg": "dist/main.min.js", | ||
"axios": "^0.18.0", | ||
"commander": "^2.20.0", | ||
"crypto-js": "^3.1.9-1", | ||
"debug": "^4.1.0", | ||
"inquirer": "^6.3.1", | ||
"jsencrypt": "^2.3.1", | ||
@@ -50,2 +55,2 @@ "moment": "^2.22.2" | ||
} | ||
} | ||
} |
/** | ||
* Chatbot API | ||
*/ | ||
const debug = require("debug")("chatopera:sdk:chatbot"); | ||
const axios = require("axios"); | ||
const debug = require('debug')('chatopera:sdk:chatbot'); | ||
const axios = require('axios'); | ||
const url = require('url'); | ||
const baseURL = process.env["SUPERBRAIN_PROXY_URL"] ? (() => { let q = url.parse(process.env["SUPERBRAIN_PROXY_URL"]); return `${q.protocol}//${q.host}` })() : "https://bot.chatopera.com"; | ||
const basePath = "/api/v1/chatbot"; | ||
const generate = require("./generate-authorization"); | ||
const baseURL = process.env['SUPERBRAIN_PROXY_URL'] | ||
? (() => { | ||
let q = url.parse(process.env['SUPERBRAIN_PROXY_URL']); | ||
return `${q.protocol}//${q.host}`; | ||
})() | ||
: 'http://dev.bot.chatopera.com:5558'; | ||
const basePath = '/api/v1/chatbot'; | ||
const generate = require('./generate-authorization'); | ||
const METHOD_POST = "POST"; | ||
const METHOD_GET = "GET"; | ||
const METHOD_DELETE = "DELETE"; | ||
const METHOD_PUT = "PUT"; | ||
const METHOD_PATCH = "PATCH"; | ||
const METHOD_POST = 'POST'; | ||
const METHOD_GET = 'GET'; | ||
const METHOD_DELETE = 'DELETE'; | ||
const METHOD_PUT = 'PUT'; | ||
const METHOD_PATCH = 'PATCH'; | ||
console.log("[chatopera] set chatbot engine baseURL", baseURL); | ||
console.log('[chatopera] set chatbot engine baseURL', baseURL); | ||
const request = axios.create({ | ||
baseURL: baseURL, | ||
timeout: 10000, | ||
headers: { | ||
"Content-Type": "application/json" | ||
baseURL: baseURL, | ||
timeout: 10000, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
responseType: 'json', | ||
// `transformResponse` allows changes to the response data to be made before | ||
// it is passed to then/catch | ||
transformResponse: [ | ||
function(data) { | ||
// remove chatbotID | ||
data = JSON.parse(data); | ||
if (data.data) { | ||
if (data.data.chatbotID) { | ||
delete data.data.chatbotID; | ||
} else if (Array.isArray(data.data)) { | ||
for (let x in data.data) { | ||
delete data.data[x].chatbotID; | ||
} | ||
} | ||
} | ||
return data; | ||
}, | ||
responseType: 'json', | ||
// `transformResponse` allows changes to the response data to be made before | ||
// it is passed to then/catch | ||
transformResponse: [function(data) { | ||
// remove chatbotID | ||
data = JSON.parse(data); | ||
if (data.data) { | ||
if (data.data.chatbotID) { | ||
delete data.data.chatbotID | ||
} else if (Array.isArray(data.data)) { | ||
for (let x in data.data) { | ||
delete data.data[x].chatbotID | ||
} | ||
} | ||
} | ||
return data; | ||
}] | ||
], | ||
}); | ||
function _resp(send) { | ||
return send.then((resp) => { | ||
if (resp.status === 200) { | ||
return resp.data; | ||
} | ||
throw resp.data || new Error(`error, statusCode ${resp.status}`); | ||
}, (err) => { | ||
throw err; | ||
}); | ||
return send.then( | ||
resp => { | ||
if (resp.status === 200) { | ||
return resp.data; | ||
} | ||
throw resp.data || new Error(`error, statusCode ${resp.status}`); | ||
}, | ||
err => { | ||
throw err; | ||
} | ||
); | ||
} | ||
@@ -63,12 +73,13 @@ | ||
Client.prototype.getChatbotById = function(clientId, secret) { | ||
debug("getChatbotById: %s, %s", clientId, secret) | ||
let path = `${basePath}/${clientId}`; | ||
return _resp(request.get(path, { | ||
headers: { | ||
Authorization: generate(clientId, secret, METHOD_GET, path) | ||
} | ||
})); | ||
} | ||
debug('getChatbotById: %s, %s', clientId, secret); | ||
let path = `${basePath}/${clientId}`; | ||
return _resp( | ||
request.get(path, { | ||
headers: { | ||
Authorization: generate(clientId, secret, METHOD_GET, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
/** | ||
@@ -81,9 +92,8 @@ * 创建问答对 | ||
Client.prototype.createFaqPair = function(clientId, data) { | ||
return _resp(request.post(`${basePath}/${clientId}/faq/database`, data)); | ||
} | ||
return _resp(request.post(`${basePath}/${clientId}/faq/database`, data)); | ||
}; | ||
Client.prototype.getFaqPairDetail = function(clientId, docId) { | ||
return _resp(request.get(`${basePath}/${clientId}/faq/database/${docId}`)); | ||
} | ||
return _resp(request.get(`${basePath}/${clientId}/faq/database/${docId}`)); | ||
}; | ||
@@ -98,4 +108,6 @@ /** | ||
Client.prototype.updateFaqPair = function(clientId, docId, data) { | ||
return _resp(request.put(`${basePath}/${clientId}/faq/database/${docId}`, data)); | ||
} | ||
return _resp( | ||
request.put(`${basePath}/${clientId}/faq/database/${docId}`, data) | ||
); | ||
}; | ||
@@ -110,4 +122,8 @@ /** | ||
Client.prototype.getFaqPairs = function(clientId, page = 1, limit = 30) { | ||
return _resp(request.get(`${basePath}/${clientId}/faq/database?page=${page}&limit=${limit}`)); | ||
} | ||
return _resp( | ||
request.get( | ||
`${basePath}/${clientId}/faq/database?page=${page}&limit=${limit}` | ||
) | ||
); | ||
}; | ||
@@ -121,4 +137,4 @@ /** | ||
Client.prototype.delFaqPair = function(clientId, docId) { | ||
return _resp(request.delete(`${basePath}/${clientId}/faq/database/${docId}`)); | ||
} | ||
return _resp(request.delete(`${basePath}/${clientId}/faq/database/${docId}`)); | ||
}; | ||
@@ -132,4 +148,6 @@ /** | ||
Client.prototype.createFaqPairExtend = function(clientId, docId, data) { | ||
return _resp(request.post(`${basePath}/${clientId}/faq/database/${docId}/extend`, data)); | ||
} | ||
return _resp( | ||
request.post(`${basePath}/${clientId}/faq/database/${docId}/extend`, data) | ||
); | ||
}; | ||
@@ -143,4 +161,6 @@ /** | ||
Client.prototype.getFaqPairExtends = function(clientId, docId) { | ||
return _resp(request.get(`${basePath}/${clientId}/faq/database/${docId}/extend`)); | ||
} | ||
return _resp( | ||
request.get(`${basePath}/${clientId}/faq/database/${docId}/extend`) | ||
); | ||
}; | ||
@@ -155,15 +175,28 @@ /** | ||
*/ | ||
Client.prototype.updateFaqPairExtend = function(clientId, docId, extendId, data) { | ||
return _resp(request.put(`${basePath}/${clientId}/faq/database/${docId}/extend/${extendId}`, data)); | ||
} | ||
Client.prototype.updateFaqPairExtend = function( | ||
clientId, | ||
docId, | ||
extendId, | ||
data | ||
) { | ||
return _resp( | ||
request.put( | ||
`${basePath}/${clientId}/faq/database/${docId}/extend/${extendId}`, | ||
data | ||
) | ||
); | ||
}; | ||
/** | ||
* 删除FAQ扩展问 | ||
* | ||
* | ||
* @return {[type]} [description] | ||
*/ | ||
Client.prototype.delFaqPairExtend = function(clientId, docId, extendId) { | ||
return _resp(request.delete(`${basePath}/${clientId}/faq/database/${docId}/extend/${extendId}`)); | ||
} | ||
return _resp( | ||
request.delete( | ||
`${basePath}/${clientId}/faq/database/${docId}/extend/${extendId}` | ||
) | ||
); | ||
}; | ||
@@ -177,6 +210,5 @@ /** | ||
Client.prototype.createFaqSynonyms = function(clientId, data) { | ||
return _resp(request.post(`${basePath}/${clientId}/faq/synonyms`, data)) | ||
} | ||
return _resp(request.post(`${basePath}/${clientId}/faq/synonyms`, data)); | ||
}; | ||
/** | ||
@@ -189,4 +221,6 @@ * 获得近义词详情 | ||
Client.prototype.getFaqSynonymsDetail = function(clientId, synonymsId) { | ||
return _resp(request.get(`${basePath}/${clientId}/faq/synonyms/${synonymsId}`)) | ||
} | ||
return _resp( | ||
request.get(`${basePath}/${clientId}/faq/synonyms/${synonymsId}`) | ||
); | ||
}; | ||
@@ -201,4 +235,6 @@ /** | ||
Client.prototype.updateFaqSynonyms = function(clientId, synonymsId, data) { | ||
return _resp(request.put(`${basePath}/${clientId}/faq/synonyms/${synonymsId}`, data)) | ||
} | ||
return _resp( | ||
request.put(`${basePath}/${clientId}/faq/synonyms/${synonymsId}`, data) | ||
); | ||
}; | ||
@@ -212,103 +248,140 @@ /** | ||
Client.prototype.delFaqSynonyms = function(clientId, synonymsId) { | ||
return _resp(request.delete(`${basePath}/${clientId}/faq/synonyms/${synonymsId}`)) | ||
} | ||
return _resp( | ||
request.delete(`${basePath}/${clientId}/faq/synonyms/${synonymsId}`) | ||
); | ||
}; | ||
Client.prototype.getFaqSynonymsList = function(clientId) { | ||
return _resp(request.get(`${basePath}/${clientId}/faq/synonyms`)) | ||
} | ||
return _resp(request.get(`${basePath}/${clientId}/faq/synonyms`)); | ||
}; | ||
Client.prototype.queryFaq = function(clientId, clientSecret, data) { | ||
let path = `${basePath}/${clientId}/faq/query`; | ||
return _resp(request.post(path, data, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path) | ||
} | ||
})) | ||
} | ||
let path = `${basePath}/${clientId}/faq/query`; | ||
return _resp( | ||
request.post(path, data, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
Client.prototype.parseIntent = function(clientId, data) { | ||
return _resp(request.post(`${basePath}/${clientId}/intent/parse`, data)) | ||
} | ||
return _resp(request.post(`${basePath}/${clientId}/intent/parse`, data)); | ||
}; | ||
Client.prototype.getConversationList = function(clientId) { | ||
return _resp(request.get(`${basePath}/${clientId}/conversation`)) | ||
} | ||
return _resp(request.get(`${basePath}/${clientId}/conversation`)); | ||
}; | ||
Client.prototype.getConversationDetail = function(clientId, conversationId) { | ||
return _resp(request.get(`${basePath}/${clientId}/conversation/${conversationId}`)) | ||
} | ||
return _resp( | ||
request.get(`${basePath}/${clientId}/conversation/${conversationId}`) | ||
); | ||
}; | ||
Client.prototype.enableConversationById = function(clientId, conversationId) { | ||
return _resp(request.put(`${basePath}/${clientId}/conversation/${conversationId}/enable`)) | ||
} | ||
return _resp( | ||
request.put(`${basePath}/${clientId}/conversation/${conversationId}/enable`) | ||
); | ||
}; | ||
Client.prototype.disableConversationById = function(clientId, conversationId) { | ||
return _resp(request.put(`${basePath}/${clientId}/conversation/${conversationId}/disable`)) | ||
} | ||
return _resp( | ||
request.put( | ||
`${basePath}/${clientId}/conversation/${conversationId}/disable` | ||
) | ||
); | ||
}; | ||
Client.prototype.getConversationEnvironment = function(clientId) { | ||
return _resp(request.get(`${basePath}/${clientId}/conversation/environment`)) | ||
} | ||
return _resp(request.get(`${basePath}/${clientId}/conversation/environment`)); | ||
}; | ||
Client.prototype.putConversationEnvironment = function(clientId) { | ||
return _resp(request.put(`${basePath}/${clientId}/conversation/environment`, data)) | ||
} | ||
return _resp( | ||
request.put(`${basePath}/${clientId}/conversation/environment`, data) | ||
); | ||
}; | ||
Client.prototype.queryConversation = function(clientId, clientSecret, data) { | ||
let path = `${basePath}/${clientId}/conversation/query`; | ||
return _resp(request.post(path, data, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path) | ||
} | ||
})); | ||
} | ||
let path = `${basePath}/${clientId}/conversation/query`; | ||
return _resp( | ||
request.post(path, data, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
Client.prototype.getUserList = function(clientId, clientSecret, page = 1, pageSize = 30, sortby = "-lasttime") { | ||
let path = `${basePath}/${clientId}/users?page=${page}&limit=${pageSize}&sortby=${sortby}`; | ||
debug("getUserList: %s, %s, %s", clientId, clientSecret, path) | ||
return _resp(request.get(path, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_GET, path) | ||
} | ||
})) | ||
} | ||
Client.prototype.getUserList = function( | ||
clientId, | ||
clientSecret, | ||
page = 1, | ||
pageSize = 30, | ||
sortby = '-lasttime' | ||
) { | ||
let path = `${basePath}/${clientId}/users?page=${page}&limit=${pageSize}&sortby=${sortby}`; | ||
debug('getUserList: %s, %s, %s', clientId, clientSecret, path); | ||
return _resp( | ||
request.get(path, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_GET, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
Client.prototype.getUserChatHistoryList = function(clientId, clientSecret, userId, page = 1, pageSize = 20) { | ||
let path = `${basePath}/${clientId}/users/${userId}/chats?page=${page}&limit=${pageSize}`; | ||
debug("getUserChatHistoryList: %s, %s, %s", clientId, clientSecret, path) | ||
return _resp(request.get(path, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_GET, path) | ||
} | ||
})) | ||
} | ||
Client.prototype.getUserChatHistoryList = function( | ||
clientId, | ||
clientSecret, | ||
userId, | ||
page = 1, | ||
pageSize = 20 | ||
) { | ||
let path = `${basePath}/${clientId}/users/${userId}/chats?page=${page}&limit=${pageSize}`; | ||
debug('getUserChatHistoryList: %s, %s, %s', clientId, clientSecret, path); | ||
return _resp( | ||
request.get(path, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_GET, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
Client.prototype.muteUserById = function(clientId, clientSecret, userId) { | ||
let path = `${basePath}/${clientId}/users/${userId}/mute`; | ||
return _resp(request.post(path, null, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path) | ||
} | ||
})) | ||
} | ||
let path = `${basePath}/${clientId}/users/${userId}/mute`; | ||
return _resp( | ||
request.post(path, null, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
Client.prototype.unmuteUserById = function(clientId, clientSecret, userId) { | ||
let path = `${basePath}/${clientId}/users/${userId}/unmute`; | ||
return _resp(request.post(path, null, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path) | ||
} | ||
})) | ||
} | ||
let path = `${basePath}/${clientId}/users/${userId}/unmute`; | ||
return _resp( | ||
request.post(path, null, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
Client.prototype.ismuteUserById = function(clientId, clientSecret, userId) { | ||
let path = `${basePath}/${clientId}/users/${userId}/ismute`; | ||
return _resp(request.post(path, null, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path) | ||
} | ||
})) | ||
} | ||
let path = `${basePath}/${clientId}/users/${userId}/ismute`; | ||
return _resp( | ||
request.post(path, null, { | ||
headers: { | ||
Authorization: generate(clientId, clientSecret, METHOD_POST, path), | ||
}, | ||
}) | ||
); | ||
}; | ||
exports = module.exports = new Client(); |
const crypto = require('crypto'); | ||
const moment = require('moment'); | ||
const debug = require('debug')('chatopera:sdk:generator'); | ||
@@ -21,2 +22,8 @@ const hmacSha1 = (secret, text) => | ||
const generate = (appId, secret, method, path) => { | ||
// bypass auth if appId or secret not present. | ||
if(appId == null || secret == null){ | ||
debug("[WARN] appId or secret not present."); | ||
return null; | ||
} | ||
const timestamp = moment().unix(); | ||
@@ -23,0 +30,0 @@ const random = Math.round(Math.random() * 10000000000); |
@@ -5,102 +5,124 @@ /** | ||
const test = require("ava"); | ||
const chatbot = require("../src/client"); | ||
const test = require('ava'); | ||
const chatbot = require('../src/client'); | ||
test.beforeEach(t => { | ||
t.context.chatbotID = '5bbd0db423fe9e4616ac2d6d'; | ||
t.context.faqDocId = 'AWZ3PDTUNZQ8InLms5Qu'; | ||
}) | ||
t.context.chatbotID = '5c134649aa257e67b216c6a5'; | ||
t.context.faqDocId = 'AWZ3PDTUNZQ8InLms5Qu'; | ||
}); | ||
test("Chatbot Test#get bot by chatbotID", async (t) => { | ||
let response = await chatbot.getChatbotById(t.context.chatbotID); | ||
console.log("bot detail:", response); | ||
t.pass(); | ||
}) | ||
test('Chatbot Test#get bot by chatbotID', async t => { | ||
let response = await chatbot.getChatbotById(t.context.chatbotID); | ||
console.log('bot detail:', response); | ||
t.pass(); | ||
}); | ||
test.skip("Chatbot Test#create faq pair by chatbotID", async (t) => { | ||
let response = await chatbot.createFaqPair(t.context.chatbotID, { | ||
"post": "怎么开通微信支付?", | ||
"reply": "登录微信公众号平台,点击左侧微信支付菜单栏,按照开通步骤开通微信支付", | ||
"enabled": true | ||
}); | ||
console.log("faq pair:", response); | ||
t.pass(); | ||
}) | ||
test.skip('Chatbot Test#create faq pair by chatbotID', async t => { | ||
let response = await chatbot.createFaqPair(t.context.chatbotID, { | ||
post: '怎么开通微信支付?', | ||
reply: | ||
'登录微信公众号平台,点击左侧微信支付菜单栏,按照开通步骤开通微信支付', | ||
enabled: true, | ||
}); | ||
console.log('faq pair:', response); | ||
t.pass(); | ||
}); | ||
test("Chatbot Test#get faq detial", async (t) => { | ||
let response = await chatbot.getFaqPairDetail(t.context.chatbotID, t.context.faqDocId); | ||
console.log("getFaqPairDetail", response); | ||
t.pass(); | ||
}) | ||
test('Chatbot Test#get faq detial', async t => { | ||
let response = await chatbot.getFaqPairDetail( | ||
t.context.chatbotID, | ||
t.context.faqDocId | ||
); | ||
console.log('getFaqPairDetail', response); | ||
t.pass(); | ||
}); | ||
test("Chatbot Test#update faq pair", async (t) => { | ||
let response = await chatbot.updateFaqPair(t.context.chatbotID, t.context.faqDocId, { | ||
post: "怎么开通支付宝支付?", | ||
reply: "登录支付宝企业平台,点击左侧微信支付菜单栏,按照开通步骤开通微信支付", | ||
enabled: true | ||
}); | ||
test('Chatbot Test#update faq pair', async t => { | ||
let response = await chatbot.updateFaqPair( | ||
t.context.chatbotID, | ||
t.context.faqDocId, | ||
{ | ||
post: '怎么开通支付宝支付?', | ||
reply: | ||
'登录支付宝企业平台,点击左侧微信支付菜单栏,按照开通步骤开通微信支付', | ||
enabled: true, | ||
} | ||
); | ||
console.log("updateFaqPair", response); | ||
t.pass(); | ||
}) | ||
console.log('updateFaqPair', response); | ||
t.pass(); | ||
}); | ||
test("Chatbot Test#get faq lists", async (t) => { | ||
let response = await chatbot.getFaqPairs(t.context.chatbotID, { | ||
page: 1, | ||
limit: 10 | ||
}); | ||
t.true(response.data.length >= 0, "Wrong doc length."); | ||
t.pass(); | ||
}) | ||
test('Chatbot Test#get faq lists', async t => { | ||
let response = await chatbot.getFaqPairs(t.context.chatbotID, { | ||
page: 1, | ||
limit: 10, | ||
}); | ||
t.true(response.data.length >= 0, 'Wrong doc length.'); | ||
t.pass(); | ||
}); | ||
test.skip("Chatbot Test#delete faq pair", async (t) => { | ||
let response = await chatbot.delFaqPair(t.context.chatbotID, 'AWZ3ebuvNZQ8InLms5Q5'); | ||
console.log("delete faq pair", response); | ||
t.pass() | ||
}) | ||
test.skip('Chatbot Test#delete faq pair', async t => { | ||
let response = await chatbot.delFaqPair( | ||
t.context.chatbotID, | ||
'AWZ3ebuvNZQ8InLms5Q5' | ||
); | ||
console.log('delete faq pair', response); | ||
t.pass(); | ||
}); | ||
test('Chatbot Test#create faq extend by chatbotID and docId', async t => { | ||
let response = await chatbot.createFaqPairExtend( | ||
t.context.chatbotID, | ||
t.context.faqDocId, | ||
{ | ||
post: '怎样支持微信支付?', | ||
} | ||
); | ||
console.log('createFaqPairExtend', response); | ||
t.pass(); | ||
}); | ||
test("Chatbot Test#create faq extend by chatbotID and docId", async (t) => { | ||
let response = await chatbot.createFaqPairExtend(t.context.chatbotID, t.context.faqDocId, { | ||
post: '怎样支持微信支付?' | ||
}); | ||
console.log("createFaqPairExtend", response); | ||
t.pass(); | ||
}) | ||
test('Chatbot Test#get faq pair extends', async t => { | ||
let response = await chatbot.getFaqPairExtends( | ||
t.context.chatbotID, | ||
t.context.faqDocId | ||
); | ||
console.log('getFaqPairExtends', response); | ||
t.pass(); | ||
}); | ||
test("Chatbot Test#get faq pair extends", async (t) => { | ||
let response = await chatbot.getFaqPairExtends(t.context.chatbotID, t.context.faqDocId); | ||
console.log("getFaqPairExtends", response) | ||
t.pass(); | ||
}) | ||
test.skip('Chatbot Test#update faq pair extend', async t => { | ||
let response = await chatbot.updateFaqPairExtend( | ||
t.context.chatbotID, | ||
t.context.faqDocId, | ||
'AWaFuQL-NZQ8InLms5SA', | ||
{ | ||
post: '怎样接入微信支付?', | ||
} | ||
); | ||
t.is(response.rc, 0, 'Wrong response code'); | ||
console.log('updateFaqPairExtend', response); | ||
t.pass(); | ||
}); | ||
test.skip("Chatbot Test#update faq pair extend", async (t) => { | ||
let response = await chatbot.updateFaqPairExtend(t.context.chatbotID, | ||
t.context.faqDocId, | ||
'AWaFuQL-NZQ8InLms5SA', { | ||
post: "怎样接入微信支付?" | ||
}); | ||
t.is(response.rc, 0, "Wrong response code"); | ||
console.log("updateFaqPairExtend", response); | ||
t.pass() | ||
}) | ||
test.skip('Chatbot Test#delete faq pair extend', async t => { | ||
let response = await chatbot.delFaqPairExtend( | ||
t.context.chatbotID, | ||
t.context.faqDocId, | ||
'AWaFuaS6NZQ8InLms5SG' | ||
); | ||
t.is(response.rc, 0, 'Wrong response code'); | ||
console.log('delFaqPairExtend', response); | ||
t.pass(); | ||
}); | ||
test.skip("Chatbot Test#delete faq pair extend", async (t) => { | ||
let response = await chatbot.delFaqPairExtend(t.context.chatbotID, | ||
t.context.faqDocId, | ||
'AWaFuaS6NZQ8InLms5SG'); | ||
t.is(response.rc, 0, "Wrong response code"); | ||
console.log("delFaqPairExtend", response); | ||
t.pass() | ||
}) | ||
test.skip("Chatbot Test#create synonyms", async (t) => { | ||
let response = await chatbot.createFaqSynonyms(t.context.chatbotID, { | ||
"text": "番茄", | ||
"neighbors": ["西红柿", "狼桃"] | ||
}); | ||
console.log("createFaqSynonyms", response); | ||
t.is(response.rc, 0, "Wrong response code"); | ||
t.pass(); | ||
}) | ||
test.skip('Chatbot Test#create synonyms', async t => { | ||
let response = await chatbot.createFaqSynonyms(t.context.chatbotID, { | ||
text: '番茄', | ||
neighbors: ['西红柿', '狼桃'], | ||
}); | ||
console.log('createFaqSynonyms', response); | ||
t.is(response.rc, 0, 'Wrong response code'); | ||
t.pass(); | ||
}); |
@@ -1,75 +0,73 @@ | ||
const test = require("ava"); | ||
const debug = require("debug")("chatopera:sdk:test") | ||
const generate = require("../src/generate-authorization") | ||
const Chatbot = require("../index"); | ||
const clientId = '5be3d0a46f80090017b3c529' | ||
const clientSecret = '208b8e0965eaccec36026cca670ccdfd' | ||
const test = require('ava'); | ||
const debug = require('debug')('chatopera:sdk:test'); | ||
const generate = require('../src/generate-authorization'); | ||
const Chatbot = require('../index'); | ||
const clientId = '5c134649aa257e67b216c6a5'; | ||
const clientSecret = 'b5287df035e815b59546077f4eea705f'; | ||
test('Test generate token', async t => { | ||
const token = generate( | ||
clientId, | ||
clientSecret, | ||
'POST', | ||
`/api/v1/chatbot/${clientId}/faq/database` | ||
); | ||
console.log('token', token); | ||
t.pass(); | ||
}); | ||
test("Test generate token", async (t) => { | ||
const token = generate(clientId, clientSecret, "POST", `/api/v1/chatbot/${clientId}/faq/database`); | ||
console.log("token", token) | ||
t.pass() | ||
}) | ||
test('Test get chatbot detail by Id', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.detail(); | ||
console.log('detail', resp); | ||
t.pass(); | ||
}); | ||
test('Test query conversation', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.conversation('nodesdk', '你好'); | ||
console.log('conversation', resp); | ||
t.pass(); | ||
}); | ||
test("Test get chatbot detail by Id", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.detail(); | ||
console.log("detail", resp); | ||
t.pass(); | ||
}) | ||
test('Test query faq', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.faq('nodesdk', '停效期间的保单是否能办理减保'); | ||
console.log('faq', resp); | ||
t.pass(); | ||
}); | ||
test("Test query conversation", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.conversation("nodesdk", "你好"); | ||
console.log("conversation", resp); | ||
t.pass(); | ||
}) | ||
test('Test get user list', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.users(); | ||
console.log('users', resp); | ||
t.pass(); | ||
}); | ||
test("Test query faq", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.faq("nodesdk", "停效期间的保单是否能办理减保"); | ||
console.log("faq", resp); | ||
t.pass(); | ||
}) | ||
test.only('Test get chat history', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.chats('nodesdk'); | ||
console.log('chats', resp); | ||
t.pass(); | ||
}); | ||
test("Test get user list", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.users(); | ||
console.log("users", resp) | ||
t.pass() | ||
}) | ||
test('Test mute user', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.mute('nodesdk'); | ||
console.log('mute', resp); | ||
t.pass(); | ||
}); | ||
test.skip('Test unmute user', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.unmute('nodesdk'); | ||
console.log('unmute', resp); | ||
t.pass(); | ||
}); | ||
test.only("Test get chat history", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.chats("nodesdk"); | ||
console.log("chats", resp) | ||
t.pass() | ||
}) | ||
test("Test mute user", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.mute("nodesdk"); | ||
console.log("mute", resp); | ||
t.pass() | ||
}) | ||
test.skip("Test unmute user", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.unmute("nodesdk"); | ||
console.log("unmute", resp); | ||
t.pass() | ||
}) | ||
test("Test ismute user", async (t) => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.ismute("nodesdk"); | ||
console.log("ismute", resp); | ||
t.pass() | ||
}) | ||
test('Test ismute user', async t => { | ||
const chatbot = new Chatbot(clientId, clientSecret); | ||
let resp = await chatbot.ismute('nodesdk'); | ||
console.log('ismute', resp); | ||
t.pass(); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
63092
19
1969
7
1
+ Addedcommander@^2.20.0
+ Addedinquirer@^6.3.1
+ Addedansi-escapes@3.2.0(transitive)
+ Addedansi-regex@3.0.14.1.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedchardet@0.7.0(transitive)
+ Addedcli-cursor@2.1.0(transitive)
+ Addedcli-width@2.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedexternal-editor@3.1.0(transitive)
+ Addedfigures@2.0.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinquirer@6.5.2(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmimic-fn@1.2.0(transitive)
+ Addedmute-stream@0.0.7(transitive)
+ Addedonetime@2.0.1(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedrestore-cursor@2.0.0(transitive)
+ Addedrun-async@2.4.1(transitive)
+ Addedrxjs@6.6.7(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@2.1.1(transitive)
+ Addedstrip-ansi@4.0.05.2.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtmp@0.0.33(transitive)
+ Addedtslib@1.14.1(transitive)