我正在使用 botkit 和 nodejs slack 开发人员工具包构建一个 slack 机器人。我有一系列 api 调用,第一个是查找用户(globalMembers),第二个是根据频道数组创建一个频道,最后一个调用是将每个用户添加到每个新创建的频道。
为此,我有几个承诺,以便循环访问渠道和成员。频道创建成功,然后我将每个成员和频道 ( [[member1, channel1], [member1, channel2]....]
) 的唯一数组发送到将邀请成员加入相应频道的承诺。
无论如何(我使用的是频道 ID),当我尝试获取频道信息或邀请成员加入该频道时,我都会收到“channel_not_found”错误。我是新的承诺,可能在某处有错误,感谢任何帮助。
下面是我的代码:
var channels = ["gameplay", "gamelog", "map"];
var channelData = channels.map(channelCreate);
var channelResults = Promise.all(channelData);
return channelResults.then(created => {
var channelMembers = [];
_.each(created, function(channel) {
// globalMembers is the user list
_.each(globalMembers, function(member) {
var array = [channel, member];
// prints array of arrays [channel, member]
channelMembers.push(array);
});
});
var memberData = channelMembers.map(channelJoin);
var memberResults = Promise.all(memberData);
return memberResults.then(joined => {
console.log(joined, "is the joined data");
});
});
var channelCreate = function channelCreate(name) {
// Join the channels
return web.channels.create(name).then((res) => {
console.log("created labyrinth channel: " + JSON.stringify(res.channel));
return res.channel;
}).catch((err) => { console.log(err) }); // End channels.join call
}; // End channel create
var channelJoin = function channelJoin(params) {
var member = JSON.stringify(params[1]["id"]);
var channel = JSON.stringify(params[0]["id"]);
console.log(member, "is the member that will join " + channel);
web.channels.info(channel).then(channelData => {
console.log(channelData);
if (channelData) {
// Invite each user to the labyrinth chat channel
return web.channels.invite(channel, member)
.then(res => {
return res;
}).catch((err) => { console.log(err) });
}
}).catch(err => console.log(err));
}; // End channel Join