# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
