Giter Site home page Giter Site logo

Comments (11)

metoikos avatar metoikos commented on July 30, 2024 16

@anonrig it's already in documentation.

bot.api.channels.list({},function(err,response) {
})

I've created simple solution for that, loading both users and channels on bot boot-up.

var fullTeamList = [];
var fullChannelList = [];
controller.spawn({
    token: config.get("slack_bot_key")
}).startRTM(function (err, bot) {
    if (err) {
        throw new Error(err);
    }

    // @ https://api.slack.com/methods/users.list
    bot.api.users.list({}, function (err, response) {
        if (response.hasOwnProperty('members') && response.ok) {
            var total = response.members.length;
            for (var i = 0; i < total; i++) {
                var member = response.members[i];
                fullTeamList.push({name: member.name, id: member.id});
            }
        }
    });

    // @ https://api.slack.com/methods/channels.list
    bot.api.channels.list({}, function (err, response) {
        if (response.hasOwnProperty('channels') && response.ok) {
            var total = response.channels.length;
            for (var i = 0; i < total; i++) {
                var channel = response.channels[i];
                fullChannelList.push({name: channel.name, id: channel.id});
            }
        }
    });
});

Now you can use both users and channels globally.

from botkit.

tonythomson avatar tonythomson commented on July 30, 2024

I believe this is a documentation error; bot.say() uses the RTM API, which expects a channel ID.

from botkit.

ZuzooVn avatar ZuzooVn commented on July 30, 2024

@metoikos What's your development environment?

from botkit.

metoikos avatar metoikos commented on July 30, 2024

Hello @ZuzooVn
OS X El Capitan

~  uname -a
Darwin rocko 15.0.0 Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
➜  ~  node --version
v4.2.2

from botkit.

ZuzooVn avatar ZuzooVn commented on July 30, 2024

I can not build the source code with

➜ ~ uname -a Darwin hostname.local 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64

➜ ~ node --version v5.0.0

from botkit.

metoikos avatar metoikos commented on July 30, 2024

I installed with npm install botkit command.
It generates some errors but it's not related to botkit, it is a bufferutil issue. You can check out at issue #2

from botkit.

anonrig avatar anonrig commented on July 30, 2024

@metoikos How do you learn the channel id?

from botkit.

tonythomson avatar tonythomson commented on July 30, 2024

We've drifted off-topic from the issue... @benbrown Any plans for a chatroom/forum/email list?

@anonrig A list of current channel IDs is available from the channel list API, but it's probably better to just use the data you get from the bot's initial connection to RTM, and then keep that list up to date. You can edit the file Slackbot_worker.js (see line 75 or so) to have the bot cache different data sets for the Slack team to which you're connecting (e.g. users, channels, IMs, etc.)

from botkit.

benbrown avatar benbrown commented on July 30, 2024

@tonythomson There is an open slack room waiting for you!! http://dev4slack.xoxco.com/ We've already got a botkit channel open and active.

from botkit.

PrajaktaNaik avatar PrajaktaNaik commented on July 30, 2024

How do I get the current channel name in which my bot is replying to the user.

from botkit.

jsullivanlive avatar jsullivanlive commented on July 30, 2024

@PrajaktaNaik I had the same question today and here's how I did it (you'll want to cache it since it hits the api):

    controller.hears(['test'], ['direct_message', 'mention'],  (bot, message) => {
        bot.api.channels.info({channel: message.channel}, (e, r) => {
            if (r && r.ok) bot.reply(message, 'channel name: ' + r.channel.name)
        })
    })

from botkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.