Message Handler Help


I am experimenting with the message handler, using the docs here:

But this simple script does not work in preview mode or in the browser.


So, the Hello text does not work, but the lower portion of the docs passing the time payload works…

Please post your code.

No one can help you without the code.

1 Like

Hm, yes that’s true. I deleted the first attempt and tried it again… now it works.

def onMessageReceived(self, payload):
	This method will be called when a message with the matching type code
	arrives at this component.

		self: A reference to this component
		payload: The data object sent along with the message
	# implement your handler here
	self.props.text = 'Hello'


def runAction(self, event):
	This event is fired when the 'action' of the component occurs.

		self: A reference to the component that is invoking this function.
		event: An empty event object.
	messageType = 'mh1'

IDK - the first time, nothing. Well, it works now, so I am moving forward!

1 Like

Beware that the default scope for sendMessage is “page”. Perhaps you were using a different page the first time around?

Well, assuming I followed the directions, lol, the view box should have been the only one checked. But I can’t go back in time!

The docs are wrong; that example provides no scope to the function call and so it will default to “page”, but the checkbox specified in the images is “view”. This will result in the example not working until you either use the page scope checkbox or you modify the function to use a scope of “view”.

I’ve reached out to the Docs team to update the example.