execute a command when extension ringing asterisk - asterisk

I used these commands for save CallerID in database :
exten => s,1,MYSQL(Connect connid localhost root 123456 CallerID)
exten => s,2,Set(idcaller=${CALLERID(name)})
exten => s,3,MYSQL(Query resultid ${connid} INSERT INTO CallerID SET Num="${idcaller}")
exten => s,4,MYSQL(Disconnect ${connid})
Now i want to execute these commands when extension is ringing ...
It means that first IVR works then the diall extension Id then these Commands have to work ...
where i have to put my commands ?
thanks alot .

You can't do anything on ringing state, it is not implemented in asterisk
You can do that when extension entered before dial - just put that before dial command like
exten => 100,1,MYSQL(Connect connid localhost root 123456 CallerID)
exten => 100,2,Set(idcaller=${CALLERID(name)})
exten => 100,3,MYSQL(Query resultid ${connid} INSERT INTO CallerID SET Num="${idcaller}")
exten => 100,4,MYSQL(Disconnect ${connid})
exten => 100,n,Dial(SIP/100,,ro)
NOTE, MYSQL command is depricated. User func_odbc or realtime.

To do something when extension is ringing you have to use AMI interface and write your own application using it to detect ringing state and write it to database (or do anything else you like).
https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=4817239

Related

How to call an another phone after hangup the first?

I would like to call a phone, hangup and call an another phone from the server.
Like this :
Server->Phone A->Hangup->Server->phone B
This is what I already tried :
[appel]
exten => a,1,Answer
[do something]
exten => 2,1,Goto(pasCharge)
[pasCharge]
exten => [do something]
exten => ce,2,Dial(SIP/vincent)
exten => [doSomething]
exten => ce,3,Hangup
I have the first call (appel) but not the second (centre). It just hangup after the first.
Could you help me please ?
If you want dialplan be able continue after hangup of first call, you shoudl add g option to dial param
pro-sip.net> core show application Dial
-= Info about application 'Dial' =-
.....
[Syntax]
Dial(Technology/Resource[&Technology2/Resource2[&...]][,timeout[,options[,URL]]])
....
g: Proceed with dialplan execution at the next priority in the current
extension if the destination channel hangs up.
To build on what #arheops was saying, adding the lowercase g in the Dial() command instructs Asterisk that when the called party hangs up, continue to execute commands in the current context at the next priority.
So you could do something like this:
[pasCharge]
exten => ce,2,Dial(SIP/vincent,g)
exten => ce,3,Dial(SIP/Vbourdon,g)
exten => ce,4,[doSomething]
This would dial vincent then Vbourdon, and your doSomething could be a Goto, etc, anything you like.

Playback an audio file to a specific channel in asterisk dialplan

I need to make a voice translation service on active calls like skype, for that purpose I need to record voice from caller and whisper the translated voice to callee and vise-versa
I need to add to the dialplan lines to playback audio to the other channel with lower voice but current playback app doesn't have this option
any solution for that?
this is my code below
[macro-speech]
;;Speech recognition demo:
;exten => s,1,Answer()
exten => s,1,agi(googletts.agi,"Say something in English, when done press the pound key.",en)
exten => s,n(record),agi(speech-recog.agi,en-us)
exten => s,n,Verbose(1,Script returned: ${confidence} , ${utterance},en-us)
;Check the probability of a successful recognition:
exten => s,n(success),GotoIf($["${confidence}" > "0.6"]?playback:retry)
;Playback the text:
exten => s,n(playback),agi(googletts.agi,"The text you just said was...",en)
exten => s,n,agi(googletts.agi,"${utterance}",en)
;------------- Translate to different languages
;Translate a text string from english to german:
exten => s,n,agi(googletranslate.agi,"${utterance}",de)
exten => s,n,agi(googletts.agi,"${gtranslation}",de)
;------------------------------------------------
exten => s,n,goto(record)
;Retry in case speech recognition wasn't successful:
exten => s,n(retry),agi(googletts.agi,"Can you please repeat more clearly?",en)
exten => s,n,goto(record)
exten => s,n(fail),agi(googletts.agi,"Failed to get speech data.",en)
exten => s,n(end),Hangup()
freepbx11*CLI> core show function VOLUME
-= Info about function 'VOLUME' =-
[Synopsis]
Set the TX or RX volume of a channel.
[Description]
The VOLUME function can be used to increase or decrease the 'tx' or 'rx' gain
of any channel.
For example:
Set(VOLUME(TX)=3)
Set(VOLUME(RX)=2)
Set(VOLUME(TX,p)=3)
Set(VOLUME(RX,p)=3)
[Syntax]
VOLUME(direction[,options])
[Arguments]
direction
Must be 'TX' or 'RX'.
options
p: Enable DTMF volume control
[See Also]
Not available
freepbx11*CLI>

