> For the complete documentation index, see [llms.txt](https://docs.digitalsamba.com/reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digitalsamba.com/reference/sdk/methods/sendmessagetocustomtile.md).

# sendMessageToCustomTile()

Posts a message to the iframe of the custom tile which was previously created with [addCustomTile()](/reference/sdk/methods/addcustomtile.md).

It is mainly used if you have listeners in your custom tile and want to inform your iframe.

{% hint style="warning" %}
The method must be called after you have add the custom tile. It won't do anything if there isn't an existing tile with a matching name.
{% endhint %}

{% hint style="info" %}
This method is often used in conjunction with the [addCustomTile()](/reference/sdk/methods/addcustomtile.md) and [removeCustomTile()](/reference/sdk/methods/removecustomtile.md) methods.
{% endhint %}

In the below example a custom AI tile is added to the stage and then a message send to it.

```javascript
sambaFrame.on('userJoined', (event) => {
   const data = event.data;
   if (data.type === 'local') {
     sambaFrame.addCustomTile({
        "name": "AI", 
        "html": '<iframe src="url to your customm site with a listener inside"></iframe>',
        "position": "last"
     });
     
     .....................
     
     //At some point later
     sambaFrame.sendMessageToCustomTile({
     
        //Identifier and title of your custom tile. Must match the name in addCustomTile
        "name": "AI",
        
        //A custom event name which your tile knows about
        "event": "muteInternally",
         
        /*
          The target origin for postMessage
          https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
        */
        "origin": "*" ,
        
        //Some custom payload data if you need        
        "data": {
          "everything": true/false
        }
     });
   }
});
```

```javascript
//Somewhere in your embedded iframe custom site
<script>
  window.addEventListener("message", (event) => {
    console.log(event.data);
    alert(JSON.stringify(event.data));
  }, false);
</script>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.digitalsamba.com/reference/sdk/methods/sendmessagetocustomtile.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
