Templates

The key configuration is very flexible, but to complex for the end user. The end user wants to select a function, enter a few necessary parameters and use the key.

A template predefines an key setup and specifies the needed parameters. These parameters are described via the ''XPath'' within the key specification.

Since the template is part of the phones configuration, it can be provided via Provisioning. It is especially convenient to overwrite existing templates ( like do not disturb) if the phone should not handle the donotdisturb function locally. In this scenario, the user will continue to see the translated key for do not disturb, can configure the key he wants and if the key is pressed a remote do not disturb is triggerd.

Example: speed dial

  <template prio="30" name="@string/speed_dial_title">
    <keyConfiguration>
      <function>
        <invocations>
          <invocation>
            <invite>
              <!-- empty uri, will be written by the parameter -->
              <uri/>
              <line>
                <id/>
              </line>
            </invite>
          </invocation>
        </invocations>
        <reactions>
          <reaction>
            <presence>
              <subscribe type="dialog">
                <uri/>
                <line>
                  <id/>
                </line>
              </subscribe>
            </presence>
          </reaction>
        </reactions>
      </function>
    </keyConfiguration>
    <parameters>
      <parameter name="uri">
        <path>//subscribe/uri</path>
        <path>//invite/uri</path>
        <mode>append</mode>
      </parameter>
      <parameter optional="true" name="identity">
        <path>//subscribe/line/id</path>
        <path>//invite/line/id</path>
      </parameter>
    </parameters>
  </template>

Example: LUA Template Call forwarding in Auerswald PBX

  <!-- switch the call forwarding for not responding within the PBX on or off
    parameter: identity
    parameter: target: call forwarding target
  -->
  <template name="@string/call_forwarding_no_response_title">
    <keyConfiguration>
      <lua>
        <code>
	  local valid = false
          local active = false
          local on = "*61*"
          local off = "#61#"
          local userpath = "/identities/identity["..identity.."]/"
          local host = config.get(userpath .. "host")
          local user = config.get(userpath .. "username")
 
          local function updateLed()
            if valid then
              if active then
                key:setLed( "green" )
              else
                key:setLed( "off" )
              end
            else
              key:setLed( "red", true )
            end
          end
 
          local unescape = function(url)
            return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
          end
 
          local function check_sub(data, uri, handle)
            local x = xml.eval(data)
            local test_uri_on = "sip:"..on..target.."#"..user.."@"..host
            if unescape(uri) == test_uri_on and x ~= nil then
              for _,dlg in ipairs(x) do
                state = dlg:find("state") 
                if state and state[1] == "trying" then 
                  active = true
                elseif state and state[1] == "terminated" then
                  active = false
                end
              end
            end
            updateLed()
          end
 
          local function check_valid()
            if identity =="" or target=="" then
              valid = false
            else
              valid = true
            end
          end
 
          local function sub()
            sip.subscribe(on..target.."#"..user,"0",identity,check_sub)
          end
 
          function onKeyUp()
            if active and valid then
              sip.invite(off.."#"..user)
            elseif valid then
              sip.invite(on..target.."#"..user)
            end
          end
 
          check_valid()
          updateLed()
          sub()
          </code>
          <params>
            <param name="identity"/>
            <param name="target"/>
          </params>
        </lua>
      </keyConfiguration>
      <parameters>
        <parameter name="@string/identity">
	  <path>//param[@name="identity"]/value</path>
        </parameter>
        <parameter name="@string/target">
          <path>//param[@name="target"]/value</path>
        </parameter>
      </parameters>
  </template>

For lua skripts, the parameters are placed in the configuration params section.