RocketChat/Rocket.Chat · error · Error

error-not-allowed-to-close-conversation

Error message

error-not-allowed-to-close-conversation

What it means

Thrown in the POST handler of 'livechat/room.close' (room.ts:137-139) when the setting 'Omnichannel_allow_visitors_to_close_conversation' is disabled (falsy). This is the very first check in the handler — it fires before any token or room validation. The setting is read via rcSettings.get() from the server settings store.

Source

Thrown at apps/meteor/server/api/v1/omnichannel/room.ts:138

				throw new Error('invalid-room');
			}

			return API.v1.success({ room: froom, newRoom: false });
		},
	},
);

// Note: use this route if a visitor is closing a room
// If a RC user(like eg agent) is closing a room, use the `livechat/room.closeByUser` route
API.v1.addRoute(
	'livechat/room.close',
	{ validateParams: isPOSTLivechatRoomCloseParams },
	{
		async post() {
			const { rid, token } = this.bodyParams;

			if (!rcSettings.get('Omnichannel_allow_visitors_to_close_conversation')) {
				throw new Error('error-not-allowed-to-close-conversation');
			}

			const visitor = await findGuest(token);
			if (!visitor) {
				throw new Error('invalid-token');
			}

			const room = await findRoom(token, rid);
			if (!room) {
				throw new Error('invalid-room');
			}

			if (!room.open) {
				throw new Error('room-closed');
			}

			const language = rcSettings.get<string>('Language') || 'en';
			const comment = i18n.t('Closed_by_visitor', { lng: language });

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Enable the setting in Admin > Omnichannel > Allow visitors to close conversation (set to true).
  2. Via settings API or CLI: set Omnichannel_allow_visitors_to_close_conversation to true.
  3. If the setting should remain disabled, use the authenticated 'livechat/room.closeByUser' endpoint instead (requires an agent/admin user with 'close-livechat-room' permission).

Example fix

// before — setting is disabled, visitors cannot close
POST /api/v1/livechat/room.close
// throws 'error-not-allowed-to-close-conversation'

// after — enable in admin settings, then retry
// Admin > Omnichannel > Allow visitors to close conversation = true
POST /api/v1/livechat/room.close
// { rid: '...', token: '...' }
Defensive patterns

Strategy: validation

Validate before calling

// Check the setting before attempting to close a room as a visitor
const allowClose = await getSetting('Omnichannel_allow_visitors_to_close_conversation');
if (!allowClose) {
  // use the authenticated room.closeByUser endpoint instead, or enable the setting
  throw new Error('Visitor close is disabled — use room.closeByUser as an agent');
}

Try / catch

try {
  await api.post('/livechat/room.close', { rid, token });
} catch (err) {
  if (err.message === 'error-not-allowed-to-close-conversation') {
    // fall back to authenticated close-by-user endpoint
    await api.post('/livechat/room.closeByUser', { rid, comment: 'Closed by agent' }, { auth: true });
  }
}

Prevention

When it happens

Trigger: Calling POST /api/v1/livechat/room.close when the admin setting 'Omnichannel_allow_visitors_to_close_conversation' is set to false. Any request body (even valid ones) will trigger this error before token/room checks.

Common situations: Administrator disabled visitor-initiated room closing in Omnichannel settings; fresh installation where the setting defaults to false; setting was changed during deployment without updating the client widget to hide the close button.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/50fdba0a7a2ecea7. Report an issue: GitHub.