吴伟贤のBlog

Feed Rss

freeswitch cookbook 第5章(四) 创建XML互动式语音菜单

07.20.2013, freeswitch, by .

转自:http://www.8000hz.com/archives/80.html

Creating XML IVR menus
创建XML互动式语音菜单

FreeSWITCH包含一个 用于创建和主叫进行交互IVR菜单 的系统,简单但很灵活。
在本方法中,我们会创建一个和Freeswitch默认配置的demo IVR 非常相似的自定义语音菜单。

Getting ready

为了测试,我们需要一个文本编辑器和电话。我们会在你拨打5002时收听到创建的自定义菜单。自定义菜单使用FreeSWITCH声音文件中的通用欢迎辞。

How to do it…

使用以下步骤来定义一个menu:

1. 打开文本编辑器,创建一个新的文件conf/ivr_menus/custom_ivr.xml.
2.  添加以下行:

<menu name="simple_greeting" 
      greet-long="ivr/ivr-generic_greeting.wav" 
      greet-short="ivr/ivr-generic_greeting.wav" 
      invalid-sound="ivr/ivr-that_was_an_invalid_entry.wav" 
      exit-sound="voicemail/vm-goodbye.wav" 
      confirm-attempts="3" 
      timeout="10000" 
      inter-digit-timeout="2000"
      max-failures="3" 
      max-timeouts="3" 
      digit-len="4"> 
  <entry action="menu-exec-app" digits="9" 
         param="directory default ${domain}"/> 
  <entry action="menu-exec-app" 
         digits="/^(10[01][0-9])$/" 
         param="transfer $1 XML features"/> 
  <entry action="menu-top" digits="*"/>
</menu>

3.  保存文件

下面,我们创建一个简单的extension, 用来测试我们的IVR菜单:
1. 使用文本编辑器打开conf/dialplan/default/01_Custom.xml
2. 添加这个extension:

<extension name="sample greeting">
  <!-- Good morning 12am to 11:59 --> 
  <condition hour="0-11" break="never"> 
    <action application="set" data="tod=morning" inline="true"/> 
  </condition> 
  <!-- Good afternoon 12pm to 17:59 --> 
  <condition hour="12-17" break="never"> 
    <action application="set" data="tod=afternoon" inline="true"/> 
  </condition> 
  <!-- Good morning 18:00 to 23:59 --> 
  <condition hour="18-23" break="never"> 
    <action application="set" data="tod=evening" inline="true"/> 
  </condition> 
  <condition field="destination_number" expression="^5002$"> 
    <action application="answer"/> 
    <action application="sleep" data="1000"/> 
    <action application="playback" 
            data="ivr/ivrgood_${tod}.wav"/> 
    <action application="sleep" data="500"/> 
    <action application="ivr" data="simple_greeting"/>
  </condition> 
</extension>

3.  保存文件退出
4.  在fs_cli中执行reloadxml命令或按F6

拨打5002来测试一下新的extension.

How it works…
虽然这是一个创建菜单的超小例子,但对于如何为一个企业PBX创建一个简单的“主欢迎辞” 依然非常有用。

There’s more…
很多时候把短语宏和IVR菜单结合起来是非常有用的。例如,在我们的拨号方案中,我们显示地计算一天中的时间然后再把声音播放给主叫。然后我们使用ivr 应用加载我们的通用欢迎辞。用几个理由来说明这样并不是最好的。首先,我们的欢迎语仅使用一个WAV文件,所以不管录的是什么,我们都是不能动的. 其次, 使用一个短语宏就给了我们一些灵活性.让我们来使用短语宏来提高一下我们的菜单.我们的目标如下:

Ø 在我们的欢迎辞中添加”重复以上选项,请按星号键.”
Ø 当重复选项时,跳过”早上好,中午好,下午好”
Ø 提高拨号方案的可读性

下面就是见证奇迹的时刻, 使用一个短语宏就可以实现这些目标,甚至更多. 首先, 我们清理一下拨号方案. 打开conf/dialplan/default/01_Custom.xml和编辑我们的extension使它只有以下的行:

<extension name="sample greeting"> 
  <condition field="destination_number" expression="^5002$"> 
    <action application="answer"/> 
    <action application="ivr" data="simple_greeting"/> 
  </condition> 
</extension>

现在我们创建一个独立的extension,它永远在diaplan开始的时候就执行. 通常情况下就放到default context 的开头.打开conf/dialplan/default.xml,把以下内容添加为default context的第一个extension.

<extension name="set_tod" continue="true">
  <!-- Good morning 12am to 11:59 --> 
  <condition hour="0-11" break="never"> 
    <action application="set" 
            data="tod=morning" 
            inline="true"/> 
  </condition> 
  <!-- Good afternoon 12pm to 17:59 --> 
  <condition hour="12-17" break="never"> 
    <action application="set" 
            data="tod=afternoon" 
            inline="true"/>
  </condition> 
  <!-- Good morning 18:00 to 23:59 --> 
  <condition hour="18-23" break="never"> 
    <action application="set" 
            data="tod=evening" 
            inline="true"/>
  </condition>
</extension>

添加了这个extension, 通过default context的所有通话都会设置一个通道变量tod.
这样的顺序就可以使任何的extension(或脚本,短语宏)都有权限访问tod, 而不是我们特定的extension.

下面, 打开conf/ivr_menus/custom_ivr.xml, 改变下面这两行为我们的宏:

greet-long="phrase:simple_greeting:long" 
greet-short="phrase:simple_greeting:short"

最后, 添加两个新的宏. 它有些长, 但它给我们实现了不少东西.打开conf/lang/en/ivr/custom.xml, 添加一个新的宏:

<macro name="simple_greeting">
  <input pattern="^(long)$" break-on-match="true"> 
    <match> 
      <action function="sleep" 
              data="1000"/> 
      <action function="play-file" 
              data="ivr/ivr-good_${tod}.wav"/> 
      <action function="sleep" 
              data="500"/> 
      <action function="play-file" 
              data="ivr/ivr-generic_greeting.wav"/> 
      <action function="sleep" 
              data="500"/> 
      <action function="play-file" 
              data="ivr/ivr-to_repeat_these_options.wav"/> 
      <action function="sleep" 
              data="250"/> 
      <action function="play-file" 
              data="voicemail/vm-press.wav"/> 
      <action function="sleep" 
              data="100"/> 
      <action function="play-file" 
              data="ascii/42.wav"/> 
</match>
  </input> 
  <input pattern="^(short)$"> 
    <match> 
      <action function="play-file" 
              data="ivr/ivr-generic_greeting.wav"/> 
      <action function="sleep" 
              data="500"/> 
      <action function="play-file" 
              data="ivr/ivr-to_repeat_these_options.wav"/> 
      <action function="sleep" 
              data="250"/> 
      <action function="play-file" 
              data="voicemail/vm-press.wav"/> 
      <action function="sleep" 
              data="100"/> 
      <action function="play-file" 
              data="ascii/42.wav"/> 
    </match> 
  </input> 
</macro>

保存所有的文件, 在fs_cli中执行reloadxml命令或按F6. 尝试拨打5002和按*重复语音菜单.
在重复中,系统不会再播放早上好,等等. 除了更多的功能, 使用短语宏还可以更简单地改变播给主叫的提示音.

See also
Ø Refer to the Company directory recipe earlier in this chapter
Ø 参考本章节中前面提及的 公司目录

评论已关闭。