Custom automation - modifications flow for successful integration on Automation plugin

Hi all,

I’m trying to create a custom automation that when a query is marked as solution/solved, the creator of the topic will receive a pms (or alternatively, a new reply is created in the thread with a pre-defined message - in both cases it would be a poll).

It needs to be a custom automation as the current available ‘send pms’ script into the automation plugin sends the pms to whomever has sent the reply that was marked as solution/solved (and not to the person who has created the topic, as intended in my use case).

Below is the script I have created to attempt to post a new reply in the topic once a reply is marked as solution (in the following sample, I’m not sending the poll as reply, just giving the freedom for the admin to choose what is going to be returned or let is as default):

# frozen_string_literal: true

DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::REPLY_ON_SOLUTION) do
    field :reply_text, component: :text
    # field :answering_user, component: :user
    field :once, component: :boolean
  
    version 1
  
    triggerables %i[:first_accepted_solution] if defined?(DiscourseSolved)
  
    placeholder :sender_username
    placeholder :word
  
    script do |context, fields, automation|
      topic = context["topic"]
      # user = context["user"]
      reply_text = fields.dig("reply_text", "value")
  
      # Post a reply in the topic where a solution was marked
      PostCreator.create!(
        Discourse.system_user,
        topic_id: topic.id,
        raw: reply_text || "A solution has been marked for this topic!",
      )
    end
  end

But I’m not sure if it should be PostCreator.create!, or PostCreator.reply, or perhaps something else. What brings me to one question:

  • Is there anywhere documented the keywords to be used during a custom automation script creation?

Based on the above automation, once I trigger it marking a reply as solution, after 1s I’m getting a pop-up message with a 500 internal server error message on the screen.

  • Am I missing something? My deployment was done using devcontainers, in my local machine for development test purposes.
  • What is necessary to do, after creating the custom script? Maybe I am missing something in this phase? Or maybe it is problem in the script itself?
  • Is anywhere documented, the steps to proceed after your script is done? For instance: which files needs to be modified in order to everything work smoothly? (I found hard way I needed to change the client.en.yml for the correct name and description shows in the automation list)

I’m planning to give it an attempt, based in the send pms built-in script, to change my script for instead of create a reply, send the pms, but not sure on the following:

  • how I would tag the person who had created the topic and not the one that had the reply marked as solution?

Thank a lot in advance for any pointers and help.

Did you follow this guide?