请问一下各位大佬,我在云函数中使用腾讯云的智能闲聊接口,云函数中报错,请问一下怎么办?
api组件名称: tencentcloud-sdk-nodejs 中的 智能闲聊机器人 client.ChatBot(params) 问题: 此云函数在本地调试的时候可以正常运行,但是在云端测试的时候,结果会返回null 通过查看错误信息,我初步认为是premise异步调用的问题,即当数据传回来的时候,云函数的调用已经结束,于是我在前面加上了 await ,但是没有效果,请大家帮我看看,哪里出问题了,我折腾了快半天了,谢谢各位 // 云函数文件文件,
const cloud = require('wx-server-sdk')
const tencentcloud = require("tencentcloud-sdk-nodejs");
const NlpClient = tencentcloud.nlp.v20190408.Client;
const clientConfig = {
credential: {
secretId: "",
secretKey: "",
},
region: "ap-guangzhou",
profile: {
httpProfile: {
endpoint: "nlp.tencentcloudapi.com",
},
},
};
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const client = new NlpClient(clientConfig);
//const client = new NlpClient(clientConfig);
const params = {
"Query": "你好"
};
return await client.ChatBot(params)
}
本地云函数运行时,可以获取 [图片] 当使用云函数在线调用的时候出现错误 返回结果
null
日志
START
(node:133) UnhandledPromiseRejectionWarning: TypeError: cb is not a function
at NlpClient.failRequest (/var/lang/node12/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:65:9)
at /var/lang/node12/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:72:98
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:133) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:133) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
REPORT RequestId:4d6d0c54-22df-49ee-85af-22cf14ddd92e Duration:67ms Memory:256MB MemUsage:86.802467MB
END
(node:133) UnhandledPromiseRejectionWarning: TypeError: cb is not a function
at NlpClient.failRequest (/var/lang/node12/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:65:9)
at /var/lang/node12/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:72:98
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:133) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)