os / slacker

Full-featured Python interface for the Slack API
Apache License 2.0
1.6k stars 245 forks source link

Attachments not working. #30

Closed Panoplos closed 9 years ago

Panoplos commented 9 years ago

I am trying to post the following via slacker:

    attachment = {
        "attachments": [
            {
                "fallback": "Fallback text",
                "title": "Title",
                "fields": [
                    {
                        "value": "*some field data*",
                        "short": True
                    },
                    {
                        "value": "*some more data*",
                        "short": True
                    }
                ],
                "mrkdwn_in": ["fields"],
                "color": "good"
            }
        ]
    }
    slacker.chat.post_message(
        SLACK_CHANNEL,
        "Testing Attachments",
        SLACK_USER,
        attachments=attachment,
        icon_url=SLACK_ICON_URL
    )

Where I have set the constants to my settings, but you should be able to test this yourself.

image

Note, if I use json.dumps(attachment), the result is:

image

Which contains empty attachments.

gavinhodge commented 9 years ago

I had the same problem with a similar library, and the solution was to json.dumps(attachments).

Just be sure your attachments variable is a list not a dict. The library includes the "attachments": part for you. I hope this helps.

Jonovono commented 9 years ago

Ya json.dumps worked for me. I might submit a PR tomorrow. Feel like this should be handled.

For example you will assign attachments to something like:

att = [
        {
          "fallback": "A new review!",

        "color": "good",

        "pretext": ":musespinning: %s %s %s %s %s" % (full_star, full_star, empty_star, empty_star, full_star),

        "author_name": "super",

        "text": "cool"
    }
]
os commented 9 years ago

Fixed in #35. Closing.

os commented 9 years ago

Thanks everyone.