-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_slack_test.py
executable file
·48 lines (39 loc) · 1.42 KB
/
simple_slack_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
"""
Simple Slack API test script that mimics the curl command:
curl -H "Authorization: Bearer $SLACK_API_TOKEN" https://slack.com/api/conversations.list
"""
import os
import requests
import json
from dotenv import load_dotenv
# Load environment variables from .env file if it exists
load_dotenv()
# Get the Slack API token
SLACK_API_TOKEN = os.getenv("SLACK_API_TOKEN")
if not SLACK_API_TOKEN:
print("Error: SLACK_API_TOKEN environment variable is not set.")
exit(1)
print(f"Token prefix: {SLACK_API_TOKEN[:10]}...")
# Set up headers exactly like curl
headers = {
"Authorization": f"Bearer {SLACK_API_TOKEN}"
}
# Make the request without any additional parameters
print("\nMaking request to https://slack.com/api/conversations.list...")
response = requests.get("https://slack.com/api/conversations.list", headers=headers)
data = response.json()
# Print the full response for debugging
print(f"Status code: {response.status_code}")
print(f"Response OK: {data.get('ok')}")
print(f"Error (if any): {data.get('error')}")
# Print the number of channels if successful
if data.get("ok") and "channels" in data:
print(f"Found {len(data['channels'])} channels")
print("First few channel names:")
for i, channel in enumerate(data['channels'][:5]):
print(f" - {channel.get('name')}")
else:
print("Failed to get channels list")
print("Full response:")
print(json.dumps(data, indent=2))