通过 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 个赞

现在这可行吗?

我们也非常希望看到这一功能 :folded_hands: 如果目前还不支持,实现它需要大量额外工作吗?

我们的一些社区成员是行业领袖或领域专家(SME),他们会举办 YouTube 直播。这对于问答环节来说尚可(勉强能用),但对于深入讨论来说则糟糕透顶。

我们希望能够引导用户将问题发布到现有的活动主题帖中(我们已使用了 活动插件),并让回复窗口自动弹出,同时确保提问者能够发布到对应专家的主题帖下。

对我们合作的许多用户而言,我们提供的核心价值之一就是为他们提供一个能与用户进行深入讨论的平台。

当他们进行 YouTube 或 Facebook 直播时,那仅仅是开启对话。而 Discourse 则是延续对话的完美工具。

如果我们能通过提供一个直接链接,让用户点击后自动打开回复对话框,并预填一些模板文本,这将大大简化流程,对我们来说会非常有帮助!!

2 个赞

我也是。这对我们的社区会非常有用。

1 个赞

我在自己的实例中使用了一个简单的主题组件来实现这个功能。下面是我的一个改编版本——除了 #reply 之外,它还支持 #upload(在桌面端打开上传窗口的新回复)和 #edit(用于 Wiki 的原始发帖)。

它还需要一些改进,比如避免使用 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 个赞