Remote control solution

I’m running Asterisk on Fedora, and it work just perfectly.
Now, I am writing an mobile app to use Asterisk originate two channels.
My solution for now as below:
Running a python script on server receiving TCP packet which contains two SIP numbers,
and then execute shell command “Asterisk -rx ‘originate …’”.
It works just correctly, however, since there are still some functions need to be implemented,
I’m wondering if it’s a efficient method?
For example, if I want to implement ‘hangup’ function,
I need to use ‘grep’ or ‘awk’ to figure out which channel I need to hangup,
so the whole command will look like this asterisk -rx \"channel request hangup $(asterisk -rx 'core show channels' | awk '/\/' number \>/ {print $1}' | head -1 )"
I guess it is too complex and efficientless,
Is there any other way to do it smarter?

Use AGI(Asterisk Gateway Programming), you can write API code to do the same.