How To Send Text Chat Message To External Storage

Diarkis Room comes with text chat functionality. Chat data is stored and managed within a room's memory and will not be persisted. If you need to persist the chat data, you need to send chat data somewhere else.

Here, we explain how to send the chat message data elsewhere when a new text chat message is received on the server.

// import github.com/Diarkis/dairkis/server, github.com/Diarkis/diarkis/room github.com/Diarkis/diarkis/util

// This exposes all room commands
room.ExposeCommands()
// This exposes all room support commands including text chat
roomSupport.ExposeCommands()

// Make sure you write this block of code AFTER calling room.ExposeCommands() and roomSupport.ExposeCommands()
// By doing so, we make sure sendTextChatData function is executed after the text chat is handled
server.HandleCommand(util.CmdBuiltInVer, util.CmdRoomChatSync, sendTextChatData)

// This function handles the sending of incoming text chat message
func sendTextChatData(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)) {
if len(payload) == 0 {
// Empty data, ignore it
next(nil)
return
}
textChatData := string(payload)
// Send textChatData somewhere else here!
next(nil)
}