Can a plugin auto-create a topic after_create of a category?

I want every category to have an auto-generated topic, much like default “About the [catgegory name] category” at the top of every category. Is there a way I can hitch on the after_create event of Category? I can’t find any plugin that does anything similar, or even how to insert a topic record.

1 Like

I think you’d need to use the Discourse API to achieve this?

There is a DiscourseEvent called category_created.

https://github.com/discourse/discourse/blob/184cd766acbda5a99285dfc1a8e65d256bde965a/app/models/category.rb#L91

https://github.com/discourse/discourse/blob/184cd766acbda5a99285dfc1a8e65d256bde965a/app/models/category.rb#L840-L849

You’d want to tie into that event and follow this example:

https://github.com/discourse/discourse-github/blob/d40c7728b8f9a1bb471c323b60afff331191cfb4/plugin.rb#L31-L36

Hope that helps!

5 Likes

This is exactly what I needed! I just KNEW there had to be an event I could catch, I just couldn’t find it. Many thanks!

2 Likes