# Component to add a custom message to the Composer based on user and categories ID

**URL:** https://meta.discourse.org/t/component-to-add-a-custom-message-to-the-composer-based-on-user-and-categories-id/392244
**Category:** Development
**Tags:** composer
**Created:** [December 27, 2025, 5:21pm UTC](https://meta.discourse.org/t/component-to-add-a-custom-message-to-the-composer-based-on-user-and-categories-id/392244 "2025-12-27T17:21:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![alltiagocom](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alltiagocom/32/492709_2.png) [@alltiagocom](https://meta.discourse.org/u/alltiagocom)
#### Post date: [December 27, 2025, 5:21pm UTC](https://meta.discourse.org/t/component-to-add-a-custom-message-to-the-composer-based-on-user-and-categories-id/392244/1 "2025-12-27T17:21:17Z")

</div>

Today I was facing this issue:

> [@Required tags should only be required based on type of user](https://meta.discourse.org/t/required-tags-should-only-be-required-based-on-type-of-user/392238):
>
> I have this tag group that I want to force on myself, as an admin, on a particular category, so I never forget to properly tag topics. Since those tags are very specific and I don’t want them to be used by anyone else but me, I restricted who can use them: Now, the issue is that when I try to create a new topic in that category as a non-admin, I can’t, because it requires me to add at least one tag, but all tags are restricted to admins: [image] My…

but for now, until the team works on it (hopefully), I decided to ask Claude for some help building a Component that allows me to have a custom message in the Composer to remind me to add a tag. I can add one or more users, by ID, and I can limit it to certain categories, also by ID.

If the ID (user and categories) is NOT on the list, I see this:

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/e/e/6eeedab67499312c7471216759e59bb3c2a64b63.png)

If the ID is on the list, I see the message:

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/8/b/38b5bc7a92354502fbd3ee906eb8943ddac0018c.png)

If this is helpful to others, here it is (just create a component and add the script to the JS tab):

```js
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer("0.8.31", (api) => {
  // Configuration: Add your user IDs and category IDs here
  const TARGET_USER_IDS = [2]; // Replace with actual user IDs
  const TARGET_CATEGORY_IDS = [4,49]; // Replace with actual category IDs
  const REMINDER_MESSAGE = "🛑 Add the appropriate tag to this post!";
  
  let previousCategoryId = null;
  let checkInterval = null;
  
  function checkAndUpdateMessage() {
    const composer = api.container.lookup("controller:composer");
    if (!composer || !composer.model) {
      // Composer is gone, stop checking
      if (checkInterval) {
        clearInterval(checkInterval);
        checkInterval = null;
      }
      return;
    }
    
    const currentUser = api.getCurrentUser();
    if (!currentUser || !TARGET_USER_IDS.includes(currentUser.id)) return;
    
    const model = composer.model;
    const categoryId = model.categoryId;
    
    // Only act if category has changed
    if (categoryId === previousCategoryId) return;
    previousCategoryId = categoryId;
    
    const currentReply = model.reply || "";
    
    // Remove message if it was added
    if (currentReply.startsWith(REMINDER_MESSAGE)) {
      model.set("reply", currentReply.replace(REMINDER_MESSAGE, "").trim());
    }
    
    // Add message if in target category and composer is empty
    if (categoryId && TARGET_CATEGORY_IDS.includes(categoryId)) {
      const cleanReply = model.reply || "";
      if (cleanReply.trim().length === 0) {
        model.set("reply", REMINDER_MESSAGE);
      }
    }
  }
  
  // Check on composer open
  api.onAppEvent("composer:opened", () => {
    previousCategoryId = null;
    checkAndUpdateMessage();
    
    // Start polling for category changes
    if (checkInterval) clearInterval(checkInterval);
    checkInterval = setInterval(checkAndUpdateMessage, 300);
  });
  
  // Stop checking when composer closes
  api.onAppEvent("composer:closed", () => {
    if (checkInterval) {
      clearInterval(checkInterval);
      checkInterval = null;
    }
    previousCategoryId = null;
  });
});

```
