내가 작성한 Ruby 플러그인을 설치하는 방법은 무엇인가요?

디스코urs 사용자 이메일이 포함된 CSV 파일이 있습니다. 매일 실행되어 특정 사용자 집단에 특정 이메일 템플릿을 보내는 스크립트를 만들어야 합니다. 그리고 매일 이 스크립트를 다음 사용자 집단을 대상으로 실행해야 합니다. 어떻게 하면 될까요?

https://ask.discourse.com/ 에 따르면, 이 작업을 자동화하기 위해 코드를 작성하고 해당 코드와 데이터를 plugins 폴더에 배치해야 한다고 합니다. 코드 제안은 다음과 같습니다:

# frozen_string_literal: true
# name: auto-email
# about: A custom plugin to send bulk emails using automation and CSV files
# version: 0.3

require 'csv'

after_initialize do
  if defined?(DiscourseAutomation)
    # Define a unique scriptable for the automation
    DiscourseAutomation::Scriptable::AUTO_EMAIL_SCRIPT = "auto_email_script"

    add_automation_scriptable(DiscourseAutomation::Scriptable::AUTO_EMAIL_SCRIPT) do
      # Define fields for the automations UI:
      field :email_template, component: :message # Email body to be sent
      field :csv_file_name, component: :text # Name of CSV file in the "data" folder

      script do |context, fields, automation|
        # Define the path to the data folder
        data_folder_path = Rails.root.join("plugins", "auto-email", "data")

        # Get the CSV file name from the admin automation field
        csv_file_name = fields["csv_file_name"]["value"]
        csv_file_path = File.join(data_folder_path, csv_file_name)

        # Ensure the file exists
        unless File.exist?(csv_file_path)
          Rails.logger.warn("CSV file #{csv_file_path} not found!")
          next
        end

        # Parse the CSV file
        begin
          users = CSV.read(csv_file_path, headers: true).map(&:to_hash)
        rescue StandardError => e
          Rails.logger.error("Error reading CSV file (#{csv_file_name}): #{e.message}")
          next
        end

        # Get the email message content from the automation field
        email_body = fields["email_template"]["value"]

        # Iterate through users from the CSV and send emails
        users.each do |user_data|
          email = user_data["email"] || user_data["normalized_email"]
          user = User.find_by_email(email)
          
          if user
            begin
              # Send an automated email using SystemMessage
              SystemMessage.new(user).send_email(
                "custom_email_template", # Ensure this email template exists
                message_body: email_body
              )
              Rails.logger.info("Email sent to: #{email}")
            rescue StandardError => e
              Rails.logger.error("Failed to send email to #{email}: #{e.message}")
            end
          else
            Rails.logger.warn("No user found with email: #{email}")
          end
        end
      end
    end
  end
end

그리고 제 플러그인 구조는 다음과 같습니다:
/var/discourse/plugins/auto-email/
├── README.rb
├── data/
├── mamapedia_users_data_01.csv
├── lib/
├── plugin.rb

하지만 앱을 재시작하거나 재빌드해도 관리자 패널에서 새 플러그인을 볼 수 없습니다. 로그에는 오류가 표시되지 않습니다.

무엇을 잘못하고 있는 걸까요? 다른 조치를 취해야 하나요?

디스코urs 플러그인 개발 - 1부 - 기본 플러그인 만들기부터 시작하는 것을 추천합니다.

그 방법을 시도해 보았는데, 아주 간단합니다. 하지만 불행히도 제 환경에서는 작동하지 않습니다.

같은 솔루션을 두 개의 다른 앱에서 테스트해 보았습니다. 제가 사용한 plugin.rb 파일은 다음과 같습니다:

# name: auto-email
# about: 플러그인의 작동 방식을 보여주는 아주 간단한 플러그인
# version: 0.0.1
# authors: Xavier Garzon

컨테이너의 플러그인 폴더(/var/www/discourse/plugins)도 확인해 보았는데, 제 플러그인이 복사되지 않은 것 같습니다. 이것이 문제의 일부일 수도 있습니다.

두 번째 테스트에서는 다음 명령어도 시도해 보았습니다:

./launcher rebuild app --clean

그리고

./launcher restart app

현재 실행 중인 버전은 다음과 같습니다:
3.4.0.beta4-dev
(9f41ce7fce)

플러그인을 GitHub 저장소에 올렸나요?

plugin.rb를 단순히 /lib에 넣는 것으로는 안 되며, 반드시 plugins 폴더에 있어야 합니다. 또한 프로덕션 환경에서는 셀프호스팅 사이트에 플러그인 설치하기에 설명된 대로 GitHub를 통해 추가해야 합니다.

네. 거기에 없다면 없는 것입니다.

해당 플러그인 관련 주제들을 모두 꼼꼼히 읽어보시는 것이 좋습니다. 또한 개발 환경에서 테스트를 수행하는 것도 중요합니다.