gpt4 book ai didi

artificial-intelligence - 重铸.ai : TypeError: Cannot read property 'attachment' of undefined

转载 作者:行者123 更新时间:2023-12-03 21:17:32 27 4
gpt4 key购买 nike

我希望我的 recast.bot 回复用户的回复。这是代码,但我收到以下错误消息。如何解决这个问题?

Bot Server is running on port 5002
TypeError: Cannot read property 'attachment' of undefined
at new Message (C:\FD\Node\node_modules\recastai\lib\apis\resources\message.js:66:31)
at Connect.handleMessage (C:\FD\Node\node_modules\recastai\lib\apis\connect\index.js:49:30)
at C:\FD\Node\ct2Nbot.js:28:19
at Layer.handle [as handle_request] (C:\FD\Node\node_modules\express\lib\router\layer.js:95:5)
at next (C:\FD\Node\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\FD\Node\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\FD\Node\node_modules\express\lib\router\layer.js:95:5)
at C:\FD\Node\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\FD\Node\node_modules\express\lib\router\index.js:335:12)
at next (C:\FD\Node\node_modules\express\lib\router\index.js:275:10)

我正在关注他们的 SDK: https://github.com/RecastAI/SDK-NodeJS/wiki/Receive-and-send-messages
    const express = require('express');
const bodyParser = require('body-parser');
const recastai = require('recastai').default;
const build = new recastai.build('xxxxxx', 'en');

var client = new recastai('xxxxxx')

const app = express();
const port = 5002;
app.use(bodyParser.json());

app.post('/', function(req, res) {
client.connect.handleMessage(req, res, onMessage)
})
app.listen(port, () => {
console.log('Bot Server is running on port ' + port);
})

function onMessage (message) {
var content = message.content
var type = message.type
message.addReply([{ type: 'text', content: 'Hello, world' }])
message.reply()
.then(res => console.log('message sent'))
}

最佳答案

在 handlemessage 函数中,您正在使用获取消息有效负载中不存在的 .attachment 属性。使用新的构建器,您可以直接在构建器中管理这些消息,而无需事先构建后端

关于artificial-intelligence - 重铸.ai : TypeError: Cannot read property 'attachment' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53376089/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com