Asterisk func realtime
Synopsis:
RealTime Read/Write FunctionsDescription:
REALTIME(family|fieldmatch[|value[|delim1[|delim2]]]) on readREALTIME(family|fieldmatch|value|field) on write
This function will read or write values from/to a RealTime repository.
REALTIME(....) will read names/values from the repository, and
REALTIME(....)= will write a new value/field to the repository.
Notes
- CLI> core show function REALTIME
Return value
On a read, this function returns a delimited text string. The name/value pairs are delimited by delim1, and the name and value are delimited between each other with delim2. The default for delim1 is '=' and the default for delim2 is '|'. If there is no match, NULL will be returned by the function. On a write, this function will always return NULL.Example reading from realtime repository (AEL2 statement):
_6XX => {
Set(row="${REALTIME(sipusers,callerid,${EXTEN})}"); //executing SELECT * FROM <sipusers>* WHERE callerid=${EXTEN} into variable $row
NoOp(${row});
Set(col_name_pair=${CUT(row,"|",1)});
NoOp(${col_name_pair}); //col_name_pair become: name=mysipuser
Set(col_name=${CUT(col_name_pair,"=",2)});
NoOp(${col_name}); //col_name become: mysipuser (and that's what we want)
Dial(SIP/${col_name});
};
Set(row="${REALTIME(sipusers,callerid,${EXTEN})}"); //executing SELECT * FROM <sipusers>* WHERE callerid=${EXTEN} into variable $row
NoOp(${row});
Set(col_name_pair=${CUT(row,"|",1)});
NoOp(${col_name_pair}); //col_name_pair become: name=mysipuser
Set(col_name=${CUT(col_name_pair,"=",2)});
NoOp(${col_name}); //col_name become: mysipuser (and that's what we want)
Dial(SIP/${col_name});
};
- <sipusers> is name of data family configured in extconfig.conf
Example output:
— Executing 656@comapny:1 Set("SIP/micj-081e7a60", "row="name=mic12|callerid=443111656|host=dynamic|secret=secret123|context=company|ipaddr=10.10.10.14|port=5060|regseconds=1169961269|username=mic12|"") in new stack
— Executing 656@comapny:2 NoOp("SIP/micj-081e7a60", "name=mic12|callerid=443111656|host=dynamic|secret=secret123|context=company|ipaddr=10.10.10.14|port=5060|regseconds=1169961269|username=mic12|") in new stack
— Executing 656@comapny:3 Set("SIP/micj-081e7a60", "col_name_pair=name=mic12") in new stack
— Executing 656@comapny:4 NoOp("SIP/micj-081e7a60", "name=mic12") in new stack
— Executing 656@comapny:5 Set("SIP/micj-081e7a60", "col_name=mic12") in new stack
— Executing 656@comapny:6 NoOp("SIP/micj-081e7a60", "mic12") in new stack
— Executing 656@comapny:7 Dial("SIP/micj-081e7a60", "SIP/mic12") in new stack
Example reading from realtime in extensions.conf
I couldn't get mysql and the switch Realtime/context@extensions to work.So using the same sql table i came up with this instead... it's missing a few cases (eg. Macro)
exten => _.,1,Set(row="${REALTIME(extensions,exten,${EXTEN})}")
exten => _.,2,Set(app=${CUT(row,"|",5)})
exten => _.,3,Set(appdatapair=${CUT(row,"|",6)})
exten => _.,4,Set(appdata=${CUT(appdatapair,"=",2)})
exten => _.,5,GotoIf($"${app}" != "Goto"?6:11)
exten => _.,6,Set(opt0=${CUT(appdata,"\,",1)})
exten => _.,7,Set(opt1=${CUT(appdata,"\,",2)})
exten => _.,8,Set(opt2=${CUT(appdata,"\,",3)})
exten => _.,9,NoOp(${opt0},${opt1},${opt2})
exten => _.,10,Goto(${opt0},${opt1},${opt2})
exten => _.,11,GotoIf($"${app}" != "Dial"?12:14)
exten => _.,12,Dial(${appdata})
exten => _.,13,Hangup()
exten => _.,14,Answer()
exten => _.,15,Playback(pbx-invalid)
exten => _.,16,Hangup()
Example writing to database using realtime
Add avp into extconfig.confavp => pgsql,hostedpbx,thiak_avp
and add new extension into extension.conf
exten => s,n,Set(REALTIME(avp|attribute|USED_CHANS/BOB|value)=1)
This will execute the following SQL:
UPDATE avp SET value = '1' WHERE attribute = 'USED_CHANS/BOB'

Comments