Opening a reply window via URL

Hi All,

I know that we can create a new topic via url with special param.
But I want my users to click a link to reply a specific topic. Is there a way to add special params in the url query to auto open reply window for my users? If not, is there a way I can do this?

「いいね!」 5

Yes, @techapj added this a while ago, details are here:

「いいね!」 1

Hi Jeff,

Thank you for your reply, but what I want is that I want my users to reply
a topic which has already been created by others.
eg. I have a topic A in my forum, and I want every user click this link to
reply under topic A, not to create another topic.

What I want is when I open this link, the reply window popup, I want this
action equals to click the “reply” button under a topic.

「いいね!」 1

It has been a while and I haven’t found a way to do it.
I just want to be able to create a link that when clicked opens a specific topic with the reply box activated and with the focus on it.

Something like:
https://meta.discourse.org/t/how-to-open-reply-window-via-url/#reply

Anyone knows how can it be achieved?
Thanks,

「いいね!」 2

What I posted above works, but remember you don’t need to be on a specific topic to reply to it.

If your requirement is “must navigate to topic page, and then open the composer to reply”, then we don’t have that… but again it’s not required, you can reply to any topic from any other topic (or any location in the Discourse app, in fact) in the composer.

That post only mentions new-topic, where is the handy url to post a reply?

I believe there is one, cc @techAPJ

I’m aiming to use that link outside of Discourse. For example, putting a link on my blog, and when clicked it opens a new tab and starts a reply on a particular topic of the forum.

Is there a way to do it?

Thanks for your help.

Yes, the answer above works as you describe. Perhaps @techapj can help me explain because I seem to be failing at explaining this at the moment.

「いいね!」 2

The feature we have right now only supports creating new topic via URL.

What @magoz wants is to have a URL for an existing topic that will open composer and user can start replying on that topic as soon as they visit that URL. This is currently not available and is not on my list right now.

Should we add support for this feature?

「いいね!」 8

Not sure about it seems very uncommon

「いいね!」 3

My bad @magoz I was indeed misunderstanding. I could have sworn we had a pre-filled reply URL though.

「いいね!」 3

Apologies for my late reply.

Opening the composer (in a blank state) from an URL would be useful for those who have external websites working with Discourse and ask their users to reply to a particular Discourse topic.

For instance, I have a private website where I teach online lessons. I ask my students to reply to specific discourse topics to introduce themselves, to post their homework, etc.

It would be nice to be able to add something like ?reply at the end of any topic’s URL, and share that link with them.

For example:

<a href="https://meta.discourse.org/t/how-to-open-reply-window-via-url/44781?reply">link</a>

It would open a new reply to that topic with the composer open.

「いいね!」 7

I would love to see it, too. Including template-support for answers, so it’s not just for topics :slight_smile:

「いいね!」 6

今、これは可能でしょうか?

私たちもこの機能をぜひ実現したいと考えています🙏 もしまだ実現していない場合、これを実現するために追加の作業は多く必要でしょうか?

私たちのコミュニティのメンバーには、YouTube Live セッションを運営する思想のリーダーや専門知識を持つ方々(SME)がいます。Q&A にはそれなりに適していますが、深い議論を行うには全く不適切です。

既存のイベントトピック(イベントプラグイン を使用したもの)にユーザーが質問を投稿できるよう誘導し、返信ウィンドウをポップアップ表示させ、質問を持つ人々がそれぞれの SME のトピックに投稿していることを保証したいと考えています。

私たちが多くの方々に提供している大きな付加価値の一つは、ユーザーと深く議論できる場を提供することです。

YouTube や Facebook のライブ配信では、会話を「開始」するに過ぎません。Discourse は、その会話を「継続」するための完璧なツールです。

直接クリックできる URL を提供し、返信ダイアログボックスを自動的に開き、テンプレートテキストを事前に埋め込むことでプロセスを簡素化できれば、非常に助かります!!

「いいね!」 2

同じく、コミュニティにとって非常に役立つと思います。

「いいね!」 1

この機能については、私のインスタンスではシンプルなテーマコンポーネントを使用しています。以下は私のコードを適応させたものです。これには #reply の他に、#upload(デスクトップで新しい返信を開くとアップロードウィンドウが表示される)や #edit(ウィキの OP 用)も対応しています。

setTimeout の回避や draftSequence の適切な管理(topic.draft_sequence が正しいかどうかは確信がありません)など、まだ改善の余地があります。また、ここでのベストプラクティスが何かはわかりません。とはいえ、私の環境では問題なく動作しています。

/t/[slug]/[id]#reply のように任意のトピックに移動すると、空の新しい返信でコンポーザーが開きます。

事前にテキストを入力したい場合は、composer.open に渡すオブジェクトの reply 属性を設定することで実現できます。また、そのトピックに既に下書きが存在する場合、新しい返信を作成する前に保存するか破棄するかを尋ねられます。下書きを再開したい場合は、draftSequence が正しく設定されている必要があります。

<script type="text/discourse-plugin" version="0.4">
  if (/.*#reply$/g.test(document.URL)) {
    const { REPLY } = require('discourse/models/composer').default;
    
    const composer = Discourse.__container__.lookup('controller:composer');
    
    setTimeout(function() {
      const topic = Discourse.__container__.lookup("controller:topic").get("model");
      if (topic) {
        composer.open({
            action: REPLY,
            draftKey: topic.draft_key,
            draftSequence: topic.draft_sequence,
            topic,
        });
      }
    }, 0)
  }
</script>

参考になれば幸いです。

「いいね!」 13

これを変更/更新しましたか?それは非常に役立つでしょう。インスタンスで次のようなユースケースを見つけました。

人々にバナートピックに返信する簡単なワンクリック方法を提供する

「いいね!」 1

私が覚えている唯一の変更は、ユーザーがまだログインしていない場合にログインフローを強制することでした。それは次のようなものです。

        if (!Discourse.User.current()) {
            Discourse.__container__.lookup("route:application").send("showLogin");
        }

私はまだ私のコミュニティで、ReactアプリからDiscourseのこれらのフロー(返信、編集、アップロードなど)のいずれかにユーザーを直接誘導するためにそれを使用しています。

「いいね!」 2