Formatting posts with the Slack api

2020-03-26 13:51发布

问题:

I'm trying to create Posts with botkit using the Slack api, but I can't find any documentation on how to format a Post file in Slack.

bot.api.files.upload({
    content: "# Heading",
    filename: "test.md",
    filetype: "post",
    channels: "random"
});

Markdown formatting doesn't work for this, is there any syntax to formatting Slack Posts?

Trying with HTML the response from the created file is like this:

<document><p>&lt;document&gt;&lt;h1&gt;H1&lt;\/h1&gt;&lt;p&gt;&lt;\/p&gt;&lt;h2&gt;H2&lt;\/h2&gt;&lt;p&gt;&lt;\/p&gt;&lt;h3&gt;H3&lt;\/h3&gt;&lt;p&gt;&lt;\/p&gt;&lt;p&gt;Text &lt;i&gt;italic&lt;\/i&gt; &lt;b&gt;bold&lt;\/b&gt; &lt;a href=&quot;<a href=\"http:\/\/www.slack.com%22%3Elink%3C\/a%3E\">http:\/\/www.slack.com&quot;&gt;link&lt;\/a&gt;<\/a> &lt;u&gt;underline&lt;\/u&gt;&lt;\/p&gt;&lt;p&gt;&lt;\/p&gt;&lt;p&gt;&lt;strike&gt;strikethrough&lt;\/strike&gt;&lt;\/p&gt;&lt;p&gt;&lt;\/p&gt;&lt;p&gt;&lt;code&gt;Code Block;&lt;\/code&gt;&lt;\/p&gt;&lt;\/document&gt;<\/p><\/document>

so it's escaping html tags.

回答1:

Posts support markdown formatting.

E.g., try setting the following content:

# A Post Header

### Subheading

An image? ![Funny](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4jlx3aktZVFKAkaNB7fvy67BFQuaO3HedVQ6VIXeR5OLnfbOOEbrcp-G4)

[A link to google](https://www.google.com)

* A list item
* Another list item

`a code block`

You then post with filetype="post", and get the following:

I tested and slack appears to support most markdown features but not all. Make sure to test your formatting!



标签: slack-api