Automatically append staff notice to user posts

Our system generates accounts for posting announcements, we were wondering if there was a way to add a separate staff notice that has its own icon that automatically appends to these posts so we can explain that it is an auto-generated account? Even by userid/name, or group works.

1 Like

I think you can achieve this with theme components. For example, this code does what you need:

<script type="text/discourse-plugin" version="0.8">

const { iconHTML } = require("discourse-common/lib/icon-library");

const bot_id = 128856; // or some else
api.decorateWidget("post:before", (helper) => {
    if (helper?.getModel()?.user_id !== bot_id) {return;}
    return helper.h("div.post-notice",[
        helper.rawHtml(iconHTML("shield-alt")), // icon name
        helper.h("p", "this is a bot"),  // text
    ]);
});

</script>
3 Likes

Hi there!

I’ve tried using JS to auto-append a staff notice to an auto-generated account if it is a member of the group “autogenerated” but I’m not sure where I’m going wrong.

<script>
   window.onload = function() {
     const { groupMembers } = await discourse.groups.getMembers({
       group_name: 'autogenerated'
     });

     if (groupMembers.includes(helper.getModel().user_id)) {
       return helper.h('div.post-notices', [
         helper.rawHtml(iconHTML('shield-alt')),
         helper.h('p', 'This account is auto-generated and should be considered as a bot. The account is not monitored by Staff.')
       ]);
     }
   }
 </script>

I’ve put the code in the “Head” part of our component, however, it’s not running. I’m not sure if it isn’t calling the function correctly, or if my IF statement suddenly isn’t being met.

Hi @jhealey :slight_smile: I’ve slipped your post into the existing topic as they seem very similar questions. :+1:

You might want to lock the other topic then. I probably should’ve replied to this topic instead… :sweat_smile:

1 Like

I relied too much on the auto tools doing it and didn’t check. :slight_smile: I have removed the other topic. :+1:

Thanks! :blush:

If you’re using await, your function must be async.

1 Like

I don’t know how I didn’t notice that! Thank you! It’s working now :slight_smile:

It’s okay! Once in a while, we all make oversights like that.

You’re welcome! :heart:

all these hacks are nice and all, but this should be a built-in feature in some way or another.