Discourse-automation

Summary: Discourse Automation lets you automate actions through scripts and triggers. Customisation is made through an automatically generated UI.

:link: GitHub: GitHub - discourse/discourse-automation
:arrow_right: Install: Follow the plugin installation guide.

Features

  • Easy automation of complex workflows
  • Triggers automations at specific dates, periodically, or on specific events
  • Provides automatically generated UIs to specify options for your automation

Vocabulary

  • trigger: represents the name of the trigger, eg: user_added_to_group
  • triggerable: represents the code logic associated to a trigger, eg: triggers/user_added_to_group_.rb
  • script: represents the name of the script, eg: send_pms
  • scriptable: represents the code logic associated to a script, eg: scripts/send_pms.rb

Configuration

Automations can be created and updated from Admin → Plugins → Automations, or directly from /admin/plugins/discourse-automation.

Available scripts

Script name Plugin Description
Banner Topic automation convert a topic into a banner notice
Flag post on Words automation flag a topic on creation/edition if it contains specific words
Gift Exchange automation simple implementation of the secret santa game
Pin Topic automation pin and unpin a topic in the future
Send PMs automation send PMs with support for placeholders
Suspend User By Email automation suspend a user for a specified duration
Topic required words automation enforce the presence of at least one of the specified words in the posts of a topic
Auto Responder automation given a series of keywords and associated replies, automatically respond with the corresponding reply
User Global Notice automation presents a global notice on the site for a specific user
Random Assign assign assign a random user from a given group to the given topic

Available triggers

Note that due to their nature, each script only supports certain triggers. For example it wouldn’t make sense for a script enforcing the content of a post to trigger when a user is added to a group.

Trigger name Plugin Description
API Call automation triggers when a certain API endpoint is called
Recurring automation triggers at intervals ranging from every minute to every year
Point in Time automation triggers at a specific date and time
Post created/edited automation triggers when a post of a specified topic is created or edited
User added to group automation triggers when a user is added to a group
User promoted automation triggers when a user is promoted from one specified trust level to another, or for all of them
Stalled wiki automation triggers when a wiki hasn’t been edited for a while
First accepted solution solved triggers when a user achieves their first accepted solution

More scripts and triggers to come!

Plugin API

add_automation_scriptable(name, &block)
add_automation_triggerable(name, &block)

Scriptable API

field

field :name, component: lets you add a customisable value in your automation’s UI.

List of valid components:

# foo must be unique and represents the name of your field.

field :foo, component: :text # generates a text input
field :foo, component: :list # generates a multi select text input where users can fill values
field :foo, component: :choices, extra: { content: [ {id: 1, name: 'your.own.i18n.key.path' } ] } # generates a combo-box with a custom content
field :foo, component: :boolean # generate a checkbox input
field :foo, component: :category # generates a category-chooser
field :foo, component: :group # generates a group-chooser
field :foo, component: :date_time # generates a date time picker
field :foo, component: :tags # generates a tag-chooser
field :foo, component: :user  # generates a user-chooser
field :foo, component: :pms  # allows to create one or more PM templates
field :foo, component: :categories  # allows to select zero or more categories
field :foo, component: :key-value  # allows to create key-value pairs
field :foo, component: :message  # allows to compose a PM with replaceable variables
field :foo, component: :trustlevel  # allows to select one or more trust levels
triggerables and triggerable!
# Lets you define the list of triggerables allowed for a script
triggerables %i[recurring]

# Lets you force a triggerable for you script and also lets you force some state on fields
field :recurring, component: :boolean
triggerable! :recurring, state: { foo: false }
placeholders
# Lets you mark a key as replaceable in texts using the placeholder syntax `%%sender%%`
placeholder :sender

Note that it’s the responsibility of the script to provide values for placeholders and to apply the replacement using input = utils.apply_placeholders(input, { sender: 'bob' })

script

This is the heart of an automation and where all the logic happens.

# context is sent when the automation is triggered, and can differ a lot between triggers
script do |context, fields, automation|
end

Localization

Each field you will use will depend on i18n keys and will be namespaced to their trigger/script.

For example a scriptable with this content:

field :post_created_edited, component: :category

Will require the following keys in client.en.yml:

