useAppMessage wraps both sending and receiving in one hook.
Send and receive
useAppMessage returns a sendAppMessage function, and takes an onAppMessage callback for incoming messages:
onAppMessage callback must be memoized with useCallback, like all Daily React event callbacks.
Addressing messages
The second argument tosendAppMessage chooses recipients:
'*'sends to every other participant (the default broadcast).- A
session_idstring sends to one participant only.
App messages are not delivered to the sender. If you want the sender’s own UI to reflect the message (an optimistic chat bubble, your own reaction), update local state when you call
sendAppMessage, not from onAppMessage.Replying from the handler
onAppMessage receives sendAppMessage as its second argument, so you can respond to a message without calling the hook twice or threading the function through closures:
Patterns
Use atype field to multiplex different kinds of messages over the one channel:
Next steps
Handling events
The event model behind the callbacks.
sendAppMessage reference
The underlying daily-js method and limits.