How to bind a callback to the reactions in the ChatInterface component?

import panel as pn

def react_on_click(reactions):
    print(reactions)

def bind_on_send(instance, event):
    message = instance.objects[-1]
    pn.bind(react_on_click, message.param.reactions, watch=True)

ci = pn.chat.ChatInterface(button_properties={"send": {"post_callback": bind_on_send}})
ci.show()

This example demos how to add callbacks to messages after it’s been sent. When the user clicks on the heart reaction, [‘favorite’] will be printed.

image

1 Like