While Realtime is fully functional without implementing anything in your function stacks, you may find yourself wanting to build function stacks to extend the functionality of Realtime. This is possible with the new Realtime Event function, located under APIs & Lambdas in the function panel.Documentation Index
Fetch the complete documentation index at: https://docs.xano.com/llms.txt
Use this file to discover all available pages before exploring further.

Using the Realtime Event Function
This function sends a message of type ‘event’ to the channel specified. Remember, a message can be anything from plain text to a JSON object for even further flexibility.
Please note that Event is different than Message, and will need to be handled accordingly by your frontend.
Example
Realtime connections do not log message history. This means that once a user leaves our Marvel chat room, if they come back, they won’t be able to see any of the previous messages. So, we want to store our messages in a database table as they are sent to the channel. We could approach this in a couple of different ways.- Have our frontend send an API request at the same time a message is sent to the channel to log the message.
- Have our frontend only send an API request, and our API can handle delivering the message once it is stored.
Code Explanation
Code Explanation
First, we define the function and make sure we define two parameters: channel for the channel to send the message to, and message for the message body.After that, we’re using fetch, a Javascript function to send API requests, to our endpoint. We don’t need to worry much about the technical details here if you aren’t comfortable, but you may need to change the method and/or add new parameters to the body of the request depending on your use case. For this example, all our API needs is that channel name and message.Now, we need to handle what happens when our Send button is clicked. We’ll start by looking for that element and adding an event listener to it. It just looks for our form, which has an ID of form, and a submit button inside of it.We’ll add a line to ensure that no ‘default’ behavior occurs when a user clicks the send button.Next, we’ll call our sendMessageToRealtime function and give it our ‘marvel-chat-room’ channel name and the value of the message input box. Right after that, we clear the input to prepare for the next message.


