main chat functional