Friday 24 February 2023

SlackAPIPostOperator unable to send to private slack channel.

 
I am using SlackAPIPostOperator from an Airflow Dag.  And have successfully made a bot that will send messages to my Slack Channel 

slack_post = SlackAPIPostOperator(
task_id="slack_notification",
channel="#my_slack_channel",
username="airflow",
text="A test message from Airflow. Please ignore",
token="#######",
dag=dag,
)


However, when I use the same logic on a Private channel it wouldn't work.  And I couldn't see my bot to be able to 'invite' it to the channel.  


To fix this ...

To grant your bot permission to join private channels, you will need to ensure that it has the channels:join and channels:read OAuth scopes. Here’s how you can check and modify your bot’s scopes:
  1. Go to the Slack API website and navigate to the “OAuth & Permissions” section of your app’s settings.
  2. Scroll down to the “Scopes” section and check that your bot has the channels:join and channels:read scopes.
  3. If the scopes are not already added, click on the “Add an OAuth Scope” button and select the scopes from the dropdown list.
  4. After adding the scopes, make sure to re-install your app in the workspace to apply the changes.
After , that I had to re-invite the Bot to the Private Channel  ( through the add people ) and it worked.