from slack import WebClient
import os
import json

#slack config
slack_token = os.environ["SLACK_API_TOKEN"]
client = WebClient(token=slack_token)

#getting user info from slack
def get_user_info(user_id):
    response = client.api_call(
        api_method='users.info',
        params={'user': user_id},
        headers= {'Content-Type': 'application/x-www-form-urlencoded'}
    )
    return response
    
#posting message info to slack
def post_message(message,ts):
    response = client.api_call(
        api_method='chat.postMessage',
        params={'channel': 'testing-slack-integration','text':message, 'thread_ts':ts}
    )
    return response
    
#posting message info to slack
def route_message_to_channel(message,tag):
    channel = 'other-issues'
    channelmap = json.loads(os.environ["CATEGORY_CHANNEL_MAP"])
    if tag in channelmap.keys():
        channel = channelmap[tag]
    print(channel)
    response = client.api_call(
        api_method='chat.postMessage',
        params={'channel': channel,'text':message}
    )
    return response