hwo to stok variable wiith menu

Home » Asterisk Users » hwo to stok variable wiith menu
Asterisk Users 8 Comments

hello list,

i have created one menu like below all work without issue, what i want to
do is ,

when the customer press 3 in menu context exten => 3,1,Goto(support,s,1)
i want to stok this variable (3) in database or file instead to go to
support context

thanks for your help and support

best regards

[default]
exten => 529,1,Ringing()
exten => 529,2,Wait(4)
exten => 529,3,Goto(accueil,s,1)

[accueil] ; définition d’un contexte pour l’accueil
exten => s,1,SetGlobalVar(sounds_path=/var/lib/asterisk/sounds/)
exten => s,2,Background(${sounds_path}welcome)
exten => s,3,goto(accueil,s,1)
exten => #,1,Goto(menu,s,1)
exten => i,1,Playback(${sounds_path}erreur-saisie)
exten => i,2,goto(accueil,s,1)
exten => t,1,Goto(accueil,s,1)
[menu]
exten => s,1,Background(${sounds_path}menu)
exten => 0,1,Goto(menu,s,1)
exten => 1,1,Goto(appel,s,1)
exten => 2,1,Goto(message,s,1)
exten => 3,1,Goto(support,s,1)
exten => s,2,goto(menu,s,1)
exten => i,1,Playback(${sounds_path}erreur-saisie)
exten => i,2,Goto(menu,s,1)
exten => t,1,Goto(menu,s,1)

[appel] ; définition d’un contexte pour le menu d’appel
exten => s,1,Background(${sounds_path}appel)
exten => s,2,WaitExten(10)
exten => 0,1,Goto(menu,s,1)
exten => 223,1,Dial(SIP/${EXTEN},20,tr)
exten => i,1,Playback(${sounds_path}erreur-saisie)
exten => i,2,Goto(appel,s,1)
exten => t,1,Goto(appel,s,1)
[message] ; définition d’un contexte pour la messagerie
exten => s,1,VoiceMailMain(${CALLERIDNUM})
exten => t,1,Hangup()

[support] ; définition d’un contexte pour le support
exten => s,1,GoToIfTime(09:00-17:00|mon-fri|*|*?s,4)
exten => s,2,Playback(${sounds_path}no-relation-support)
exten => s,3,Goto(menu,s,1)
exten => s,4,Playback(${sounds_path}relation-support)
exten => s,5,Queue(default)
exten => t,1,Hangup()

