Slack отправить вложение, возвращающее 500 ошибка - PullRequest
0 голосов
/ 30 мая 2018

Я пытаюсь отправить вложение на веб-крючок Slack.

Я следовал документации по API и могу отправить простое сообщение.Когда я пытаюсь отправить вложение, я получаю ошибку 500, я предполагаю, что есть проблема с моей полезной нагрузкой, но я не могу решить ее на всю жизнь.

Как мне получить вложение, чтобы опубликовать успешно?

import slackweb

slack = slackweb.Slack(url='WEB HOOK URL HERE')

slack.notify(text="Maguro is a sushi")

attachments = []
attachment = {
    "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",
            "footer": "Slack API",
            "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
            "ts": 123456789
        }
    ]
}

attachments.append(attachment)
slack.notify(attachments=attachments)

1 Ответ

0 голосов
/ 30 мая 2018

В вашем сообщении Slack отсутствуют два обязательных поля с вложениями: text и channel.Вам также нужно уменьшить значение поля short до false.

См. Исправленное сообщение здесь в тестере сообщений Slack :

{
    "text": "You need this field",
    "channel": "C########",
    "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",
            "footer": "Slack API",
            "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
            "ts": 123456789
        }
    ]
}

Создайте структуру JSON, включающую эти два поля и переменную attachments, и вы должныхорошо идти.

...