Define the custom function in the dag :
sc = SlackClient(my_slack_token)
def slack_failed_task(contextDictionary, **kwargs):
base_url = mybasedUrl
task_instance = contextDictionary.get('task_instance')
log_url = '{task_instance.log_url}'.format(**locals())
failed_alert = sc.api_call('chat.postMessage',
link_names=1,
task_id='slack_failed',
channel='#mychannel',
icon_url='https://raw.githubusercontent.com/airbnb/airflow/master/airflow/www/static/pin_100.png';,
username='Airflow',
text = ':hankey: DAG Failed on dagid=*{task_instance.dag_id}* taskid=*{task_instance.task_id}* :page_facing_up: <{log_url}|see log> @mehdio :trollface: ? '.format(**locals()))
return failed_alert.execute
Then use on each task, on_failure_callback=slack_failed_task
For last version of the python slack client, the tag name doesnt work anymore, you need to specify id of the user via <@user_id>