chat middleware