complete chat function