from slackclient import SlackClient
import json

slack_client = SlackClient('SLACKBOT TOKEN GOES HEE')


a = slack_client.api_call("api.test")
print a

b = slack_client.api_call("auth.test")
print b


def list_channels():
    channels_call = slack_client.api_call("channels.list")
    if channels_call.get('ok'):
        return channels_call['channels']
    return None
    
def channel_info(channel_id):
    channel_info = slack_client.api_call("channels.info", channel=channel_id)
    if channel_info:
        return channel_info['channel']
    return None
    
def channel_history(channel_id):
    channel_history = slack_client.api_call("channels.history", channel=channel_id)
    if channel_history:
        return channel_history
    return None
    
def send_message(channel_id, message):
    slack_client.api_call(
        "chat.postMessage",
        channel=channel_id,
        text=message,
        username='pythonbot',
        icon_emoji=':robot_face:'
    )
    
channels = list_channels()
if channels:
    print("Channels: ")
    for c in channels:
        print(c['name'] + " (" + c['id'] + ")")
        detailed_info = channel_info(c['id'])
        if 'latest' in detailed_info:
            print(detailed_info['latest']['text'])
else:
    print("Unable to authenticate.")

#channelInfo = 'XXXXXXXXXX'
#print 'Attempting to pull history for %s' %channelInfo
#thechannelhistory = channel_history(channelInfo)
#if 'messages' in thechannelhistory:
#    print json.dumps({'channel_info': channelInfo, 'messages': thechannelhistory },indent=4)

#send_message('XXXXXXXXX', "hello from the internet")

#thechannelhistory = channel_history(channelInfo)
#if 'messages' in thechannelhistory:
#    print json.dumps({'channel_info': channelInfo, 'messages': thechannelhistory },indent=4)