Search code examples
node.jsslack-apislack

How do I add a URL inside the field option in a Slack attachment?


I am trying to send notifications into the Slack channel from the external source. I am trying to put the URL link inside field tag of attachment. Is there a way to do that?

{
    "attachments": [
        {
            "fallback": "Required plain-text summary of the attachment.",

            "color": "#36a64f",

            "pretext": "Optional text that appears above the attachment block",

            "author_name": "Bobby Tables",
            "author_link": "http://flickr.com/bobby/",
            "author_icon": "http://flickr.com/icons/bobby.jpg",

            "title": "Slack API Documentation",
            "title_link": "https://api.slack.com/",

            "text": "Optional text that appears within the attachment",

            "fields": [
                {
                    "title": "Priority",
                    "value": "High",
                    "short": false
                }
            ],

            "image_url": "http://my-website.com/path/to/image.jpg",
            "thumb_url": "http://example.com/path/to/thumb.png"
        }
    ]
}

Solution

  • Yes, you can use URLs in fields. But it only works in the value tag. There you can even use markup.

    Here is an example in PHP:

    $slack->addAttachment( array (
        "fallback" => "Fallback",
        "title" => "Title",
        "text" => "text",
        "fields" => array (
            array (
                "title" => "Priority",
                "value" => "<http://i.imgur.com/nwo13SM.png|test>",
                "short" => false
            )
            )
        ));