Esempio n. 1
0
const setCorrectChannel = () => {
	bot.getChannels().then((channelList) => {
		for (let channelInArray of channelList.channels) {
			if (channelInArray.name === s3.channel) {
				channelId = channelInArray.id
				break
			}
		}
	})
}
Esempio n. 2
0
function getChannelById(id) {
    channelList = bot.getChannels()._value.channels;
    //console.log(channelList);
    //console.log(channelList);

    for(i = 0; i<channelList.length; i++) {
        if(channelList[i].id == id) {
            return channelList[i].name;
        }
    }
    //should never get here, but don't return nothing cause that's bad
    return "\"channel not found\"";
}
Esempio n. 3
0
bot.on('start', function() {
	console.log('started');
	bot.getChannels().then(function(res) {
		console.log('got channels');
		//console.log(res);
		
		res.channels.forEach(function(ch) {
			fromId.channels[ch.id] = ch.name;
			toId.channels[ch.name] = ch.id;
		});
		//console.log(fromId.channels);
		
		bot.getUsers().then(function(res) {
			console.log('got users');
			//console.log(res);
			
			res.members.forEach(function(u) {
				fromId.users[u.id] = u.name;
				toId.users[u.name] = u.id;
			});
			//console.log(fromId.users);
			
			bot.on('message', function(o) {
				var u = fromId.users[o.user];
				var ch = fromId.channels[o.channel];
				switch (o.type) {
					case 'presence_change':
						console.log('@%s is now %s', u, o.presence);
						break;
					
					case 'user_typing':
						console.log('@%s is now typing on #%s', u, ch);
						break;
					
					case 'message':
						var msg = o.text;
						var verb = 'wrote';
						if (o.subtype === 'message_deleted') {
							console.log('message deleted from #%s', ch);
							break;
						}
						else if (o.subtype === 'message_changed') {
							u = fromId.users[o.message.user];
							msg = o.message.text;
							verb = 'edited';
						}
						console.log('@%s %s on #%s "%s"', u, verb, ch, msg);
						break;
					
					case 'hello':
						break;
					
					default:
						console.log(o);
				}
			});
		});
	});
	
	//bot.postMessageToChannel('general', 'hey yo');
	
	// var params = {
	//	icon_emoji: ':cat:'
	//};
	//bot.postMessageToChannel('general', 'meow!', params);
	//bot.postMessageToUser('username', 'meow!', params);
	//bot.postMessageToGroup('private_group', 'meow!', params);
	//
	// more information about additional params https://api.slack.com/methods/chat.postMessage
});