プラグインからメールアドレスにPMを送信

こんにちは。

プラグインを構築しており、ユーザーのメールに何かを送信する必要があります。

次を使用しています。

      creator = PostCreator.new(test_user, {
        target_recipients: "someone@toto.com",
        archetype: Archetype.private_message,
        subtype: TopicSubtype.system_message,
        title: "Hello test subject",
        raw: "This is the message. Does it work ?"
      })

test_user は管理者です。

しかし、これを使用して送信しようとするたびに、「トピックが空です」というエラーが発生します。

何か考えはありますか?

仕様によると、グループ名またはユーザー名を受け取るはずです。

「いいね!」 2

こんにちは、ロバートさん。

それは奇妙ですね。フロントエンドでは、Discourse は次のようなペイロードを使用しており、機能しています(私のプライベートメールでテスト済み):

raw: Again a message content here.
title: Hello there general kenoby
archetype: private_message
target_recipients: j.doe@something.com

バックエンドでグループ名を期待しているのは奇妙だと思います :confused:

「いいね!」 1

TL;DR: target_recipients ではなく target_emails を使用してください。

target_recipientsPostsController のパラメータであり、PostCreator の引数ではないことに注意してください。
そのコントローラーは、受信者がユーザー、グループ、またはメールアドレスであるかどうかを 判断し、最終的に NewPostsManagertarget_emails として渡され、最終的に TopicCreator に渡されます。

「いいね!」 5

ありがとうございます!それでした :slight_smile:

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