Input Pattern and Registers

If the pattern matches, the phrase macro will find in registers the parts of input between the pattern parentheses.

It is exactly the same as with the "expression" patterns in dialplan: let's say the input pattern is "^d(d{3})(d)(.*)$"; if the input is "1234567ciao", the phrase macro will then find "234" in $1, "5" in $2, and "67ciao" in $3.

Registers enable a single macro to be used to read variable contents to the caller. Let's look at how a macro can be used to read the number of messages (new or saved) in the caller's mailbox:

 
  <macro name="voicemail_message_count"> 
    <input pattern="^(1):(.*)$" break_on_match="true"> 
      <match> 
        <action function="play-file" data="voicemail/vm-you_have.wav"/> 
        <action function="say" data="$1" method="pronounced" type="items"/> 
        <action function="play-file" data="voicemail/vm-$2.wav"/> 
        <action function="play-file" data="voicemail/vm-message.wav"/> 
      </match> 
    </input>   
    <input pattern="^(d+):(.*)$"> 
      <match> 
        <action function="play-file" data="voicemail/vm-you_have.wav"/> 
        <action function="say" data="$1" method="pronounced" type="items"/> 
        <action function="play-file" data="voicemail/vm-$2.wav"/> 
        <action function="play-file" data="voicemail/vm-messages.wav"/> 
      </match> 
    </input> 
  </macro> 
 

In case the caller has only one new message, the phrase macro is invoked as "phrase: voicemail_message_count:1:new." The first input patterns will match because the first character of the argument string is "1." Also, that first character is enclosed by parentheses in the pattern, and the first parentheses' content (that is, the character "1" in this case) will go into the $1 register. The rest of the input, after a colon, used in this case as separator, is again enclosed within parentheses. Its content will go into the $2 register. In this case, $2 will contain the string "new."The phrase macro will execute the actions contained in "match" tags and then exit - break-on-true. Registers' values are used in actions: they give the argument to the "say" action, and they compose the name of the file in "play-file." Also note that, in this case, that is , matching a pattern with one message (new or saved), the phrase macro will correctly play the voicemail/vm-message.wav audio file, singular.

Let's look at what happens if the phrase macro is invoked for a caller with three saved messages: "phrase: voicemail_message_count:3:saved."The first input pattern will not match (the first argument character is not a "1"). The second input pattern is "^(d+):(.*)$" and will match. All digits up to the colon will end up in the $1 register, while the $2 register will contain the string "saved." Also, please note that in the "match" section of this input pattern the file played to the caller is voicemail/vm-messages.wav, plural. Clever, huh?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.76.89