Automations

Automations can be managed from the Admin panel. They can be found under Settings -> Automations.

Each automation consists of 3 parts:

  1. Trigger
  2. Condition
  3. Action

If you are seeing any triggers, conditions or actions that are not in the documentation below, they are probably added by a plugin, and you should refer to their documentation.

The trigger decides when to execute the action. Triggers also provide the payload which is available in the condition and action.

forumify currently ships with the following triggers:

Execute: After an entity is created in the database.

Payload:

  • entity: object

Execute: After an entity is updated in the database.

Payload:

  • entity: object

Execute: After an entity is removed from the database.

Payload:

  • entity: object

Once the automation is triggered, conditions make it easier to decide wether to continue with the action or not.

For example, if the trigger is set to "Doctrine: Persist", and the entity is "Topic", a condition can filter only for topics created in a specific forum.

Learn more: Symfony Expression Language

While the trigger and condition run synchronously, the action is executed in a message queue worker to prevent a slow running action from impacting user experience. This means that sometimes the automation may seem to "lag behind" a little bit.

Sends a POST request to the given webhook URL.

For example, to send data to Zapier:

  • Webhook URL: The webhook URL given by Zapier (Catch Raw Hook)
  • Data: The data sent to Zapier, for example with a Doctrine Topic trigger:
{{ {
    topic: entity.title,
    content: entity.firstComment.content
}|json_encode|raw }}

The example creates the data object, then JSON encodes it and dumps the raw output. This method is recommended since it takes care of escaping quotes and slashes which may break your JSON.

Call any external API using a HTTP request.

Cross-post your topics to a Discord channel using a Discord Webhook.

  • Name: News to Discord
  • Enabled:
  • Trigger: Doctrine: Persist
  • Entity: Forumify\Forum\Entity\Topic
  • Condition: Expression
  • Expression: entity.getForum().getSlug() == 'news'
    • You can find the slug of a forum by visiting it in a browser. https://example.org/forum/ this-part-here,
  • Webhook URL: https://discord.com/api/webhooks/id/token
    • Use the Copy Webhook URL button after creating a webhook in Server Settings -> Integrations -> Webhooks -> New Webhook.
  • Data: Something compatible with Discord's webhook execution format. For example an embed:
{{ {
    embeds: [
        {
            title: entity.title,
            description: entity.firstComment.content|html_to_markdown({
                strip_tags: true,
                hard_break: true,
                header_style: 'atx',
                remove_nodes: 'img',
            })|u.truncate(4000, '...', false),
            url: absolute_url(path('forumify_forum_topic', { slug: entity.slug })),
        }
    ]
}|json_encode|raw }}

You can do even more, like prefixing it with a message that includes a link to the forum and the author:

{% set user = entity.createdBy %}
{% set userLink = '[' ~ user.displayName ~ '](' ~ absolute_url(path('forumify_forum_profile', { username: user.username })) ~ ')' %}
{% set forumLink = '[' ~ entity.forum.title ~ '](' ~ absolute_url(path('forumify_forum_forum', { slug: entity.forum.slug })) ~ ')' %}
{{ {
    content: userLink ~ ' just posted a new topic in ' ~ forumLink,
    embeds: [...]
}|json_encode|raw }}

Zapier allows you to build incredibly complex automation workflows with tons of templates. Like creating Facebook posts, sending emails, asking ChatGPT, insert into a spreadsheet,...

You can use forumify automations as a trigger for a Zapier workflow.

  • Name: Events To Zapier
  • Enabled:
  • Trigger: Doctrine: Persist
  • Entity: Forumify\Calendar\Entity\CalendarEvent
  • Condition: Expression
  • Expression: entity.getCalendar().getSlug() == 'workshops'
    • You can find the slug of a calendar by visiting it in a browser. https://example.org/calendar/ this-part-here,
  • Webhook URL: https://hooks.zapier.com/hooks/catch/id1/id2/
    • When you create a Zapier Catch Hook trigger, it will automatically generate a Webhook URL for you to use.
  • Data: The format for Zapier isn't strict so we just give it the fields we want to use.
{{ {
    title: entity.title,
    start: entity.start|date('Y-m-d H:i:s'),
    content: entity.content,
    calendar: entity.calendar.title
}|json_encode|raw }}

If you trigger the automation at least once, your data will become available in Zapier's UI and you can build the rest of your workflow there.