Hi! This question is quite intresting, recently plant biologists identified the strategy used by plants to recognize an attack. when insect ingest parts of a plant digestion turns proteins into a peptide elicitor, which is secreted back into the plant during subsequent feedings. the plant recognizes this elicitor and launches its defensive chemistry.
i think this explanation is useful for your concern.