How to force asterisk to take the output from a php script and compare for the further implementation of the dial plan?

Good day to all! Started to understand with asterisk not long ago, the question arose about how to set up speech recognition, and call the desired subscriber, there is a php script that works and returns the name. Example of output in cli:
-- Executing [1000@outcoling:4] AGI("SIP/1001-00000088", "voice.php/tmp/1485942576.136") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/voice.php
voice.php/tmp/1485942576.136: Ivan
-- <sip 1001-00000088>AGI Script yandex_voice.php completed, returning 0</sip>

Prompt how to make so that "Ivan" was picked up in the dial plan and compares the value and perform an action which corresponds, as I understand it you need to do using gotoif, here is an example of dial plan:
exten=1000,n,GotoIf($[“${?????????????????}” = “Ivan”]?6:3)
August 19th 19 at 22:40
3 answers
August 19th 19 at 22:42
exten => s,9,GotoIf($[${TEXT} = John]?11:13)) had to be so!
August 19th 19 at 22:44
Have you tried to use AGI set variable?
August 19th 19 at 22:46
Never use AGI
You can make a CURL and put the answer into a variable.
Often used system curl-Ohm invoking it through a SHELL

Find more questions by tags AsteriskPHP