> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Hello Realtime

## Article: Hello Realtime

## Article Link: https://dev.wix.com/docs/coding-examples/getting-started/hello-world/hello-realtime.md

## Article Content:

# Hello Realtime

Allows site visitors to publish updates to specific channels in realtime.

<div style="display: flex; flex-direction: row; align-items: center;"> 
<span style="display: flex; flex-direction: row; align-items: center; margin-right: 20px;"> 
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/1e0a3fdcaa7d1a296c01998f48bd9125.png" style="width: 15px; height: 15px;"> 
<span style="margin-left:3px; color:rgb(51 56 83); font-size:1rem">Introduction</span> 
</span> 
<span style="color:rgb(51 56 83); font-size:1rem">Last updated: 14 Apr 2025</span> 
</div> 
<div style="display: flex; flex-direction: column; padding-top: 20px; padding-bottom: 20px;">
<div style="width: 100%; margin-bottom: 20px;"> 
<img src="https://static.wixstatic.com/media/d2a594_bcc5233af6e54ffc8d0ae3f4b0043811~mv2.webp" alt="Hello Realtime" style="width: 100%;"> 
</div> 
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: center; width: 100%;">
<div style="margin: 0px 20px 20px 0px;">
<a href="fallback::https://manage.wix.com/edit-template/from?originTemplateId=1a50ca8e-9334-47cc-8f81-418d1b49c950&templateId=cc137b8b-accf-486e-ba7d-339320180d4b&autoDevMode=true" target="_blank"> <button style="margin-right: 10px;background-color:#106DFF; color:white; padding:10px 20px; border:none; border-radius:21px; cursor:pointer; margin: 0px 20px 20px 0px;" target="_blank">Open Example</button></a> 
<a href="fallback::https://www.wix.com/velo-examples/hello-rltm-studio" target="_blank"><button style="background-color:white; color:#106DFF; padding:10px 20px; border:1px solid #106DFF; border-radius:21px; cursor:pointer; width:125px;" target="_blank">Preview</button></a> 
</div> 
</div> 
</div> 
</div>

## About
---

