make chat into js library style