ReadonlydataThe message payload sent by the host. Matches https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data.
If true, the event is able to trigger. If false, the event will not trigger.
ReadonlyreplyToken identifying the message currently being delivered, for replying
asynchronously. Read it inside the bound callback (before any await)
and pass it to MessageEvent.reply once the result is ready.
Reading the token marks the delivery as deferred, so the sender keeps waiting for the reply. If a callback neither replies nor reads the token, the request is completed with an error as soon as the callback returns, letting the sender fail fast instead of waiting for its timeout. Empty for messages that don't expect a reply.
ReadonlytopicThe routing topic of this message event. Use this to filter messages by channel in your bind callback.
ReadonlytypeThe MIME type of MessageEvent.data, e.g. "application/json".
Binds a callback function to this event.
StaticgetReturns the typename of the SceneEvent.
Returns true if the object matches or derives from the passed in type.
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Send a response back to the host that sent this message. Each message may be replied to at most once.
Called without token, this replies to the message currently being
delivered and is only valid inside the bound callback. To reply after
asynchronous work (e.g. an await, a timeout, or a later frame),
capture MessageEvent.replyToken inside the callback and pass it
here.
data may be any JS value (object, array, string, number, etc.). It is
serialized via the stringified-js transport so the host receives the
value with its original shape and types (including types that plain JSON
cannot represent, e.g. Map/Set/Date/BigInt).
Optionaltoken: string
Event fired when a message is received from the host (Lens Studio or an AI agent). Subscribe via ScriptComponent.createEvent with "MessageEvent". Use MessageEvent.topic to route messages and MessageEvent.reply to send a response back to the sender.
MessageEvent.topic, MessageEvent.type, and MessageEvent.replyToken are only valid inside the bound callback for the message currently being delivered. MessageEvent.reply can be called directly inside the callback, or after asynchronous work by passing a token captured from MessageEvent.replyToken inside the callback.
Since
Lens Scripting Version 373
Snap OS
Example