Migrating embedded topics from topicId to automatic topic creation

AI-generated summary

Migrating embedded topics from topicId to automatic topic creation

n1bff is looking to switch from a hard-coded mapping of webpage URLs to Discourse topic IDs to using Discourse’s automatic topic creation for embedding comments. They have an existing setup using the “alternate configuration” method but want to change to the “simple setup” method.

After implementing a temporary solution with an if switch, n1bff encountered issues with bad thread references due to incorrect URLs. They found the topic_embeds table and are wondering if they can safely delete from it and re-visit the pages to regenerate threads, or if they need to clean up related rows elsewhere.

pfaffman pointed out a relevant guide on embedding Discourse comments on another website via JavaScript.

The environment: I have a Discourse forum and a website. The website has pages. The pages use embedded Discourse topics for commenting.

As part of a migration process I am currently using a hard-coded mapping of “webpage url” to “Discourse topic id” and use server-side code on the webpages to embed the appropriate Discourse topic.

This works well for all existing webpages because I migrated previous comments into Discourse topics.

For new webpages it would be too much overhead to a) create a new topic and b) continue to track the new mappings between webpages and topics. So I would like to switch to Discourse’s own logic for creating topics on-demand and not specify the existing topic IDs on the webpages anymore.

I assume that Discourse has its own mapping table to know which topic to serve if a request for an embedded comment thread comes in.

Is that the case and can I manually insert my existing mappings there, then switch my webpages to use that functionality?

So you want to Embed Discourse comments on another website via Javascript?

That is what I already do and where I want to change the configuration.

Currently I use Embed Discourse comments on another website via Javascript (“Configuring Discourse for Embedding (simple setup)”)

And I want to change to the standard Embed Discourse comments on another website via Javascript (“(Alternate Configuration) Linking to existing topics”)

I added a simple if switch to my website that uses a stored topicId if available and the page’s discourseEmbedUrl otherwise.

Sadly I had a bad URL for some pages and now I have bad thread references between the pages and the threads. I found the table topic_embeds, that seems to be it. Can I safely delete from that table and re-visit the pages to regenerate threads? Or do I need to clean up some related rows elsewhere?