Sending posts to Slack, and even better structured data support

As hinted at a few weeks ago in our 3rd birthday post, you can now send posts from Ghost directly into your Slack team via a simple webhook integration!


This is a companion discussion topic for the original entry at https://blog.ghost.org/slack-integration/

you can now send posts from Ghost directly into your Slack team via a simple webhook integration

Is this the site.changed webhook as described here?: https://ghost.org/docs/api/v2/webhooks/

site.changed Triggered whenever any content changes in your site data or settings

Or is it something different?

I’d like to receive webhooks me too, from Ghost, when a new blog post gets published, and I’d need 1) the ids of the author(s) of the new blog post, and 2) the blog post Ghost comment_id and 3) its url. — I’m wondering, what data gets sent to Slack? The url I presume — and what about the author ids and the comment_id?

Background: I’m developing a blog commenting system (Talkyard), and if the above-mentioned data was included in the webhook, then this commenting system could automatically subscribe the relevant blog post author(s) in a multi-author blog to get notified about comment replies the blog readers post.

***

I notice in the screenshot there’s an “Apps” tab opened. — Can I create my own “App” in Ghost? What’s the difference between this Ghost-Slack “App”, and the integrations on the integrations page ? (Didn’t find anything when I websearched for “ghost app vs integration” :- ))

Howdy! :cowboy_hat_face: Slack is one of our Built-in Integrations which I believe does use the webhooks you linked to, but you can make your own Custom Integrations as well:

Note here that Custom Integrations has the same webhooks https://ghost.org/integrations/custom-integrations/#set-up-a-webhook

@DavidDarnes Ok, thanks. Then that webhook is probably the one I want to use — if it just includes enough information, I mean, not only blog post URL but also comment_id and author id. (The docs are a bit empty.)

I didn’t find documented anywhere what’s included in the webhook POST request body. If you (or someone) happen to know, it’d be interesting to know. (Or, I suppose I could install Ghost locally and send a request to http://webhook.site to find out)

@KajMagnus web hooks for individual resource events such as post.published contain the same information as a GET request to the resource in question in the Admin API. The webhook payloads have this general format:

{
    current: {
        ...all resource fields
    },
    previous: {
        ...only changed fields, with previous values
    }
}

I would suggest testing this for yourself so you can play with it and see how the data looks, there are a number of sites you can set up webhook captures on such as https://webhook.site as you pointed out.

RE the Slack integration, it uses an internal events system and talks directly to the Slack API. However using the webhooks system you could create your own Slack integration using the right webhook events - you can see the full list of those when setting up webhooks in the admin.

site.changed wouldn’t be very useful for this, it’s only a basic notification that something on the site has changed and doesn’t contain any information about what has changed. It’s designed for integration with static site generators where you’d want to rebuild each time anything changed.

1 Like