# Custom automation - modifications flow for successful integration on Automation plugin

**URL:** https://meta.discourse.org/t/custom-automation-modifications-flow-for-successful-integration-on-automation-plugin/350141
**Category:** Development
**Created:** [February 2, 2025, 3:48pm UTC](https://meta.discourse.org/t/custom-automation-modifications-flow-for-successful-integration-on-automation-plugin/350141 "2025-02-02T15:48:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ddsongs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ddsongs/32/471200_2.png) [@ddsongs](https://meta.discourse.org/u/ddsongs)
#### Post date: [February 2, 2025, 3:48pm UTC](https://meta.discourse.org/t/custom-automation-modifications-flow-for-successful-integration-on-automation-plugin/350141/1 "2025-02-02T15:48:17Z")

</div>

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):

```plaintext
# 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.

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [February 2, 2025, 11:12pm UTC](https://meta.discourse.org/t/custom-automation-modifications-flow-for-successful-integration-on-automation-plugin/350141/2 "2025-02-02T23:12:33Z")

</div>

Did you follow this guide?

> [@Create custom Automations](https://meta.discourse.org/t/create-custom-automations/275931):
>
> information_source This is a draft, and may need some extra work. 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 Plugin API add\_automation\_scriptable(name, &block) add\_automation\_triggerable(name, &block) Scriptable AP…

---

<div class="post-metadata">

### Author: ![ddsongs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ddsongs/32/471200_2.png) [@ddsongs](https://meta.discourse.org/u/ddsongs)
#### Post date: [February 4, 2025, 2:17pm UTC](https://meta.discourse.org/t/custom-automation-modifications-flow-for-successful-integration-on-automation-plugin/350141/3 "2025-02-04T14:17:24Z")

</div>

Hi @NateDhaliwal ,

Many thanks for your reply.

Yes, I have followed that guide… I will comment the guide with some suggestions afterwards.

I made the custom automation work btw.

The problem with the 500 internal server error was that I was tagging the wrong “context”, I found it out looking at the logs and tagging the correct one.

Once the content of the right context was added to a variable, the 500 internal server error was solved.

Further logic in the code was also modified.

Edit: To make the custom automation work in my local deployed instance I had to modify also the following files:

## Create your custom automation script

## Update: server.en.yml

add custom automation name; title; and description on the scriptables section of the yml file.

## Update: client.en.yml

add custom automation name on scriptables; add the ‘field’ keyword; inside field keyword add ‘field\_name’ followed by ‘label’ and ‘description’

## Update: scripts.rb

add the custom automation name in the list of scripts. Sample: FILE\_NAME = “file\_name”

## Update: plugin.rb

inside ‘after\_initialize do’, add the path to the custom automation script. Sample: ‘lib/discourse\_automation/scripts/file\_name’

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 6, 2025, 2:18pm UTC](https://meta.discourse.org/t/custom-automation-modifications-flow-for-successful-integration-on-automation-plugin/350141/4 "2025-03-06T14:18:12Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
