55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import os
|
|
from dotenv import load_dotenv
|
|
from slack_sdk import WebClient
|
|
from pathlib import Path
|
|
|
|
load_dotenv()
|
|
|
|
def test_slack_connection():
|
|
"""Test basic Slack connection and bot setup"""
|
|
|
|
token = os.getenv("SLACK_TOKEN")
|
|
|
|
if not token:
|
|
print("❌ SLACK_TOKEN not found in .env file")
|
|
return False
|
|
|
|
print(f"✓ SLACK_TOKEN found: {token[:10]}...")
|
|
|
|
try:
|
|
client = WebClient(token=token)
|
|
|
|
# Test authentication
|
|
auth_response = client.auth_test()
|
|
|
|
if auth_response["ok"]:
|
|
print(f"✓ Bot authenticated successfully!")
|
|
print(f" Bot User ID: {auth_response['user_id']}")
|
|
print(f" Bot Username: {auth_response['user']}")
|
|
print(f" Team: {auth_response['team']}")
|
|
|
|
# Test listing channels
|
|
channels_response = client.conversations_list(types="public_channel,private_channel")
|
|
|
|
if channels_response["ok"]:
|
|
channels = channels_response["channels"]
|
|
print(f"\n✓ Found {len(channels)} channels:")
|
|
|
|
for channel in channels[:5]: # Show first 5
|
|
print(f" - {channel['name']} (ID: {channel['id']})")
|
|
|
|
if len(channels) > 5:
|
|
print(f" ... and {len(channels) - 5} more")
|
|
|
|
return True
|
|
else:
|
|
print(f"❌ Authentication failed: {auth_response}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error connecting to Slack: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("Testing Slack Connection...\n")
|
|
test_slack_connection() |