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.

Wednesday 4 January 2023

In Wagtail GeoLocation Widget how to set a Default location ( and set zoom )

 To set the default map location in the wagtailgeowidget package, you can define the GEO_WIDGET_DEFAULT_LOCATION setting in your Django settings file.

Here is an example of how to do this:

GEO_WIDGET_DEFAULT_LOCATION = {"lat": 50.5230, "lng": -4.6558}

This will set the default map location to the coordinates 50.5230° N, 4.6558° W (Bodmin, Cornwall, United Kingdom).

The GEO_WIDGET_DEFAULT_LOCATION setting should be a dictionary with keys 'lat' and 'lng' representing the latitude and longitude, respectively. The values should be float values.

You can also set the default map location dynamically based on the value of a field in your model by defining a callable as the value of the GEO_WIDGET_DEFAULT_LOCATION setting.

Here's an example of how to do this:

from django.conf import settings def get_default_location(): # Code to retrieve default location from model goes here return {"lat": 50.5230, "lng": -4.6558} GEO_WIDGET_DEFAULT_LOCATION = get_default_location

This will set the default map location to the value returned by the get_default_location function.