IT门户, 中国互联网人工智能物联网行业资讯平台--公众IT
新闻来源:互联网资料整理       发布时间:2023/4/5 14:23:17       共计:4601 浏览

前言:

9小时前小编发现微信小程序用户:【岁月无痕】提出了一个关于“请问一下各位大佬,我在云函数中使用腾讯云的智能闲聊接口,云函数中报错,请问一下怎么办?”的问题,在问题中开发者岁月无痕对该问题做了如下阐述:

问题类型:


  • API和组件:

问题描述:

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)

注:以上是微信小程序开发者:”岁月无痕”对于本问题的一些阐述,这里做一个引用,我们将实时关注微信小程序助手对该问题提出的解决方案。

解决方案:

【38分钟前】微信小程序技术运营专员对用户岁月无痕提出的请问一下各位大佬,我在云函数中使用腾讯云的智能闲聊接口,云函数中报错,请问一下怎么办?给予如下回复

结语:

流量变现是移动互联网永远的话题。由于用户属性和所属行业等原因,部分APP空有流量,但变现能力较弱。受制于原生APP单一的功能,这类企业对变现模式的探索屡屡碰壁。加入微信官方智能小程序,可以用智能小程序提升自己的商业化效率。

如果您也在使用微信小程序,请关注我们,如果您有关于微信小程序的使用问题请关注我们,如果您要找百度小程序模板、微信小程序模板请关注小程序模板网或者去微信开放社区找官方人员给予解决,相信微信官方在小程序上的发力会是一个里程碑!

版权说明:
本网站凡注明“公众IT 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
您可以扫描右侧微信二维码联系我们。
网站首页 关于我们 联系我们 合作联系 会员说明 新闻投稿 隐私协议 网站地图