我正在尝试使用 slack API 发布图像。我目前打开了两个 API(使用 python),即 rtm 和 slackbot。
sc = SlackClient(API_KEY)
sc.api_call('chat.postMessages', channel=, text=) #post as bot
sc.rtm_connect():
sc.rtm_send_message(channel=..., message=...) #post as desired user
这些示例可以很好地将文本发布到频道,但我需要将图像发布到频道。
我想使用 rtm_* 方法发布图像,但我不知道如何。我看到的唯一图片参考是https://api.slack.com/docs/attachments但我看不到使用 rtm API 的方法。
任何帮助表示赞赏。TIA。
更新/编辑:
所以我尝试使用Jon
推荐的方法,即:
sc.api_call("chat.postMessage", channel='D0K7P9MCJ', text='postMessage test',
attachments='[{"image_url":"http://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg"}]')
但这似乎不起作用(没有发布图像)并且没有引发错误。
解决方案
我通过在附件部分包含一个标题来完成这项工作。希望它抛出一个错误,=/