Typical Asterisk script
What follows is a typical asterisk script (technically, scripts are called "contexts" in Asterisk jargon). It starts with a greeting followed by an invitation to select a language; then, it asks a single question and stores the answer in Q1. Along the way, the case call history is updated to reflect the circumstances.
; ------------------------------------------------ FRANÇAIS [oplus_petitemusique_f] exten => s,1,Answer exten => s,n,Set(CDR(userfield)=${number}) exten => s,n,AMD(3500|1500|300|5000|120|50|5|256) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_MACHINE"]?machine,1) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_PERSON"]?talk,1) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_NOTSURE"]?uncertain,1) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_HANGUP"]?h,1) exten => uncertain,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "uncertain") exten => uncertain,n,Goto(oplus_petitemusique_f_hangup,s,1) exten => machine,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "machine") exten => machine,n,Goto(oplus_petitemusique_f_hangup,s,1) exten => h,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "hung_up") exten => h,n,Goto(oplus_petitemusique_f_hangup,s,1) exten => fax,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "fax") exten => fax,2,Goto(oplus_petitemusique_f_hangup,s,1) exten => failed,1,set(CODE=-1) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 0 ]?"no_service":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 1 ]?"no_service":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 3 ]?"ring_no_answer":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 5 ]?"busy":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 8 ]?"out_line_unavailable":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${CODE} = -1 ]?"failed${CODE}":${CODE})}) exten => failed,n,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "${CODE}") exten => failed,n,Goto(oplus_petitemusique_f_hangup,s,1) exten => talk,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "response") exten => talk,n,Goto(oplus_petitemusique_f,s,21) exten => s,21,Playback(custom/dar/fr/dar-1-intro-f) exten => s,22,Background(custom/dar/fr/dar-2-langue-f) exten => 1,1,SetLanguage(fr) exten => 1,2,Goto(oplus_petitemusique_f_question,s,1) exten => 2,1,SetLanguage(en) exten => 2,2,Goto(oplus_petitemusique_e_question,s,1) exten => i,1,SetLanguage(fr) exten => i,2,Goto(oplus_petitemusique_f_question,s,1) exten => t,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "time_out_1") exten => t,2,Goto(oplus_petitemusique_f_hangup,s,1) exten => h,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "hung_up") exten => h,2,Goto(oplus_petitemusique_f_hangup,s,1) [oplus_petitemusique_f_question] exten => s,1,Set(LOOPCOUNT=0) exten => s,2,Playback(custom/dar/dar-3-please) exten => s,3,Background(custom/dar/dar-4-question) exten => 1,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "complete" Q1 1) exten => 1,2,Goto(oplus_petitemusique_f_end,s,1) exten => 2,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "complete" Q1 2) exten => 2,2,Goto(oplus_petitemusique_f_end,s,1) exten => 0,1,Goto(oplus_petitemusique_f_question,s,1) exten => i,1,Set(LOOPCOUNT=$[${LOOPCOUNT} + 1]) exten => i,2,GotoIf($[${LOOPCOUNT} > 9]?h,3) exten => i,3,Goto(oplus_petitemusique_f_question,s,2) exten => t,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "time_out_2") exten => t,2,Goto(oplus_petitemusique_f_hangup,s,1) exten => h,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "hung_up") exten => h,2,Goto(oplus_petitemusique_f_hangup,s,1) exten => h,3,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "excess_loop") exten => h,4,Goto(oplus_petitemusique_f_hangup,s,1) [oplus_petitemusique_f_end] exten => s,1,Playback(custom/dar/dar-5-merci) exten => s,2,Goto(oplus_petitemusique_f_hangup,s,1) [oplus_petitemusique_f_hangup] ; Cette section coupe la communication sans déclencher l'extension "h" ; et donc sans ajouter d'appel à l'historique d'appels exten => s,1,system(/usr/bin/cwASTstocke.sh ${interviewer} "released") exten => s,n,Hangup ; ------------------------------------------------ ANGLAIS [oplus_petitemusique_e] exten => s,1,Answer exten => s,n,Set(CDR(userfield)=${number}) exten => s,n,AMD(3500|1500|300|5000|120|50|5|256) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_MACHINE"]?machine,1) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_PERSON"]?talk,1) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_NOTSURE"]?uncertain,1) exten => s,n,GotoIf($["${AMDSTATUS}" = "AMD_HANGUP"]?h,1) exten => uncertain,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "uncertain") exten => uncertain,n,Goto(oplus_petitemusique_e_hangup,s,1) exten => machine,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "machine") exten => machine,n,Goto(oplus_petitemusique_e_hangup,s,1) exten => h,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "hung_up") exten => h,n,Goto(oplus_petitemusique_e_hangup,s,1) exten => fax,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "fax") exten => fax,2,Goto(oplus_petitemusique_e_hangup,s,1) exten => failed,1,set(CODE=-1) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 0 ]?"no_service":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 1 ]?"no_service":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 3 ]?"ring_no_answer":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 5 ]?"busy":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${OutgoingSpoolFailedReason} = 8 ]?"out_line_unavailable":${CODE})}) exten => failed,n,Set(CODE=${IF($[ ${CODE} = -1 ]?"failed${CODE}":${CODE})}) exten => failed,n,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "${CODE}") exten => failed,n,Goto(oplus_petitemusique_e_hangup,s,1) exten => talk,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "response") exten => talk,n,Goto(oplus_petitemusique_e,s,21) exten => s,21,Playback(custom/dar/fr/dar-1-intro-e) exten => s,22,Background(custom/dar/fr/dar-2-langue-e) exten => 1,1,SetLanguage(en) exten => 1,2,Goto(oplus_petitemusique_e_question,s,1) exten => 2,1,SetLanguage(fr) exten => 2,2,Goto(oplus_petitemusique_f_question,s,1) exten => i,1,SetLanguage(en) exten => i,2,Goto(oplus_petitemusique_e_question,s,1) exten => t,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "time_out_1") exten => t,2,Goto(oplus_petitemusique_e_hangup,s,1) exten => h,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "hung_up") exten => h,2,Goto(oplus_petitemusique_e_hangup,s,1) [oplus_petitemusique_e_question] exten => s,1,Set(LOOPCOUNT=0) exten => s,2,Playback(custom/dar/dar-3-please) exten => s,3,Background(custom/dar/dar-4-question) exten => 1,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "complete" Q1 1) exten => 1,2,Goto(oplus_petitemusique_e_end,s,1) exten => 2,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "complete" Q1 2) exten => 2,2,Goto(oplus_petitemusique_e_end,s,1) exten => 0,1,Goto(oplus_petitemusique_e_question,s,1) exten => i,1,Set(LOOPCOUNT=$[${LOOPCOUNT} + 1]) exten => i,2,GotoIf($[${LOOPCOUNT} > 9]?h,3) exten => i,3,Goto(oplus_petitemusique_e_question,s,2) exten => t,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "time_out_2") exten => t,2,Goto(oplus_petitemusique_e_hangup,s,1) exten => h,1,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "hung_up") exten => h,2,Goto(oplus_petitemusique_e_hangup,s,1) exten => h,3,system(/usr/bin/cwASTstocke.sh ${prefixe} ${projet} ${telkey} ${interviewer} ${nlignes} "excess_loop") exten => h,4,Goto(oplus_petitemusique_e_hangup,s,1) [oplus_petitemusique_e_end] exten => s,1,Playback(custom/dar/dar-5-merci) exten => s,2,Goto(oplus_petitemusique_e_hangup,s,1) [oplus_petitemusique_e_hangup] ; Cette section coupe la communication sans déclencher l'extension "h" ; et donc sans ajouter d'appel à l'historique d'appels exten => s,1,system(/usr/bin/cwASTstocke.sh ${interviewer} "released") exten => s,n,Hangup