我正在尝试编写一个cisco webex
机器人,让所有人都进入空间(房间)并随机只写一个名字。我有这个代码
framework.hears("daily host", function (bot) {
console.log("Choosing a daily host");
responded = true;
// Use the webex SDK to get the list of users in this space
bot.webex.memberships.list({roomId: bot.room.id})
.then((memberships) => {
for (const member of memberships.items) {
if (member.personId === bot.person.id) {
// Skip myself!
continue;
}
let names = (member.personDisplayName) ? member.personDisplayName : member.personEmail;
let arrays = names.split('\n');
var array = arrays[Math.floor(Math.random()*items.length)];
console.log(array)
bot.say(`Hello ${array}`);
}
})
.catch((e) => {
console.error(`Call to sdk.memberships.get() failed: ${e.messages}`);
bot.say('Hello everybody!');
});
});
但这不起作用。let arrays = names.split('\n');
在我使用空格分隔并且没有逗号之后也命名。我认为是因为什么代码不起作用控制台日志的输出:
[ '乔治华盛顿' ]
[ '约翰' ]
['威廉霍华德塔夫脱']
现在的主要问题是如何将输出转换为数组?