We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

subdialog to catch session vars

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
jjohnson
Posts: 4
Joined: Thu Nov 05, 2015 5:03 pm

subdialog to catch session vars

Post by jjohnson »

Since we need the calle rid upon incoming call initiation (for user validation), we added a subdialog element to the form like so:

<subdialog name='session' src='http://secure.homecaregps.net/ivr/plum.session.vxml'/>

then field elements to assign the variables:

<field name="session_callerid" expr="session.callerid"/>
<field name="session_calledid" expr="session.calledid"/>
<field name="session_sessionid" expr="session.sessionid"/>

and inside plum.session.vxml, we wrote the following:

<?xml version="1.0"?>
<vxml version="2.0">
<form>
<block>
<field name='session_callerid' expr="session.telephone.ani"/>
<field name='session_calledid' expr="session.telephone.dnis"/>
<field name='session_sessionid' expr="session.id"/>
<return namelist="session_callerid session_calledid session_sessionid"/>
</block>
</form>
</vxml>

Both the application URL (http://secure.homecaregps.net/ivr/.php) and the small vxml file validate as true with your xml validator. However, the error reads as

TypeError: session has no properties line 1

Are we doing something incorrect here?

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: subdialog to catch session vars

Post by support »

Hi,

There are a few little things that are causing issues here. Firstly, when you use the <subdialog> tag, the variables returned must be accessed using the same name as specified in the <return> tag in the subdialog script.

so if you have a subdialog as such:
<subdialog name='session' src='subdialog.vxml'/>
and your subdialog script has the return tag:
<return namelist="session_callerid session_calledid session_sessionid"/>

when you return from your subdialog, you'll have access to:
session.session_callerid
session.session_calledid
session.session_sessionid

Also, when accessing the returned values from a subdialog, you want to make sure to include a <block> tag after the subdialog, like such:

<subdialog name='session' src='subdialog.vxml'/>
<block>
...access variables here
</block>

As a note, the <field> tag is usually used for gathering user input (this of it as a <input> tag in a html form). If you're just looking to use a regular variable, the <var> tag is the better option.

Those were the only minor items we were seeing with your script. We put together a basic working sample of what you're looking to accomplish:

main.vxml
<code>
<?xml version="1.0"?>
<vxml version="2.0">
<form>
<subdialog name='session' src='subdialog.vxml'/>
<block>
<var name="session_callerid" expr="session.session_callerid"/>
<var name="session_calledid" expr="session.session_calledid"/>
<var name="session_sessionid" expr="session.session_sessionid"/>
<log>ani: <value expr="session_callerid"/></log>
<log>dnis: <value expr="session_calledid"/></log>
<log>session id: <value expr="session_sessionid"/></log>
</block>
</form>
</vxml>
</code>

subdialog.vxml
<code>
<?xml version="1.0"?>
<vxml version="2.0">
<form>
<block>
<var name='session_callerid' expr="session.telephone.ani"/>
<var name='session_calledid' expr="session.telephone.dnis"/>
<var name='session_sessionid' expr="session.id"/>
<return namelist="session_callerid session_calledid session_sessionid"/>
</block>
</form>
</vxml>
</code>

When you call in, your subdialog will return the session id, ani, and dnis for the call, the main script will assign them to variables and then log the values.

As a side note, unless there's a specific reason you need to capture the ani, dnis, and sesison id in a sudbialog, you could do it right at the beginning of your script.

main.vxml:
<?xml version="1.0"?>
<vxml version="2.0">
<form>
<block>
<var name='ani' expr="session.telephone.ani"/>
<var name='dnis' expr="session.telephone.dnis"/>
<var name='session_id' expr="session.id"/>
<log>ani: <value expr="ani"/></log>
<log>dnis: <value expr="dnis"/></log>
<log>session id: <value expr="session_id"/></log>
</block>
</form>
</vxml>

This has the same end result, minus the additional subdialog.

If you were looking to do this as a subdialog such that you could use it in a number of different applications, the most efficient solution would be to use a root document that you could include in all of your applications and then set these variables globally in that script. Details about using root documents can be found here:
http://www.plumvoice.com/docs/dev/devel ... otdocument

Hopefully that helps. Please let us know if you have any additional questions.

Regards,
Plum Support

jjohnson
Posts: 4
Joined: Thu Nov 05, 2015 5:03 pm

Re: subdialog to catch session vars

Post by jjohnson »

Your response is very informative, thank you. Allow me to explain our current workflow, which may need to be altered based on your configuration:

Upon the call initiation, we currently receive a $_REQUEST array that includes the following" session_id, callerid, and calledid. Before any speech to text is delivered to the caller, our system checks the database to verify the caller (via the callerid) is actually authorized to even access the system. If so, we send the initial welcome message along with the persons name (e.g. 'Hello, John Doe. Please enter your access code...').

It appears to me, based on what you wrote and my testing, that we may have to ask a user for their access code, then after submission, validate access using both access code AND the callerid received in the $_REQUEST (get or post) array. Upon confirmation, we can then state "Hello John Doe. Here's the main menu...." . Is this correct?

Please note: This is NOT a deal breaker, but a key question that came up with our security hounds and server gods here.

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: subdialog to catch session vars

Post by support »

Hi,

How you choose to do validation (ani vs ani and access code) is dependent on what values you need to authenticate your caller.

If you only need the ani, here's a sample where you can use the provided ani to validate the caller at the start of the call.

main.vxml:

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">

   <!-- declare some page variables -->
   <var name="ani" expr="session.telephone.ani"/>

   <!-- validate the callers ani -->
   <form>     
      <subdialog name="result" namelist="ani" method="post" src="validate_ani.php"/>
      <block>
         <if cond="result.valid">
            <goto next="#valid_caller"/>
         <else/>
            <goto next="#invalid_caller"/>
         </if>
      </block>
   </form>

   <form id="invalid_caller">
      <block>
         <prompt>
            Sorry, you do not have access to use this system. Goodbye.
         </prompt>
         <disconnect/>
      </block>
   </form>

   <form id="valid_caller">
      <block>
         <prompt>
            You've been validated successfully.
         </prompt>
         <disconnect/>
      </block>
   </form>

</vxml>
validate_ani.php

Code: Select all

<?php
header('Content-type: text/xml');
$ani = $_POST['ani'];

// You can query your database to validate your caller here with the $ani value
// for the sake of a sample, let's set the valid variable to true
$valid = true;

echo("<?xml version=\"1.0\"?>\n");
?>

<vxml version="2.0">
	<form>
		<block>
			<var name="valid" expr="'<?= $valid ?>'"/>
			<return namelist="valid"/>
		</block>
	</form>
</vxml>
Since your subdialog is a php script, you can just accept the POST parameters and query your database directly in that script and return whether or not the caller can continue onward in the call. This is a very common caller validation approach using the ani of the caller.

If you first wanted to get the access code from the caller and then use the access code and ani together to validate the caller, you could do something like the following:

main.vxml

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">

   <!-- declare some page variables -->
   <var name="code"/>
   <var name="ani" expr="session.telephone.ani"/>

   <!-- record the callers access code -->
   <form id="access_code">
      <field name="access_code" type="digits?length=5">
         <prompt>
            Hello, please enter your access code.
         </prompt>
         <filled>
            <assign name="code" expr="access_code"/>
            <goto next="#validate_caller"/>
         </filled>
      </field>
   </form>

   <form id="validate_caller">
      <subdialog name="result" namelist="code ani" method="post" src="validate_caller.php"/>
      <block>
         <if cond="result.valid">
            <goto next="#valid_caller"/>
         <else/>
            <goto next="#invalid_caller"/>
         </if>
      </block>
   </form>

   <form id="invalid_caller">
      <block>
         <prompt>
            Sorry, you do not have access to use this system. Goodbye.
         </prompt>
         <disconnect/>
      </block>
   </form>

   <form id="valid_caller">
      <block>
         <prompt>
            You've been validated successfully.
         </prompt>
         <disconnect/>
      </block>
   </form>

</vxml>
validate_caller.php

Code: Select all

<?php
header('Content-type: text/xml');
$ani = $_POST['ani'];
$code = $_POST['code'];

// You can query your database to validate your caller here with the $ani and $code values
// for the sake of a sample, let's set set the valid variable to true
$valid = true;
echo("<?xml version=\"1.0\"?>\n");
?>

<vxml version="2.0">
	<form>
		<block>
			<var name='valid' expr="'<?= $valid ?>'"/>
			<return namelist="valid"/>
		</block>
	</form>
</vxml>
That way, the caller calls in, you gather the ani and access code, and then can use both values to validate the caller before moving forward with the call.

If you wanted to first validate the ani and then validate the ani and access code, you could combine both samples to do so relatively easily, these were more to explain how authentication commonly is approached. You can also return additional variables from your subdialogs, if you wanted to return the callers name to play a welcome message before asking for the access code or anything like that.

Hopefully that help, but please let us know if you have any additional questions.

Regards,
Plum Support

Post Reply