Auto-Responder
This demo shows how to use .on() and .remove(),
together with the ability to send private messages,
to greet new joiners with a personalized DM.
Toggle the auto-responder to greet new joiners with a personalized DM. Open this page in another tab to see the greeting arrive.
Note: You can do some pretty clever things with the
join event, such as sharing memory between connections without
the need for backend storage, or having everyone in channel greet the joiner so they can determine who is online, the fastest connection
(first to greet them), etc.In this window, you are ....
no messages yet...
import { connect } from 'itty-sockets'
const channel = connect('examples:auto-responder', {
announce: true, // include uid/alias in join/leave events
echo: true, // receive your own messages back
as: '...', // display name (alias)
})
// greet new joiners with a personalized DM
const greet = ({ uid, alias }) => {
channel.send({ text: `Hey ${alias}, welcome!` }, uid)
}
// toggle auto-responder on/off
channel.on('join', greet) // enable
channel.remove('join', greet) // disable