en:
  js:
    discourse_automation:
      scriptables:
        post_created_edited:
          fields:
            restricted_category:
              label: Category
               description: Optional, allows to limit trigger execution to this category

Note that description is optional here.

44 Likes

Thank you, thank you!

5 Likes

Amazing idea! Literally 5min before I saw this we had a perfect use case for such a plugin. We are looking to automatically archive topics based on a date trigger so that users cannot give any more likes to its posts.

We have topics for monthly photocontests in which users post their photos and users can give likes to their favorites. From those the top 5 most liked go into a final voting. Only issue is that users can still like photo submissions even after the given deadline.

5 Likes

I would love for this this plugin to also optionally trigger chat-integration plugin, to trigger a reply or notification on associated chat systems as well.

If you’re taking feature requests at any point, I would love to automate the publishing and unpublishing of the global notice at https://thisismydiscoursesite.com/admin/site_settings/category/uncategorized

image

The fact that adding and removing a global notice is manual really cuts down on our ability to strategically use it to promote events or highlight other time sensitive things in our community.

4 Likes

Yes it could definitely go into core automation. :+1:

5 Likes

On 2.7.6 Stable there is no selectable calendar or trash can icon when creating an automation. Unsure of how to manually fill out Execute at to create a weekly, recurring pinned topic. Dates seem specific as opposed to a relative day of the week (Tuesday) or month.

1 Like

Can you show me a screen of what you are looking at please?

On master I correctly see this:
Capture d’écran 2021-07-19 à 16.27.04

1 Like

2.7.6 stable on Firefox 90.0 (64-bit)

I see a trash can icon after writing in a value.

image

1 Like

Sadly this component doesn’t work with firefox yet.

3 Likes

Thank you, works with Chromium.

Is it possible to trigger based on general day of the week? Looking to automate a recurring pinned topic rule.

Pin each Monday
Unpin each Tuesday

Currently the rule is defined as 7/26 at 7:45am pin through 7/27 at 11:59pm
I don’t see an option to set as recurring.

1 Like

ATM this script pin_topic is only working with point_in_time, could be made to work with recurring though.

3 Likes

Firefox can be used, at least for pinning topics in the plugin. Execute at and Pinned until must be typed in manually as displayed below:

image

2 Likes

Yes firefox treats it as a regular text input

4 Likes

Hi I was wondering if you could use this with Discourse Signatures → To enable Signatures on new user sign up?

If so how would one set this up? The discourse Signature plugin does not give option to have enabled by default.

2 Likes

Yes you could most likely, I dont know this plugin. It should be a PR to the plugin.

3 Likes

Waiting for this :taco:

This can really help.

3 Likes

Apparently this is planned to land in the Business plan, which is awesome. I’d like to not get too ahead of myself in imagination, though.

Could this be used to:

  • tag posts that come in via email (perhaps with stringent criteria)?
  • automatically suggest tags if no tags are given (not by email; via the web)?
  • set a topic timer for all new posts in a category?
  • act as a “smart” topic timer, removing replies that don’t have a certain keyword, or not enough likes, or similar?
  • move any post marked as wiki to be owned by a “wiki-bot” user (so it’s clear it’s not necessarily the first editor’s words)?
  • validate calendar plugin [date] entries to reject overlaps?

This isn’t a prioritized list, but they’re all off-the-top-of-my-head, things I’ve wanted at some point recently. :slight_smile:

1 Like

:+1:

:+1:

:+1:

:+1:

:+1:

Most likely not, depends of the exact expectations. But no live feedback on the UI.


None of these are currently done, but these are good ideas which shouldn’t be too hard to implement.

8 Likes

Thanks! How about these?

  • Automatically tag posts based on regexes, including a result of that regex? For example, if the text matches /Fedora ((Linux|Workstation) )?(\d\d)/, tag with fedora-linux-$2 (matching the second ()).

  • After some time (13 months, in my use case) with no activity, close posts and move to an Archive category (to help implement How should category archiving work? - #9 by mattdm), except pinned posts, and possibly conditional upon tags, number of likes/votes

  • Make a web query and respond based on the result? In my specific case, I want to query our bug tracker, and create, edit, or move topics and replies based on specific fields in the result.

3 Likes