Plugin API » Applets

Applet Instance

AppletInstance defines a bunch of methods to access the data stored in an Applet. Using these methods, you can access the information stored by the flow editor in your applet coding(ui.php and twiml.php).

For more information on developing applets please see the Applet Quickstart.

AppletInstance::getValue( $name, $default = ‘‘ )

If you need to get a value you set inside your Applet UI from an input, select or checkbox, use getValue()

Arguments

Name Type Description
$name string To select an array or an item on the array, use name[] or name[1]. They will return an array or value of the array.
$default mixed Default value if no data is stored for that name.

Returns

mixed

Usage

$value = AppletInstance::getValue('text-entry');

Examples

Accessing a value from a textbox in an Applet’s user interface named ‘monkey-name’.

<input type="text" name="monkey-name" value="" />


In your Applet ui.php or twiml.php:

$name = AppletInstance::getValue('monkey-name', 'howie');



In your Applet ui.php

<input type="text" name="monkey-name" value="<?php echo AppletInstance::getValue('monkey-name', 'howie'); ?>" />

AppletInstance::getDropZoneUrl( $name = ‘dropZone’ )

When you want to redirect a caller from a dropZone, use this method to get the url to redirect to.

Arguments

Name Type Description
$name string To select an array or an item on the array, use name[] or name[1]. They will return an array or value of the array.

Returns

mixed — URL(s) to Applet Instance set to the dropzone

Usage

$next = AppletInstance::getDropZoneUrl('next');

Examples

Redirecting to a dropzone in twiml.php

$next = AppletInstance::getDropZoneUrl('next');
$response = new TwimlResponse;
$response->redirect($next);
$response->respond();

Output

<Response>
    <Redirect>http://example.com/twiml/applet/voice/1/f34dsa</Redirect>
</Response>

AppletInstance::getDropZoneValue( $name = ‘dropZone’ )

When you just want to know what the applet instance path is inside your flow, use this method.

Arguments

Name Type Description
$name string To select an array or an item on the array, use name[] or name[1]. They will return an array or value of the array.

Returns

mixed

Usage

$value = AppletInstance::getDropZoneValue('text-entry');

Examples

Implementation of getDropZoneUrl using getDropZoneValue

function getDropZoneUrl($name = 'dropZone')
{
    $values = AppletInstance::getDropZoneValue($name);
    if(empty($values))
    {
        return '';
    }

    if(is_string($values))
    {
        $values = array($values);
    }

    /* Build drop zone urls from values */
    $urls = array();
    foreach($values as $i => $value)
    {
        if(empty($value))
        {
            $urls[$i] = '';
            continue;
        }
		
        $parts = explode('/', $value);
        $value = $parts[count($parts) - 1];
        
        $urls[$i] = join('/', array(
                        AppletInstance::$baseURI,
                        $value));
    }

    if(count($urls) > 1)
    {
        return $urls;
    }
    
    return !empty($urls)? $urls[0] : '';
}

Output

http://example.com/OpenVBX/twiml/applet/voice/1/f34dsa

AppletInstance::getAudioSpeechPickerValue( $name = ‘audioSpeechPickerValue’ )

When you want to get the selection of the audio or speech text a user filled out, use this method.

Use the helper method, AudioSpeechPickerWidget::getVerbForValue($pickerValue) with this method to retrieve the say or play objects to add to your responses.

Arguments

Name Type Description
$name string To select an array or an item on the array, use name[] or name[1]. They will return an array or value of the array.

Returns

mixed — URL(s) or string(s) of text to be given to the speech engine.

Usage

$value = AppletInstance::getAudioSpeechPickerValue('text-entry');

Examples

Presenting audioSpeechPicker value in twiml.php

$response = new TwimlResponse;

$say_or_play = AppletInstance::getAudioSpeechPickerValue('say-or-play');
AudioSpeechPickerWidget::setVerbForValue($say_or_play, $response);

$response->respond();

AppletInstance::getUserGroupPickerValue( $name = ‘userGroupPicker’ )

When you want to get a user or group selected by the user in your applets, use this method. It will return either a VBX_User or VBX_Group object.

Arguments

Name Type Description
$name string To select an array or an item on the array, use name[] or name[1]. They will return an array or value of the array.

Returns

mixed — URL(s) or string(s) of text to be given to the speech engine.

Usage

$value = AppletInstance::getUserGroupPickerValue('text-entry');

Examples

Getting devices and voicemail for a selected a user or group:

$dial_whom_user_or_group = AppletInstance::getUserGroupPickerValue('dial-whom-user-or-group');
switch(get_class($dial_whom_user_or_group))
{
    case 'VBX_User':
        foreach($dial_whom_user_or_group->devices as $device)
        {
            $numbers[] = $device->value;
        }

        $voicemail = $dial_whom_user_or_group->voicemail;
        break;

    case 'VBX_Group':
        foreach($dial_whom_user_or_group->users as $user)
        {
            $user = VBX_User::get($user->user_id);
            foreach($user->devices as $device)
            {
                $numbers[] = $device->value;
            }
        }

        $voicemail = $no_answer_group_voicemail;
        break;

    default:
        break;
}

AppletInstance::getInstanceId( )

If you want to get the current Applet Instance unique id, use this method.

Arguments

None

Returns

string — Instance ID

Examples

$instance_id = AppletInstance::getInstanceId();
echo $instance_id;

Output

Usually six character long string like below:

17d6bf

AppletInstance::getFlowType( )

When you need to detect whether an instance is either an “sms” or “voice” applet, call AppletInstance::getFlowType().

Arguments

None

Returns

string — “sms” or “voice”

Examples

$response = new TwimlResponse;

if(AppletInstance::getFlowType() == "sms")
{
    $response->sms('Reply with Sms');
}
else
{
    $response->say('I am a robot');
}