What is the correct process for custom automation?

I am a beginner and have some questions about the Create Custom Automations tutorial.

I first tried writing the automation script directly in the GitHub Codespace development environment (I don’t understand the syntax; the code was written by Claude).
After modification, the file structure should look like this:

plugins/automation/
├── lib/
│   └── discourse_automation/
│       ├── scripts.rb                 # Modified
│       └── scripts/
│           ├── ...                    # Other scripts
│           └── remove_expired_group_members.rb  # Added
└── config/
    └── locales/
        ├── server.en.yml              # Modified
        ├── client.en.yml              # Modified
        ├── server.zh_CN.yml           # Modified
        └── client.zh_CN.yml           # Modified

However, I am unsure if this operation is permissible in a production environment.
Furthermore, I am unsure if these modifications will be lost during a rebuild or an update to the automation plugin, so I dare not try it in the production environment. Perhaps I should submit a feature request for the plugin maintainers to add it?

I hope experienced friends can inform me about the correct procedure from writing tests to applying changes in the production environment.
Thank you very much!

1 Like

I believe it will have to be in a new plugin.

You can check out:

3 Likes

I have checked the link you provided.
Could you please explain to me why I should use plugins instead of creating scripts within the automation plugin?

  1. I am not a professional, and creating plugins seems more difficult.
  2. I have many functions that need to be implemented, which seems like it would require creating many plugins? (Although I also like plugins because they can be shared.)
1 Like

If I’m not wrong, if you make changes to the plugin, it will be overwritten the next time there’s an update.

4 Likes

OK, that’s what I was afraid of.
So the custom automation feature doesn’t seem to mean much to the user? :joy:
I’ll check the documentation again, and if that doesn’t work, I’ll try creating a plugin.

2 Likes

I think the tutorial (which is a draft) is lacking this information. It explains how to create new automations, but not where to do it. The answers mention plugin examples though, like the one linked by @NateDhaliwal.

Simon also suggests having a look at the data explorer plugin: Create custom Automations - #6 by simon.

Depends what you mean by “user”? :smile: As a developer, you can surely create a new plugin that adds automations. This is the way to do it properly.

Since you mention not understanding code, but being able to use AI for this, perhaps you’ll find this discussion interesting. Claude & Discourse-related development. How good is it?.

I’m currently experimenting with this (but I do have vague notions of code – not enough to create even a simple plugin by myself!), and will share my recent experience with it soon.

Since Claude directed you to edit the automation plugin, you may want to refine your prompts and have the AI follow actual good practices.

3 Likes

No. What makes it a custom automation is that it’s not one that is built in. You’ll need to add a new one in a plugin. GitHub - scossar/automation-script-example: An example of how to add a custom script to the Discourse Automation plugin., linked in the tutorial. You can start with that and try telling whatever AI that you want to add a new customization.

What do you want your custom automation to do?

1 Like

I need an automation script that can automatically remove group members whose membership has expired.
Set the group and duration, and users will be automatically removed upon expiration.

For example:
Setting: VIP Group, 30-day duration.
When a user joins the VIP group, they are removed after 30 days.

I am increasingly confused about whether the automation plugin can save scripts that I write myself (previous comments indicated they might be overwritten).

If it were you, how would you typically use the automation plugin?
Could you accurately describe your usage method (when the built-in scripts and triggers of the automation plugin cannot meet the needs)?
I think I can learn how custom features work from your scenario description.

How are users added to the vip group? Or probably makes sense to have whatever adds them to the group to also remove them. That’s what the subscription plugin does, for example.

Automations are not removed, but editing code in your container is.

You need a trigger for when a user is added to a group, and an action to remove them from a group after a period of time. I’m not sure how easy that is to do.

1 Like