In a medium saucepan, whisk together the unsweetened cocoa powder, granulated sugar, salt, and flour (if using). Ensure there are no lumps.
Gradually whisk in the milk until the mixture is smooth. It might seem thin at this stage, but don't worry, it will thicken as it cooks.
Place the saucepan over medium heat. Stir constantly with a whisk or wooden spoon, ensuring you scrape the bottom and sides to prevent scorching.
Continue to cook and stir until the mixture begins to thicken, about 5-8 minutes. It should reach a consistency similar to thin pudding or traditional gravy. Be patient; it should not boil vigorously.
Once thickened to your desired consistency, remove the saucepan from the heat. Stir in the unsalted butter until it's completely melted and incorporated.
Finally, stir in the vanilla extract. Taste and adjust sweetness if needed, though it's typically perfect as is.
Serve warm immediately.