Post to Slack with Volto#

This guide shows you how to create a content rule that posts a message to Slack, using Volto. As an example, the rule reports every user login to a Slack channel.

Prerequisites#

Create the content rule#

  1. Open Site Setup ‣ Content Rules.

    The Content Rules control panel in Volto
  2. Select Add content rule.

  3. Enter a Title, such as User Logged In, and an optional Description.

  4. In Triggering event, select User Logged in, and save the form.

    The form to add a content rule, with the User Logged in event selected
  5. In the list of rules, select Configure next to the new rule.

    The list of content rules, with the new rule marked as not assigned

Add the Slack action#

  1. Under Perform the following actions, select Post a message to Slack in the Action list, and select Add.

    The page to configure the content rule, with Post a message to Slack selected
  2. Fill in the form. The Slack action describes every field.

    The empty form to add a Slack action

    Use ${...} variables to include details about what triggered the rule. This example uses the full name of the user who logged in.

    The Slack action form, filled in with the user_fullname variable
  3. Save the form.

The action appears under Perform the following actions.

The page to configure the content rule, listing the Slack action

Assign the rule#

A rule runs only in the places it is assigned to. To run it on the whole site, assign it at the site root.

  1. Go to the site root, and open Rules from the actions menu of the toolbar.

  2. In Available content rules, choose the rule, and select Add.

    The content rules page of the site root, with the rule selected

The rule now appears as enabled, and applies to subfolders.

The content rules page of the site root, listing the assigned rule

To run the rule only inside a folder, go to that folder, and assign the rule from its Rules page instead.

Check the result#

Log in to the site in another browser. A message appears in the Slack channel.

The message posted to Slack after a user logged in

If no message appears, check the Plone backend log for errors from the contentrules.slack logger. Python API lists the messages it writes.