AI Bot icon not appearing in header for non-staff

I think adding groups to AI chatbot setting, does not display the button when they have access to the AI bot. Trust level/admin only gets to see this button in my case.

1 Like

This site setting name is misleading (cc @falco/@roman) it should be ai_bot_add_ai_pm_to_header

AI bot research here:

Look up site setting context

Reading context for: ai_helper_add_ai_pm_to_header

The ai_helper_add_ai_pm_to_header is a site setting in the Discourse AI plugin. When enabled, it displays a button in the header of the Discourse forum that allows users to start a private message (PM) with an AI Bot.

Hereā€™s a detailed breakdown of how it works:

  1. The setting is defined in the settings.yml file of the Discourse AI plugin with a default value of true. This means that, by default, the button to start a PM with the AI Bot is displayed in the header.

  2. The setting is used in the ai-bot-replies.js file. This JavaScript file contains the logic for interacting with the AI Bot.

  3. The attachHeaderIcon function checks if the ai_helper_add_ai_pm_to_header setting is enabled. If it is, it retrieves the list of enabled AI Bots from the ai_bot_enabled_chat_bots setting. This setting contains a list of AI Bots that are enabled for chat, separated by a pipe (|).

  4. If there are any enabled AI Bots, the attachHeaderIcon function attaches two widget actions to the header: showAiBotPanel and hideAiBotPanel. These actions control the visibility of the AI Bot panel.

  5. The showAiBotPanel action sets the botSelectorVisible state to true, which shows the AI Bot panel.

  6. The hideAiBotPanel action sets the botSelectorVisible state to false, which hides the AI Bot panel.

Please note that the user ID of the AI Bot is hardcoded as -110, -111, and -112 in the isGPTBot function. This function checks if a user is an AI Bot based on their user ID.


Look up site setting context

Reading context for: ai_bot_allowed_groups

The ai_bot_allowed_groups setting controls which user groups are permitted to interact with the AI Bot in private messages. This is particularly important for controlling who can receive replies from the AI Bot in a PM context.

The default groups allowed are @staff (group id: 3) and @trust_level_4 (group id: 14). These group ids are specified in the ai_bot_allowed_groups setting in the settings.yml file of the discourse-ai plugin.

The ai_bot_allowed_groups setting is used in the ai-bot-replies.js initializer. Here, it checks if the current user is a member of any of the allowed groups. If the user is in an allowed group and the AI Bot feature is enabled, the initializer attaches the header icon and initializes AI Bot replies.

The ai_bot_allowed_groups setting is also used in the entry_point.rb module of the AI Bot. This module adds the ai_enabled_chat_bots attribute to the current_user serializer. This attribute is included if the AI Bot feature is enabled and the authenticated user is a member of any of the allowed groups.

When a new post is created, the post_created event is triggered. If the post is a regular post in a private message and the postā€™s user is in any of the allowed groups, an AI reply job is enqueued.

In summary, the ai_bot_allowed_groups setting is crucial for controlling which users can interact with the AI Bot in private messages. It is used in several places in the discourse-ai plugin to enforce this restriction.

2 Likes

I was trying to say that it looks like, this PM button only shows up for admins/staff, no matter the allowed groups. It seems the PM button in header setting, does not respect the allowed AI bot groups, but rather are fixed on admin only? I canā€™t get this to show to a normal user.

This is certainly not the case, at least not hereā€¦ just added you to bot-testers group, can you see the button here? (reload)

Hm, it seems to work here. I canā€™t get it to work on two instances. Strangeā€¦ I went through all settings multiple times now.

Our current settings are:

But I am about to fix this site setting name cause it is really confusing.

Are you latest?

My settings are almost completely the same, but I have a trust-level group in the list. However, also tried without admin/TL groups, and only the ai-bot group with the same result, also tried safemode with themes/non-officials turned off, no button in all cases :thinking:

I am latest indeed.

could this be an interaction with another plugin, can you rebuild with all the non official plugins removed?

1 Like

Sure, Iā€™m rebuilding rn. Let u know in a bit, this is quite a slow server :grinning:

No change after the rebuild. My current plugin list:


    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-solved.git
          - git clone https://github.com/discourse/discourse-whos-online.git
          - git clone https://github.com/discourse/discourse-data-explorer.git
          - git clone https://github.com/discourse/discourse-fingerprint.git
          - git clone https://github.com/discourse/discourse-adplugin.git
          - git clone https://github.com/discourse/discourse-chat-integration.git
          - git clone https://github.com/discourse/discourse-docs.git
          - git clone https://github.com/discourse/discourse-chat.git
          - git clone https://github.com/discourse/discourse-gamification
          - git clone https://github.com/discourse/discourse-openid-connect
          - git clone https://github.com/discourse/discourse-rss-polling
          - git clone https://github.com/discourse/discourse-ai

FYI, the user can message the AI. Itā€™s just the button that doesnā€™t show for users.

hmm any luck? I hate to say this, but can you try bisecting the official plugins as well to see if any of them are clashing, maybe start by rebuilding with just discourse-ai? Nothing bad will happen, you can always rebuild with the rest of them shortly after.

1 Like

I will give this a try, will let you know. I did notice, itā€™s not just the header button, but also the AI composer helper that has the same issue.

UPDATE
I found the bug for you, it has to do with group privacy.

image

Every value below this (owners/owners+mods) will result into hiding the button. Not sure if this is documented somewhere, might have missed it.

Adding the bot to the group, did not make any difference. Changing the above shown visibility setting did.

2 Likes

Nice one, this is very resolvable, will sort out next week

2 Likes

No hurry for me. Iā€™d like to add that the same issue is also happening with Trust Level groups, since they are hidden by default. Changing the visibility does make the AI PM button appear.

1 Like

I have it fixed per:

Will be merged later today.

6 Likes