8 thoughts on - hwo to stok variable wiith menu

  • You can save a value to a global variable like you did within your
    sample dialplan, although I do not recommend this approach, you should
    read the note below as to why.

    You can save a value to a channel variable with the Set() command and
    use it later within the same call.

    You can save a value into the AstDB with the Set(${DB())) and access the
    value from any channel even after an Asterisk restart.

    You can setup ODBC, func_odbc and a database then access the variables
    via the functions defined within the func_odbc.conf

    The method you choose should be determined by your needs.

    Note: You set the global variable at the start of your dialplan. This
    global variable is available to ALL channels. If you set it for every
    call, you are doing so needlessly. If you have multiple applications
    accessing the same variable and each one sets it with a different value,
    you will have problems. Global variables should be used to store
    information needed in the majority of calls. The way you are using the
    global variable, I believe you may be better off removing the
    SetGlobalVar() call and instead set the variable in the [globals]
    section of extensions.conf.

    I hope that helps.

    Dale

  • thanks for your response

    i use mysql like a database and my question when the customer press 3 in
    context menu i want to stok this variable in a table in my database and i
    want to get this variable after
    could you please give an exemple like below

    thanks and regards

    [menu]
    exten => s,1,Background(${sounds_path}menu)
    exten => 0,1,Goto(menu,s,1)
    exten => 1,1,Goto(appel,s,1)
    exten => 2,1,Goto(message,s,1)

    exten => 3,1,Goto(support,s,1)
    exten => s,2,goto(menu,s,1)
    exten => i,1,Playback(${sounds_path}erreur-saisie)
    exten => i,2,Goto(menu,s,1)
    exten => t,1,Goto(menu,s,1)
    2011/11/25 Dale Noll

  • hello Noll

    thank you for your help

    i would to ask you please, i want to store the phone number of the
    customer in the option_name column when he press 3 in context menu

    i have created a database “aheevacss” with user “aheevaccs” and password
    “aheevaccs” and also i have creatd a table in this database name of table
    test with two columns:
    option_name varchar(15)
    count int

    1-how can i check if the app_mysql module compiled and loaded i use
    asterisk 1.4 and if not installed how can ido in order to install and
    loaded it

    2- can you please veify the menu below and tell me waht is wrong

    thanks and regards

    [default]
    exten => 529,1,Ringing()
    exten => 529,2,Wait(4)
    exten => 529,3,Goto(accueil,s,1)

    [accueil] ; définition d’un contexte pour l’accueil
    exten => s,1,SetGlobalVar(sounds_path=/var/lib/asterisk/sounds/)
    exten => s,2,Background(${sounds_path}welcome)
    exten => s,3,goto(accueil,s,1)
    exten => #,1,Goto(menu,s,1)
    exten => i,1,Playback(${sounds_path}erreur-saisie)
    exten => i,2,goto(accueil,s,1)
    exten => t,1,Goto(accueil,s,1)

    [menu]
    exten => s,1,Background(${sounds_path}menu)
    exten => 0,1,Goto(menu,s,1)
    exten => 1,1,Goto(appel,s,1)
    exten => 2,1,Goto(message,s,1)
    exten => 3,1,NoOp(User chose support option)
    exten => 3,n,MYSQL(Connect connid localhost aheevaccs aheevaccs aheevaccs)
    exten => 3,n,MYSQL(Query resultid ${connid} update test set count = count
    + 1 where option_name = ‘support’)
    exten => 3,n,MYSQL(Clear ${resultid})
    exten => 3,n,MYSQL(Disconnect ${connid})
    exten => 3,n,Goto(support,s,1)
    exten => s,2,goto(menu,s,1)
    exten => i,1,Playback(${sounds_path}erreur-saisie)
    exten => i,2,Goto(menu,s,1)
    exten => t,1,Goto(menu,s,1)

    [appel] ; définition d’un contexte pour le menu d’appel
    exten => s,1,Background(${sounds_path}appel)
    exten => s,2,WaitExten(10)
    exten => 0,1,Goto(menu,s,1)
    exten => 223,1,Dial(SIP/${EXTEN},20,tr)
    exten => i,1,Playback(${sounds_path}erreur-saisie)
    exten => i,2,Goto(appel,s,1)
    exten => t,1,Goto(appel,s,1)
    [message] ; définition d’un contexte pour la messagerie
    exten => s,1,VoiceMailMain(${CALLERIDNUM})
    exten => t,1,Hangup()

    [support] ; définition d’un contexte pour le support
    exten => s,1,GoToIfTime(09:00-17:00|mon-fri|*|*?s,4)
    exten => s,2,Playback(${sounds_path}no-relation-support)
    exten => s,3,Goto(menu,s,1)
    exten => s,4,Playback(${sounds_path}relation-support)
    exten => s,5,Queue(default)
    exten => t,1,Hangup()

    2011/11/25 Dale Noll

  • You are welcome.
    I saw in some other message threads, it looks like you are working out
    getting the mysql connectivity working in 1.4. In this version, it is
    an ‘add on’ that you have to download separately from the Asterisk
    source tree. The instructions given by Warren Selby are correct.
    When you do the ‘make menuselect’, you are presented with a menu with 5
    options. Under ‘Applications’ you need to check app_addon_sql_mysql.
    Under ‘Call Detail Recording’ select cdr_addon_mysql. Under ‘Resource
    Modules’ check res_config_mysql. Exit from menuselect and type ‘make’.
    You probably do not need the res_config_mysql, but it does not hurt
    anything to compile it.

    Aslo as mentioned in another thread, you do need to have mysql-devel
    package installed.

    Then run ‘make’ and ‘make install’ and ‘make samples’. This will build
    the modules app_addon_sql_mysql.so, cdr_addon_mysql.so and
    res_config_mysql.so and install them in /usr/lib/asterisk/modules. This
    does not change any existing modules, just adds the new ones.

    Start an Asterisk cli (asterisk -r) and issue the command ‘module load
    app_addon_sql_mysql’. This should load the module and the MYSQL app
    will be available in your dialplan. To verify it is loaded, you can
    issue the command ‘module show like sql’

    You should also check the /etc/asterisk/modules.conf file. There should
    be a line that says ‘autoload=yes’. If it says no, you will have to add
    a line ‘load => app_addon_sql_mysql’ (do not include the quotes).
    Note: If you want to load cdr_addon_mysql, you will have to add a ‘load
    => cdr_addon_mysql’ line as well. This file is read by asterisk at
    startup, so after you restart asterisk for the first time after these
    changes, make sure the module is loaded with the module show command.

    In the [accueil] context, you call Background with the name of the file
    to play, then immediately return to the top and play the message again,
    and again and again. It will never stop until the caller hangs up.
    Also, you are asking the caller to press the ‘#’ key to get past the
    welcome greeting before getting to the main menu. I would recommend
    playing the welcome followed immediately by the Background() for the
    menu. The call the WaitExten() to give the caller a chance to enter a
    selection. The if a timeout or invalid entry occurs, go back to the
    point where the menu is played. You should also think about a look so
    that after a few failed attempts, you hangup the line and do not tie up
    that channel.

    To save the telephone number that you when option 3 is pressed, change
    the MYSQL query line to be something like this:

    exten => 3,n,MYSQL(Query resultid ${connid} insert into test (
    option_name ) values (‘${CALLERID(num)}’))

    I noticed that in your dialplan, you have the database, username and
    password the same, aheevaccs . However in your email, you spelled the
    database “aheevacss”. Probably a typo, but in case you have connect
    errors, that is a place to look.

    Dale

  • thank you so much for you help,i have flowed your email and installed
    thesesadd-ons all
    works perfectly i can store the phone_number of the Customer ,now i can do
    what i want 🙂

    thanks every one for your support J

    2011/11/30 Dale Noll

  • The example table that I gave originally was before I knew what you were
    looking to do. I assumed, incorrectly that you simply wanted to track
    how many times an option was selected in the menu.
    I would recommend that you create a table specifically for this
    application.

    That table may look like this. Please name the table and columns
    appropriately for your application.

    create table option_three (
    calldate datetime,
    callerid varchar(40)
    )

    Then the sql would look something like this…
    exten => 3,n,MYSQL(Query resultid ${connid} insert into option_three
    ( calldate, callerid ) values ( now(), ‘${CALLERID(num)}’))

    Dale

  • hello list

    i would your help please regarding this issue

    with the below code i can store the call date and the callerid ,now i want to store also the sip phone called 223

    could you please see the code and tell me how can i add the sip phone in my table ‘Menu’

    exten => 506,1,Ringing()
    exten => 506,n,Dial(SIP/223, 30)
    exten => 506,n,Goto(support,s,1)

    [support]

    exten => s,1,NoOp(User chose support option)
    exten => s,n,MYSQL(Connect connid localhost aheevaccs aheevaccs aheevaccs)
    exten => s,n,MYSQL(Query resultid ${connid} INSERT\ INTO\ menu\ SET\
    callerid=’${CALLERID(num)}’\, calldate=now())
    exten => s,n,MYSQL(Clear ${resultid})
    exten => s,n,MYSQL(Disconnect ${connid})

    thanks and regards

    2011/12/1 salaheddine elharit