Skip to content

world.openProfile(id) ​

Asks the webapp to show the profile card of a member or of the world itself on top of your view.

openProfile(id: string): Promise<boolean>
js
const isShown = await world.openProfile(member.id);

Parameters ​

ParameterTypeWhat it is
idstringThe id of a member (from world.members or from the fromId of a message) or the world.id of the world itself. The view of an agent passes the id of the agent.

Returns ​

A Promise that resolves to a boolean:

ResultWhat it means
trueThe webapp shows the card.
falseNothing is shown. The id belongs neither to the world nor to a member or it belongs to a member known only by its role (type 'unknown') who has no profile and therefore no card yet.

The webapp renders the card over your view in its own look (a sheet on a phone) and the person closes it there. Your view receives neither an event when the card closes nor any of its content.

The promise rejects when the webapp cannot show a card (Troubleshooting).

Usage ​

Open a member's card ​

The example has a button for the world, one for each member and a last one whose id belongs to nobody and gives false. Like the webapp, a fake world resolves true for the id of the world and for the ids of the members even though it shows no card.

jsx
import { useState } from 'react';
import { useWorld } from './useWorld.js';

// A fake world with two members.
const arena = {
	name: 'Arena',
	members: [{ name: 'Ada', role: 'player' }, { name: 'Bo', role: 'player' }],
};

export default function App() {
	// While building: the fake world. In the webapp: useWorld()
	const { world, error } = useWorld({ fake: { world: arena } });
	const [result, setResult] = useState('Click a name.');

	if (error) return <p>Could not connect ({error.code}).</p>;
	if (!world) return <p>Connecting…</p>;

	// Asks the webapp to show its profile card for the world or a member over the view.
	// A fake world shows nothing, but it resolves true for the id of the world or of a member.
	async function showProfile(id, name) {
		try {
			const isShown = await world.openProfile(id);
			setResult(isShown ? `The card of ${name} is shown.` : `No card for ${name}.`);
		} catch (profileError) {
			setResult(`Error: ${profileError.code}`);
		}
	}

	// A button for the world, one per member, and one with an id nobody has.
	const everyone = [{ id: world.id, name: world.name }, ...(world.members ?? []), { id: 'nobody', name: 'Someone else' }];
	return (
		<>
			<div>
				{everyone.map((someone) => (
					<button key={someone.id} onClick={() => showProfile(someone.id, someone.name)}>{someone.name ?? 'Someone'}</button>
				))}
			</div>
			<p>{result}</p>
		</>
	);
}
js
import { connectToHost } from '@unaiverse/gui-kit';

// A fake world with two members.
const arena = {
	name: 'Arena',
	members: [{ name: 'Ada', role: 'player' }, { name: 'Bo', role: 'player' }],
};

// While building: the fake world. In the webapp: const world = await connectToHost();
const world = await connectToHost({ fake: { world: arena } });

const buttons = document.createElement('div');
const result = document.createElement('p');
result.textContent = 'Click a name.';
document.body.append(buttons, result);

// Asks the webapp to show its profile card for the world or a member over the view.
// A fake world shows nothing, but it resolves true for the id of the world or of a member.
async function showProfile(id, name) {
	try {
		const isShown = await world.openProfile(id);
		result.textContent = isShown ? `The card of ${name} is shown.` : `No card for ${name}.`;
	} catch (error) {
		result.textContent = `Error: ${error.code}`;
	}
}

// A button for the world, one per member, and one with an id nobody has.
world.subscribe((node) => {
	const everyone = [{ id: node.id, name: node.name }, ...(node.members ?? []), { id: 'nobody', name: 'Someone else' }];
	buttons.replaceChildren(...everyone.map((someone) => {
		const button = document.createElement('button');
		button.textContent = someone.name ?? 'Someone';
		button.onclick = () => showProfile(someone.id, someone.name);
		return button;
	}));
});
Live, on a fake world
Open

Open the card of who wrote a message ​

Since the fromId of a message is the id of its author, a button with the name of the sender can open their card:

js
function senderButton(message) {
  const button = document.createElement('button');
  button.textContent = message.from;
  // The person's own messages have no id: nothing to open.
  button.disabled = !message.fromId;
  button.onclick = () => world.openProfile(message.fromId);
  return button;
}

When showsSenders is false the world asks views to hide who wrote each message. In that case render no clickable name.

Open the card of the world ​

The id of the world opens the card of the world itself:

js
aboutButton.onclick = () => world.openProfile(world.id);

Caveats ​

  • Open it only when the person asks for it (for example with a click on a name or a picture). A card the person did not ask for gets in their way. Never open one on your own, in a loop or on hover.
  • It does not act in the world. The card only shows the profile until the person closes it in the webapp.
  • Not for the person. Your view cannot open the card of the person because it never receives their id (their messages have fromId: null).
  • A member known only by its role has no card. Until a member shares its profile its type is 'unknown' and its name is its role. For such a member openProfile resolves false just as the UNaIVERSE view of the world opens no card for it. Offer the button only when member.type !== 'unknown'.
  • A fake world shows no card. Its openProfile resolves true for the id of the world or of a member and false for any other id.

Troubleshooting ​

CodeWhyWhat to do
'not-allowed-verb'This webapp is older than your kit and does not know openProfile.Hide the buttons that open cards or show what you know of the member yourself.
'unavailable'This webapp cannot show a card here.Continue without the card as in the previous row.
'failed'The webapp could not run the call (rare).Let the person try again.
js
async function showCard(id) {
  try {
    await world.openProfile(id);
  } catch (error) {
    if (error.code === 'not-allowed-verb' || error.code === 'unavailable') hideCardButtons();
  }
}

See also ​

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.