generate event on asterisk dialplan if any user left confbridge

I am using confBridge in my asterisk for conferencing. I want to detect if number of user remain less than or equal to 1 in ongoing call then terminate the conference call.
I have tried this-
exten => ConfTest,1,System(asterisk -rx "confbridge kick ${DB(CONF/NUM)} ${DB(CONF/ConfTest)}")
exten => ConfTest,n,Set(DB(CONF/ConfTest)=${CHANNEL})
exten => ConfTest,n,Set(ID=${RAND(1,500)})
exten => ConfTest,n,Set(DB(CONF/NUM)=${ID})
exten => ConfTest,n,Set(target=ConfTest1)
exten => ConfTest,n,Originate(SIP/${target},app,confBridge,${ID},default_user)
exten => ConfTest,n,Set(target=ConfTest2)
exten => ConfTest,n,Originate(SIP/${target},app,confBridge,${ID},default_user)
exten => ConfTest,n,Macro(dialout-trunk-predial-hook-test)
exten => ConfTest,n,confbridge(${ID},,src_user)
exten => ConfTest,n,Answer()
exten => ConfTest,n,Set(i=1)
exten => ConfTest,n,While($[${i} = 1])
exten => ConfTest,n,GoToIf($[0${CONFBRIDGE_INFO(parties,${ID})} <= 1]?18:15)
exten => ConfTest,n,NoOp(number of participants in conference call = ${CONFBRIDGE_INFO(parties,${ID})})
exten => ConfTest,n,Wait(1000)
exten => ConfTest,n,EndWhile()
exten => ConfTest,n,System(asterisk -rx "confbridge kick ${DB(CONF/NUM)} ${DB(CONF/ConfTest))
here lines are not executing from while loop.
Is there any thing available to register hangup handler for all the channel involve in conference call.
For example-
debianpc08*CLI> confbridge list 1
Channel User Profile Bridge Profile Menu CallerID
============================= ================ ================ ================ ================
SIP/ConfTest1-0000009c default_user default_bridge ConfTest1
SIP/ConfTest2-0000009d default_user default_bridge ConfTest2
SIP/ConfTest3-0000009b src_user default_bridge ConfTest3
here i want to register hangup handler for all the channels like SIP/ConfTest1-0000009c.
You can use default hangup handler(h-extension) to catch that
;record situation
exten => ConfTest,n,Set(HANGUP_OK=NO)
exten => ConfTest,n,confbridge(${ID},,src_user)
; if user exit confbridge, clear it
exten => ConfTest,n,Set(HANGUP_OK=YES)
; if hanguped in confbridge, do something
exten => h,1,GotoIF($[ "${HANGUP_OK}" == "NO" ]?dosomething,s,1)
You are going the wrong about it. Your best choice for this task would be to use Asterisk ARI and the bridges API. The idea will be very simple, initiate a Stasis application to handle your bridge, put the channels into the bridge. As they come in and out of the bridge, listen to the WebSocket events to see who left and who came in.
You can have a look at http://www.phpari.org for additional information on how to write such an application, the demo dial application should give you ample information on how to do it.
Nir

Get extensions list in Asterisk with AMI

I'm running Asterisk 11.4.0 and I've got access to it with AMI. How can I get list of all extensions (not peers or users)?
For example, I've got dialplan like this:
exten = _XXXX,1,Verbose(Start recording!)
exten = _XXXX,2,NoOp()
exten = _XXXX,3,Set(SCREEN_FILE=${STRFTIME(${EPOCH},,%d.%m.%Y-%H:%M:%S)}_${CALLERID(num)}>${EXTEN}.gsm)
exten = _XXXX,4,MixMonitor(${SCREEN_FILE},b)
exten = _XXXX,5,Dial(SIP/${EXTEN})
exten = _XXXX,6,StopMonitor()
exten = _XXXX,7,Hangup()
exten = _49000030[0-9a-zA-Z.#_/-].,1,Goto(test1,${EXTEN},1)
exten = _49000033[0-9a-zA-Z.#_/-].,1,Goto(test2,${EXTEN},1)
So, my extensions are _XXXX, 49000030[0-9a-zA-Z.#/-]. and 49000033[0-9a-zA-Z.#/-].
Hate answering my own questions, but...
For this purpose one can use AMI command like this:
Action: 'GetConfig',
Filename: 'extensions.conf',
Category: 'default'
In the response, you will get object containing each line of "default" context as it's field. All the extensions can be easily parsed from it.

Red5phone Busy or Rejected before call established?

I did like this :
1. install red5,asterisk
2. setting environment variable, such as java, apache-ant
3. configure sip.conf at asterisk
4. Running Red5phone
It's successfully registered, but when I call between two client the Red5phone ended calling and shows that Busy or Rejected?
I don't have any idea about it. What must I do?
thanks in advance.
My sip.conf configuration :
[general]
enabled=yes
bindaddr =0.0.0.0
context=lain-lain
allowoverlap=no
srvlookup=yes
[1000]
username=1000
secret=1234
host=dynamic
disallow=all
qualify=yes
type=peer
context=digium
allow=alaw
allow=ulaw
[1001]
username=1001
secret=1234
host=dynamic
disallow=all
qualify=yes
type=peer
context=digium
allow=alaw
allow=ulaw
my extensions.conf :
[globals]
[general]
autofallthrough=yes
[lain-lain]
[digium]
exten => 1000,1,Dial(SIP/1000)
exten => 1001,1,Dial(SIP/1001)
include => internal
include => remote
[internal]
# This is how we get to our voicemail. Dial 123 from any SIP connected phone.
exten => 123,1,Answer()
exten => 123,2,VoiceMailMain(0203123456)
exten => 123,3,Hangup()
# If we’re trying to call any extension that starts with the number 2 and has 4 digits only, assume internal.
exten => _2XXX,1,NoOp()
exten => _2XXX,n,Dial(SIP/${EXTEN},30)
exten => _2XXX,n,Playback(the-party-you-are-calling&is-curntly-unavail)
exten => _2XXX,n,Hangup()
[remote]
# Anything that isn’t internal we send to the PSTN.
exten => _X!,1,NoOp()
exten => _X!,n,Dial(SIP/siptrunk/${EXTEN})
exten => _X!,n,Hangup()
[incoming]
# This is where calls coming in from the PSTN are directed – see context setting in sip.conf
exten => _X.,1,NoOp()
# Try and call the desktop and mobile. If this fails, direct to voicemail.
exten => _X.,n,Dial(SIP/jamesdesktop)
exten => _X.,n,Dial(SIP/jamesmobile)
exten => _X.,n,VoiceMail(0203123456,u)
exten => _X.,n,Hangup()
First, thanks to #gnxtech3 for your attention
finally, I make it. the solution is about configuration at module.conf
i put this line of code at my module.conf :
[modules]
.
.
load = app_dial.so
dont forget to reload asterisk.

Resources