Plugin API » Applets
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.
If you need to get a value you set inside your Applet UI from an input, select or checkbox, use getValue()
| 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. |
mixed
$value = AppletInstance::getValue('text-entry');
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'); ?>" />
When you want to redirect a caller from a dropZone, use this method to get the url to redirect to.
| 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. |
mixed — URL(s) to Applet Instance set to the dropzone
$next = AppletInstance::getDropZoneUrl('next');
Redirecting to a dropzone in twiml.php
$next = AppletInstance::getDropZoneUrl('next');
$response = new TwimlResponse;
$response->redirect($next);
$response->respond();
<Response>
<Redirect>http://example.com/twiml/applet/voice/1/f34dsa</Redirect>
</Response>
When you just want to know what the applet instance path is inside your flow, use this method.
| 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. |
mixed
$value = AppletInstance::getDropZoneValue('text-entry');
Implementation of getDropZoneUrl using getDropZoneValue
public static 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] : '';
}
http://example.com/OpenVBX/twiml/applet/voice/1/f34dsa
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.
| 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. |
mixed — URL(s) or string(s) of text to be given to the speech engine.
$value = AppletInstance::getAudioSpeechPickerValue('text-entry');
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();
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.
| 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. |
mixed — URL(s) or string(s) of text to be given to the speech engine.
$value = AppletInstance::getUserGroupPickerValue('text-entry');
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;
}
If you want to get the current Applet Instance unique id, use this method.
None
string — Instance ID
$instance_id = AppletInstance::getInstanceId(); echo $instance_id;
Usually six character long string like below:
17d6bf
When you need to detect whether an instance is either an "sms" or "voice" applet, call AppletInstance::getFlowType().
None
string — "sms" or "voice"
$response = new TwimlResponse;
if(AppletInstance::getFlowType() == "sms")
{
$response->sms('Reply with Sms');
}
else
{
$response->say('I am a robot');
}