gpt4 book ai didi

javascript - 文本未定义 - JavaScript

转载 作者:行者123 更新时间:2023-11-28 03:20:49 25 4
gpt4 key购买 nike

我目前正在为一个学校项目制作一个聊天机器人。所以基本上我想要的是聊天机器人将用户输入的特定消息的副本发送到另一个 channel 。但是当我运行代码时,它返回的值是未定义的。我的代码如下所示:

bot.on('message', data => {
if (data.type !== 'message' || data.subtype === 'bot_message') {
return;
}
findClassroomMention(data.text);
});

var classrooms =
{
L108: ["L108","108"],
L208: ["L208","208"]
};


function findClassroomMention(message) {
var found = false
for(var ClassroomId in classrooms) {
for(var term of classrooms[ClassroomId]) {
if(message.includes(term)) {
found = ClassroomId;
break;
}
}
if (found) {
notifyProblemSolver();
break;
}
}
return found
};

function notifyProblemSolver(ClassroomId) {
const params = {
icon_emoji: ':smiley:'
}
bot.postMessageToChannel('caris','We have a problem in ' + ClassroomId, params);
};

例如用户的输入是:

Hi I have a problem in classroom L108

然后我希望聊天机器人向问题解决者发送一条包含值 L108 的消息,如下所示:

We have a problem in L108

但是当我运行代码时,它会将 L108 发送为未定义:

We have a problem in undefined

最佳答案

您忘记在 notifyProblemSolver() 中传递 ClassroomId

问题

if (found) {
// You forgot to pass the ClassroomId
notifyProblemSolver();
break;
}

解决方案

if (found) {
// Add the ClassroomId
notifyProblemSolver(ClassroomId);
break;
}

关于javascript - 文本未定义 - JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59171498/

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