os / slacker

Full-featured Python interface for the Slack API
Apache License 2.0
1.6k stars 245 forks source link

get_channel_id function added #12

Closed juanpabloaj closed 9 years ago

juanpabloaj commented 10 years ago

Some slack API methods need the channel id, not the channel name, like files.upload.

Channel id ('C02GXXYZ') is different to the channel name ('test').

Example:

>>> from slacker import Slacker
>>> from slacker.utils import get_channel_id
>>> token = "aaa"
>>> channel_id = get_channel_id(token, 'test')
>>> slack = Slacker(token)
>>> slack.files.upload('index.png', channels=channel_id)
juanpabloaj commented 10 years ago

for run tests

python setup.py test

or with nosetest

nosetest
juanpabloaj commented 10 years ago

other option is add the function like a method in Channels class.

os commented 10 years ago

Thanks for this, @juanpabloaj. When I was implementing slacker, I just wanted to make it as close as possible to the original API, so it's passing exactly the same parameters, with the same order.

Unfortunately, Slack API is not very consistent with the use of channel name/ID. When some APIs are passing channel name as a channel parameter, the others are passing channel ID.

A function like this could be useful, but I would go with the second option, get_channel_id method on Channels class. If you could make those changes, I would be happy to merge it into master.

juanpabloaj commented 10 years ago

@os ok, now get_channel_id is a method of channels class.

os commented 9 years ago

Thanks @juanpabloaj. tests/init.py was missing, but I just fixed it so it's all good.