เคยเขียนถึง Asterisk CLI ไป วันนี้จะบันทึกเกี่ียวกับ AGI
AGI - Asterisk Gateway Interface
AGI เป็นช่องทางหรือชุดคำสั่ง ที่เปิดทางให้เราสามารถควบคุมช่องสัญญาณ (ZAP Channel) ผ่านทาง stdin และ stdout นั้นหมายความว่า เราสามารถใช้ภาษาอะไรก็ได้ไม่ว่าจะเป็น PERL, PHP, Pytho, Ruby, Java, C/C++, .NET language (C#,VB.NET,etc...) ไม่เว้นแม้แต่ shell ต่างๆ (bash, ash, korn, etc...) ติดต่อกับ AGI ได้อย่างง่ายดาย
AGI จะต่อกับกับ dialplan และจะถุกเรียกใช้จาก extensions.conf
EAGI จะติดต่อเกี่ยวกับ channel
DeadAGI จะใช้สำหรับต่อต่อกับ channel หลังการวางหู
FastAGI ยังช่วยให้คุณสามารถติดต่อ AGI ผ่าน TCP ได้อีกด้วย
คำสั่ง AGI มีอะไรบ้าง?
นอกจากจะดูได้ ที่นี่ ที่นี่ และที่นี่แล้ว คุณสามารถเข้าไปที่ Asterisk CLI แล้วพิมพ์คำสั่ง
show agi [agi-command]
หรือการต้องการเอกสาร AGI ให้ใช้คำสั่ง
dump agihtml <filename>
<filename> ใส่ชื่อไฟล์ที่ต้องการเท่านั้น ไฟล์จะถูกบันทึกอยู่ใน /tmp/<filename>
หลังจาก dump คำสั่งมา พบว่า คำสั่ง AGI ทั้งหมดมีดังนี้
AGI Command
answer - Answer channel
Usage: ANSWER
channel status - Returns status of the connected channel
Usage: CHANNEL STATUS []
database del - Removes database key/value
Usage: DATABASE DEL
database deltree - Removes database keytree/value
Usage: DATABASE DELTREE [keytree]
database get - Gets database value
Usage: DATABASE GET
database put - Adds/updates database value
Usage: DATABASE PUT
exec - Executes a given Application
Usage: EXEC
get data - Prompts for DTMF on a channel
Usage: GET DATA [timeout] [max digits]
get full variable - Evaluates a channel expression
Usage: GET FULL VARIABLE []
get option - Stream file, prompt for DTMF, with timeout
Usage: GET OPTION [timeout]
get variable - Gets a channel variable
Usage: GET VARIABLE
hangup - Hangup the current channel
Usage: HANGUP []
noop - Does nothing
Usage: NoOp
receive char - Receives one character from channels supporting it
Usage: RECEIVE CHAR
receive text - Receives text from channels supporting it
Usage: RECEIVE TEXT
record file - Records to a given file
Usage: RECORD FILE \
say alpha - Says a given character string
Usage: SAY ALPHA
say digits - Says a given digit string
Usage: SAY DIGITS
say number - Says a given number
Usage: SAY NUMBER
say phonetic - Says a given character string with phonetics
Usage: SAY PHONETIC
say date - Says a given date
Usage: SAY DATE
say time - Says a given time
Usage: SAY TIME
say datetime - Says a given time as specfied by the format given
Usage: SAY DATETIME [format] [timezone]
send image - Sends images to channels supporting it
Usage: SEND IMAGE
send text - Sends text to channels supporting it
Usage: SEND TEXT ""
set autohangup - Autohangup channel in some time
Usage: SET AUTOHANGUP
set callerid - Sets callerid for the current channel
Usage: SET CALLERID
set context - Sets channel context
Usage: SET CONTEXT
set extension - Changes channel extension
Usage: SET EXTENSION
set music - Enable/Disable Music on hold generator
Usage: SET MUSIC ON
set priority - Set channel dialplan priority
Usage: SET PRIORITY
set variable - Sets a channel variable
Usage: SET VARIABLE
stream file - Sends audio file on channel
Usage: STREAM FILE [sample offset]
control stream file - Sends audio file on channel and allows the listner to control the stream
Usage: CONTROL STREAM FILE [skipms] [ffchar] [rewchr] [pausechr]
tdd mode - Toggles TDD mode (for the deaf)
Usage: TDD MODE
verbose - Logs a message to the asterisk verbose log
Usage: VERBOSE
wait for digit - Waits for a digit to be pressed
Usage: WAIT FOR DIGIT
AGI with PHP
ตอนนี้ผมสนใจเฉพาะ PHP project แล้ว PHP กับ AGI มีอะไรน่าสนใจบ้าง?
Astrisk PHP บอกว่า project เค้าเร็วกว่าและยืดหยุ่นกว่า phpAGI นะ อันนี้ยังไม่รู้ ใช้แล้วเดี่ยวก็รู้เอง
และดูเหมือนคนจะใช้ Asterisk PHP เยอะกว่าด้วย
Asterisk PHP Function Reference
int asterisk_answer([string channel])
int asterisk_best_codec([string channel])
int asterisk_bridge_call([string channel,] string peer[, array options])
array asterisk_chanlist(void)
int asterisk_channel_make_compatible([string channel,] string peer)
int asterisk_channel_setoption([string channel,] int option, string data)
int asterisk_channel_status([string channel])
int asterisk_cli(int fd, string cmd)
string asterisk_codec2str(int codec)
int asterisk_control_streamfile([string channel,] string file, string fwd, string rev, string stop, string pause[, int skipms])
int asterisk_db_del(string family, string keys)
int asterisk_db_deltree(string family[, string keytree])
int asterisk_db_get(string family, string keys)
int asterisk_db_put(string family, string keys, string value)
int asterisk_exec([string channel,] string app[, string data])
string asterisk_getdata([string channel,] string filename[, int maxdigits[, int timeout]])
int asterisk_getformatbyname(string name)
string asterisk_getformatname(int format)
int asterisk_get_priority([string channel])
string asterisk_get_variable([string channel,] string variable)
array asterisk_get_variables([string channel])
int asterisk_hangup([[string channel,] int cause])
asterisk_log(long log, string message)
int asterisk_manager_command(int fd, string cmd)
asterisk_moh_start([[string channel,] string class])
asterisk_moh_stop([string channel])
int asterisk_recvchar([[string channel,] int timeout])
string asterisk_request(string type, int format, string data, int &cause)
string asterisk_request_and_dial(string type, int format, string data, int timeoute, int outstate, string callerid)
int asterisk_say_character_str([string channel,] string chars, [string ints[, string lang]])
int asterisk_say_date([string channel,] [int time[, string ints[, string lang[, string format[, string timezone]]]]])
int asterisk_say_datetime([string channel,] [int time[, string ints[, string lang]]])
int asterisk_say_datetime_from_now([string channel,] [int time[, string ints[, string lang]]])
int asterisk_say_digit_str([string channel,] string digits, [string ints[, string lang="en"]])
int asterisk_say_number([string channel], int number, [string ints[, string lang[, string options]]])
int asterisk_say_phonetic_str([string channel,] string text[, string ints[, string lang]])
int asterisk_say_time([string channel,] [int time[, string ints[, string lang]]])
int asterisk_senddigit([string channel,] string digit)
int asterisk_send_image([string channel,] string image)
int asterisk_sendtext([string channel,] string text)
asterisk_set_best_read_format([string channel])
asterisk_set_best_write_format([string channel])
asterisk_set_callerid([string channel,] string callerid[, boolean anitoo])
int asterisk_set_context([string channel,] string context)
int asterisk_set_extension([string channel,] string exten)
int asterisk_set_priority([string channel,] int priority)
asterisk_set_read_format([string channel,] int format)
int asterisk_set_variable([string channel,] string variable, string value)
int asterisk_setwhentohangup([[string channel,] int timeout])
asterisk_set_write_format([string channel,] int format)
string asterisk_state2str(int state)
int asterisk_stream_file([string channel,] string filename[, string digits[, int offset[, string lang]]])
int asterisk_tdd_mode([[string channel,] int mode])
asterisk_verbose(int level, string message)
asterisk_waitfor([string channel,] int wait)
int asterisk_waitfordigit([[string channel,] int timeout])
Links
http://www.voip-info.org/wiki/index.php?page=Asterisk+AGI
http://www.voip-info.org/wiki/index.php?page=Asterisk+EAGI
http://www.voip-info.org/wiki/index.php?pa...sterisk+FastAGI
How to setup PHP to work with the Asterisk Gateway Interface (AGI)
Introduction to AGI programming, Kyle Sexton (PDF)
>> ดูเหมือนคนจะใช้ Asterisk PHP เยอะกว่าด้วย
มา update ว่า คนใช้ phpagi น่าจะเยอะกว่า (แต่เยอะกว่าไม่ได้แปลว่า มันดีกว่า) อาจเพราะ opensource หลายๆ ตัวมักใช้ phpagi กันอยู่แล้ว
ผมก็ใช้แต่ phpagi