Airflow SlackWebhookOperator to send message to slack

47 Views Asked by At

i'm using SlackWebhookOperator to send message to slack channel but my problem is the format.

I have to send a list of active and clickable urls but when i send the list, some urls are not active like the others.

is there a way to manage that like markdown or else ?

i need also to manage special characters in text additionnally to avoid utf8

"https://url1.com/ext","https://url2.com/ext","< https://url3.com/ext >"

the first two links are clickable but the third isn't and i didn't understand how the '< >' have been added because all links are like the first two

so i would like to have all links active and clickable and printed with a return at a new line like this :

"https://url1.com/ext" "https://url2.com/ext" "https://url3.com/ext"

1

There are 1 best solutions below

0
Andrey Anshin On

You could use Block Kit for the reach formatting your messages.

There is also simple example how to use it with SlackWebhookOperator in slack provider guide

slack_webhook_operator_blocks = SlackWebhookOperator(
    task_id="slack_webhook_send_blocks",
    slack_webhook_conn_id="your-awesome-slack-webhook-conn-id",
    blocks=[
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": (
                    "*<https://github.com/apache/airflow|Apache Airflow™>* "
                    "is an open-source platform for developing, scheduling, "
                    "and monitoring batch-oriented workflows."
                ),
            },
            "accessory": {
                "type": "image", 
                "image_url": "https://raw.githubusercontent.com/apache/airflow/main/airflow/www/static/pin_100.png",
                "alt_text": "Pinwheel"
            },
        }
    ],
    message="Fallback message",
)