In this example, we use the [wix-realtime](https://dev.wix.com/docs/velo/apis/wix-realtime-frontend/introduction.md) APIs to publish site visitors' messages to channels.

## APIs 
---
<ul> 
<li><a href="portalId::f356b938-ca2c-46f4-a390-e7ed146e00e0resourceId::00c3d3b5-6c8a-4c04-a659-926390861af9slug::introduction*fallback::https://dev.wix.com/docs/velo/api-reference/wix-realtime-frontend/introduction".md target="_blank">wix-realtime-frontend</a></li> 
<li><a href="portalId::f356b938-ca2c-46f4-a390-e7ed146e00e0resourceId::02e336f0-0a91-4c7d-b7b2-ff4e9835aae6slug::introduction*fallback::https://dev.wix.com/docs/velo/api-reference/wix-realtime-backend/introduction".md target="_blank">wix-realtime-backend</a></li> 
<li><a href="portalId::f356b938-ca2c-46f4-a390-e7ed146e00e0resourceId::5323507b-3bb9-4fee-b29f-e7e56c9e41b4slug::introduction*fallback::https://dev.wix.com/docs/velo/api-reference/wix-web-module/introduction".md target="_blank">wix-web-module</a></li> 
</ul> 

## How we built it 
---
We added the following to our site:

#### Page Elements


##### Simple

* A [text input](https://dev.wix.com/docs/velo/velo-only-apis/$w/text-input/introduction.md) for the site visitor to write the message to publish.    
* A [button](https://dev.wix.com/docs/velo/velo-only-apis/$w/button/introduction.md) to publish the message.    
* A [text box](https://dev.wix.com/docs/velo/velo-only-apis/$w/text-box/introduction.md) to display the published messages. 
    

##### Channels

* A [text input](https://dev.wix.com/docs/velo/velo-only-apis/$w/text-input/introduction.md) for the site visitor to write the message to publish.
* 4 [buttons](https://dev.wix.com/docs/velo/velo-only-apis/$w/button/introduction.md) to publish the message. Each one corresponds to a specific channel.
* 4 [text boxes](https://dev.wix.com/docs/velo/velo-only-apis/$w/text-box/introduction.md) to display the published messages. Each one corresponds to a specific channel.
    

##### Permissions

* A [text input](https://dev.wix.com/docs/velo/velo-only-apis/$w/text-input/introduction.md) for the site visitor to write the message to publish.
* 3 [buttons](https://dev.wix.com/docs/velo/velo-only-apis/$w/button/introduction.md) to publish the message. Each one corresponds to a specific channel. Only site visitors with sufficient permissions can publish to each channel.
* A [text box](https://dev.wix.com/docs/velo/velo-only-apis/$w/text-box/introduction.md) to display the published messages. 
* A [login bar](https://wix.wixanswers.com/apps/widget/v1/wix/53f85d67-f8b0-41ca-9dc8-5a16390cc74f/view/en/article/5a4eb6a1-9688-4184-a776-569d3cb04e98) for site visitors to log in to the site.


#### Frontend Code 

##### Simple

The code in this file enables site visitors to publish messages to a channel. The messages are displayed on the site.
In this file, we:
1.  Defined a channel.
2.  Subscribed the site visitor to the channel, and defined that messages should be displayed in the text box when they are published.
3.  Added an onClick event handler to the **Publish** button that publishes the message entered by the site visitor to the channel.
    
###### Channels

The code in this file enables site visitors to publish messages to 1 of 4 channels. The messages are displayed on the site, grouped by channel.
In this file, we:
1.  Defined 4 channels.
2.  Subscribed the site visitor to the channels, and defined that messages should be displayed in the text box corresponding to the specified channel when they are published.
3.  Added onClick event handlers to the **Publish** buttons that publishes the message entered by the site visitor to the specified channel.
    

##### Permissions

The code in this file enables site visitors to publish messages to 1 of 3 channels:
*   updatesChannel: All site visitors can publish to this channel.
*   updatesMembersChannel: Only site members can publish to this channel.
*   updatesAdminsChannel: Only site admins can publish to this channel.
    
The messages are displayed on the site, collated by channel.

In this file, we
1.  Defined 3 channels.
2.  Subscribed the site visitor to the channels they have permissions to publish to, and defined that messages should be displayed in the text box when they are published.
    
Added onClick event handlers to the **Publish** buttons that publishes the message entered by the site visitor to the channel. The messages aren't published if the site visitor isn't subscribed to the channel.

#### Backend Code

##### realtime.web.js
The code in this web module publishes messages to channels.
We defined and exported the following method:
*   publishMessage: Publishes a specified message to a specified channel.
    

##### realtime-permissions.js

The code in this file uses a [permissions router](https://dev.wix.com/docs/velo/velo-only-apis/wix-realtime-backend/permissions-router.md) to define the permissions you want to grant to subscribers on channels.
We defined permissions for the channels used on the **Permissions** page.

## Code Snippets
---
<details open> 
<summary> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 18" width="22" height="22">
    <path d="M16.003 15.18c0 .57-.11 1.01-.31 1.32.2.31.31.75.31 1.32 0 .94.33 1.22.53 1.24.27.02.481.25.471.52-.01.27-.22.48-.49.48-.521 0-1.512-.47-1.512-2.24 0-.51-.1-.74-.16-.81h-.06c-.06 0-.11 0-.16-.01a.505.505 0 0 1-.561-.29.522.522 0 0 1-.04-.21c0-.08 0-.17.04-.25.1-.22.35-.32.58-.27h.2c.06-.06.17-.29.17-.81 0-1.77.992-2.24 1.513-2.24.28 0 .5.22.5.5s-.22.5-.5.5c-.18.02-.511.3-.511 1.24l-.01.01Zm5.967 1.1c-.09-.22-.33-.33-.57-.28h-.211c-.06-.06-.17-.29-.17-.81 0-1.77-.991-2.24-1.512-2.24-.27 0-.48.21-.49.48-.01.27.2.5.47.52.2.02.53.3.53 1.24 0 .57.11 1.01.311 1.32-.2.31-.31.75-.31 1.32 0 .94-.33 1.22-.511 1.24-.28 0-.5.22-.5.5s.22.5.5.5c.52 0 1.512-.47 1.512-2.24 0-.51.1-.74.16-.81h.06c.06 0 .11 0 .15-.01.23.06.47-.05.57-.27.041-.08.041-.17.041-.25 0-.07 0-.14-.04-.21h.01ZM17.014 4H6.001C5.451 4 5 4.45 5 5v14c0 .55.45 1 1.001 1h7.008v-1H6.001V5h11.013v6h1.001V5c0-.55-.45-1-1-1Zm-9.01 7h7.008v-1H8.004v1Zm7.008-4H8.004v1h7.008V7Z"></path>
  </svg> realtime-permissions.js </summary> 

```javascript
import {permissionsRouter} from 'wix-realtime-backend';

const updatesMembers = {name: 'updates', resourceId: 'members'};
const updatesAdmins = {name: 'updates', resourceId: 'admins'};


permissionsRouter.default( (channel, subscriber) => {
  return {read: true};
} );

permissionsRouter.add(updatesMembers, (channel, subscriber) => {
    const isMember = subscriber.type === 'Member';
    return {read: isMember};
});

permissionsRouter.add(updatesAdmins, (channel, subscriber) => {
    const isAdmin = subscriber.type === 'Admin';
    return {read: isAdmin};
});

export function realtime_check_permission(channel, subscriber) {
  return permissionsRouter.check(channel,subscriber);
}
```
</details>

<details open> 
<summary> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 18" width="22" height="22">
    <path d="M16.003 15.18c0 .57-.11 1.01-.31 1.32.2.31.31.75.31 1.32 0 .94.33 1.22.53 1.24.27.02.481.25.471.52-.01.27-.22.48-.49.48-.521 0-1.512-.47-1.512-2.24 0-.51-.1-.74-.16-.81h-.06c-.06 0-.11 0-.16-.01a.505.505 0 0 1-.561-.29.522.522 0 0 1-.04-.21c0-.08 0-.17.04-.25.1-.22.35-.32.58-.27h.2c.06-.06.17-.29.17-.81 0-1.77.992-2.24 1.513-2.24.28 0 .5.22.5.5s-.22.5-.5.5c-.18.02-.511.3-.511 1.24l-.01.01Zm5.967 1.1c-.09-.22-.33-.33-.57-.28h-.211c-.06-.06-.17-.29-.17-.81 0-1.77-.991-2.24-1.512-2.24-.27 0-.48.21-.49.48-.01.27.2.5.47.52.2.02.53.3.53 1.24 0 .57.11 1.01.311 1.32-.2.31-.31.75-.31 1.32 0 .94-.33 1.22-.511 1.24-.28 0-.5.22-.5.5s.22.5.5.5c.52 0 1.512-.47 1.512-2.24 0-.51.1-.74.16-.81h.06c.06 0 .11 0 .15-.01.23.06.47-.05.57-.27.041-.08.041-.17.041-.25 0-.07 0-.14-.04-.21h.01ZM17.014 4H6.001C5.451 4 5 4.45 5 5v14c0 .55.45 1 1.001 1h7.008v-1H6.001V5h11.013v6h1.001V5c0-.55-.45-1-1-1Zm-9.01 7h7.008v-1H8.004v1Zm7.008-4H8.004v1h7.008V7Z"></path>
  </svg> realtime.web.js </summary> 

```javascript
import { Permissions, webMethod } from "@wix/web-methods";
import { publish } from 'wix-realtime-backend';

export const publishMessage = webMethod(Permissions.Anyone,(channel, message) => { 
    return publish(channel, message);
  }
);

```
</details>

<details open> 
<summary> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 18" width="22" height="22">
    <path d="M16.003 15.18c0 .57-.11 1.01-.31 1.32.2.31.31.75.31 1.32 0 .94.33 1.22.53 1.24.27.02.481.25.471.52-.01.27-.22.48-.49.48-.521 0-1.512-.47-1.512-2.24 0-.51-.1-.74-.16-.81h-.06c-.06 0-.11 0-.16-.01a.505.505 0 0 1-.561-.29.522.522 0 0 1-.04-.21c0-.08 0-.17.04-.25.1-.22.35-.32.58-.27h.2c.06-.06.17-.29.17-.81 0-1.77.992-2.24 1.513-2.24.28 0 .5.22.5.5s-.22.5-.5.5c-.18.02-.511.3-.511 1.24l-.01.01Zm5.967 1.1c-.09-.22-.33-.33-.57-.28h-.211c-.06-.06-.17-.29-.17-.81 0-1.77-.991-2.24-1.512-2.24-.27 0-.48.21-.49.48-.01.27.2.5.47.52.2.02.53.3.53 1.24 0 .57.11 1.01.311 1.32-.2.31-.31.75-.31 1.32 0 .94-.33 1.22-.511 1.24-.28 0-.5.22-.5.5s.22.5.5.5c.52 0 1.512-.47 1.512-2.24 0-.51.1-.74.16-.81h.06c.06 0 .11 0 .15-.01.23.06.47-.05.57-.27.041-.08.041-.17.041-.25 0-.07 0-.14-.04-.21h.01ZM17.014 4H6.001C5.451 4 5 4.45 5 5v14c0 .55.45 1 1.001 1h7.008v-1H6.001V5h11.013v6h1.001V5c0-.55-.45-1-1-1Zm-9.01 7h7.008v-1H8.004v1Zm7.008-4H8.004v1h7.008V7Z"></path>
  </svg> Channels </summary> 

```javascript
import { publishMessage } from 'backend/realtime.web.js';
import { realtime } from "@wix/site-realtime";

const subscribe = realtime.subscribe

const channelA = { name: 'a' };
const channelB = { name: 'b' };
const channelB1 = { name: 'b', resourceId: '1' };
const channelB2 = { name: 'b', resourceId: '2' };

$w.onReady(function () {
    subscribeToChannels();
    setupPublishButtons();
});

function subscribeToChannels() {
    subscribe(channelA, messageHandler);
    subscribe(channelB, messageHandler);
    subscribe(channelB1, messageHandler);
    subscribe(channelB2, messageHandler);
}

function setupPublishButtons() {
    $w('#publishButtonA').onClick(event => {
        publish(event.target, channelA);
    });

    $w('#publishButtonB').onClick(event => {
        publish(event.target, channelB);
    });

    $w('#publishButtonB1').onClick(event => {
        publish(event.target, channelB1);
    });

    $w('#publishButtonB2').onClick(event => {
        publish(event.target, channelB2);
    });
}

async function publish(button, channel) {
    if ($w('#message').value) {
        button.disable();
        $w('#message').disable();

        await publishMessage(channel, $w('#message').value);

        $w('#message').value = undefined;
        $w('#message').enable();
        button.enable();
    }
}

function messageHandler(message, channel) {
    let textBoxId;

    if (channel.name === 'a') {
        textBoxId = '#receivedMessagesA';
    } else { // Channel B - check resource ID
        if (channel.resourceId === '1') {
            textBoxId = '#receivedMessagesB1';
        } else if (channel.resourceId === '2') {
            textBoxId = '#receivedMessagesB2';
        } else {
            textBoxId = '#receivedMessagesB';
        }
    }

    $w(textBoxId).value += (message.payload + '\n');
}
```
</details>

<details open> 
<summary> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 18" width="22" height="22">
    <path d="M16.003 15.18c0 .57-.11 1.01-.31 1.32.2.31.31.75.31 1.32 0 .94.33 1.22.53 1.24.27.02.481.25.471.52-.01.27-.22.48-.49.48-.521 0-1.512-.47-1.512-2.24 0-.51-.1-.74-.16-.81h-.06c-.06 0-.11 0-.16-.01a.505.505 0 0 1-.561-.29.522.522 0 0 1-.04-.21c0-.08 0-.17.04-.25.1-.22.35-.32.58-.27h.2c.06-.06.17-.29.17-.81 0-1.77.992-2.24 1.513-2.24.28 0 .5.22.5.5s-.22.5-.5.5c-.18.02-.511.3-.511 1.24l-.01.01Zm5.967 1.1c-.09-.22-.33-.33-.57-.28h-.211c-.06-.06-.17-.29-.17-.81 0-1.77-.991-2.24-1.512-2.24-.27 0-.48.21-.49.48-.01.27.2.5.47.52.2.02.53.3.53 1.24 0 .57.11 1.01.311 1.32-.2.31-.31.75-.31 1.32 0 .94-.33 1.22-.511 1.24-.28 0-.5.22-.5.5s.22.5.5.5c.52 0 1.512-.47 1.512-2.24 0-.51.1-.74.16-.81h.06c.06 0 .11 0 .15-.01.23.06.47-.05.57-.27.041-.08.041-.17.041-.25 0-.07 0-.14-.04-.21h.01ZM17.014 4H6.001C5.451 4 5 4.45 5 5v14c0 .55.45 1 1.001 1h7.008v-1H6.001V5h11.013v6h1.001V5c0-.55-.45-1-1-1Zm-9.01 7h7.008v-1H8.004v1Zm7.008-4H8.004v1h7.008V7Z"></path>
  </svg> Permissions </summary> 

```javascript
import { realtime } from "@wix/site-realtime";
import { publishMessage } from 'backend/realtime.web.js';

const subscribe = realtime.subscribe
const updatesChannel = {name: 'updates'};
const updatesMembersChannel = {name: 'updates', resourceId: 'members'};
const updatesAdminsChannel = {name: 'updates', resourceId: 'admins'};
const updatesGuestsChannel = {name: 'updates', resourceId: 'guests'};

$w.onReady(function () {
   subscribeToChannels();
   setupPublishButtons();
});

function subscribeToChannels() {
    subscribe(updatesChannel, messageHandler)
        .catch(() => console.log('Not subscribed to updates channel'));
    subscribe(updatesMembersChannel, messageHandler)
        .catch(() => console.log('Not subscribed to members channel'));
    subscribe(updatesAdminsChannel, messageHandler)
        .catch(() => console.log('Not subscribed to admins channel'));
    subscribe(updatesGuestsChannel, messageHandler)
        .catch(() => console.log('Not subscribed to guest channel'));
}

function messageHandler(message, channel) {
    const channelName = channel.name;
    const channelResource = channel.resourceId ? `-${channel.resourceId}` : '';
    let newMessageLine = `${channelName}${channelResource}: ${message.payload}\n`;
    $w('#receivedMessages').value += newMessageLine;
}

function setupPublishButtons() {
    $w('#updateButton').onClick(event => {
        publish(event.target, updatesChannel);
    });

    $w('#memberUpdateButton').onClick(event => {
        publish(event.target, updatesMembersChannel);
    });

    $w('#adminUpdateButton').onClick(event => {
        publish(event.target, updatesAdminsChannel);
    });

    $w('#guestUpdateButton').onClick(event => {
        publish(event.target, updatesGuestsChannel);
    });
}

async function publish(button, channel) {
    if ($w('#message').value) {
        button.disable();
        $w('#message').disable();

        await publishMessage(channel, $w('#message').value);
        $w('#message').value = undefined;
        $w('#message').enable();
        button.enable();
    }
}
```
</details>

<details open> 
<summary> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 18" width="22" height="22">
    <path d="M16.003 15.18c0 .57-.11 1.01-.31 1.32.2.31.31.75.31 1.32 0 .94.33 1.22.53 1.24.27.02.481.25.471.52-.01.27-.22.48-.49.48-.521 0-1.512-.47-1.512-2.24 0-.51-.1-.74-.16-.81h-.06c-.06 0-.11 0-.16-.01a.505.505 0 0 1-.561-.29.522.522 0 0 1-.04-.21c0-.08 0-.17.04-.25.1-.22.35-.32.58-.27h.2c.06-.06.17-.29.17-.81 0-1.77.992-2.24 1.513-2.24.28 0 .5.22.5.5s-.22.5-.5.5c-.18.02-.511.3-.511 1.24l-.01.01Zm5.967 1.1c-.09-.22-.33-.33-.57-.28h-.211c-.06-.06-.17-.29-.17-.81 0-1.77-.991-2.24-1.512-2.24-.27 0-.48.21-.49.48-.01.27.2.5.47.52.2.02.53.3.53 1.24 0 .57.11 1.01.311 1.32-.2.31-.31.75-.31 1.32 0 .94-.33 1.22-.511 1.24-.28 0-.5.22-.5.5s.22.5.5.5c.52 0 1.512-.47 1.512-2.24 0-.51.1-.74.16-.81h.06c.06 0 .11 0 .15-.01.23.06.47-.05.57-.27.041-.08.041-.17.041-.25 0-.07 0-.14-.04-.21h.01ZM17.014 4H6.001C5.451 4 5 4.45 5 5v14c0 .55.45 1 1.001 1h7.008v-1H6.001V5h11.013v6h1.001V5c0-.55-.45-1-1-1Zm-9.01 7h7.008v-1H8.004v1Zm7.008-4H8.004v1h7.008V7Z"></path>
  </svg> Simple </summary> 

```javascript
import { realtime } from "@wix/site-realtime";
import { publishMessage } from 'backend/realtime.web.js';
const channel = { name: 'hello-world' };

$w.onReady(function () {
    realtime.subscribe(channel, (message) => {
        $w('#receivedMessages').value += (message.payload + '\n');
    });    
    $w('#publishMessageButton').onClick(async () => {
        if($w('#message').value) {
            $w('#publishMessageButton').disable();
            $w('#message').disable();
            await publishMessage(channel, $w('#message').value);
            $w('#message').value = undefined;
            $w('#message').enable();
            $w('#publishMessageButton').enable();
        }
    });
});
```
</details>

<!-- Static content -->
## Get Help
--- 
### Join the community 

Join the [Wix Studio][discord-community] community on Discord, where experienced developers and fellow creators come together to share tips, troubleshoot issues, and collaborate.

### Hire a developer 

Building a coded solution on your own can be challenging. Let an experienced Wix developer build it for you, so you can keep working on your site or business.
Visit the [Wix Marketplace][wix-marketplace] to find a trusted developer. 

<!-- Predefined links -->
[discord-community]: https://discord.com/invite/GhdmDN926z 
[wix-marketplace]: https://www.wix.com/marketplace/brief-auto-match/web-developer?entry=velo&origin=examples-page "Wix Marketplace"