I want check slack app is added in slack channel. It works for public channel but it not work for private channel. For private channel, it always display "The app is not added to the channel."
from slack import WebClient
from slack.errors import SlackApiError
SLACK_API_TOKEN = "xoxb-******"
client = WebClient(token=SLACK_API_TOKEN)
def check_app_in_channel(channel_id, app_bot_user_id):
try:
channel_info = client.conversations_info(channel=channel_id)
print("Channel Info:", channel_info)
if 'members' in channel_info['channel']:
if app_bot_user_id in channel_info['channel']['members']:
return True
else:
return False
else:
print("Unable to retrieve members list for the channel.")
return False
except SlackApiError as e:
print(f"Error fetching channel info: {e.response['error']}")
channel_id = "C06QAP*****"
app_bot_user_id = "T065QF*****"
if check_app_in_channel(channel_id, app_bot_user_id):
print("The app is added to the channel.")
else:
print("The app is not added to the channel.")
I want code work for private channel.