There is no mechanical way to determine the communicative intent of a sentence with 100% certainty.
Things like word order, word choice, intonation, punctuation, etc. will help but all sentences are used within a broader communicative context to achieve various speech acts. Sometimes, these are clearly signalled. Other times, they require a complex human understanding of the situation in order to be able to fully parse what's going on. And, remember, often, even humans misunderstand each other. How often do you hear people answer rhetorical questions.
Take the simple 'How are you?' Most often, it is used as part of a greeting and it does not require an answer. But very often it does. But speakers may have to elaborate. 'I really mean it.', etc. Or people will follow up a question with - 'This is a rhetorical question.' You will even hear things like 'This is a rhetorical question but I'm going to answer it anyway.'