<?php $response = new Response(); /* Fetch all the data to operate the menu */ $digits = isset($_REQUEST['Digits']) ? $_REQUEST['Digits'] : false; $prompt = AppletInstance::getAudioSpeechPickerValue('prompt'); $invalid_option = AppletInstance::getAudioSpeechPickerValue('invalid-option'); $repeat_count = AppletInstance::getValue('repeat-count', 3); $next = AppletInstance::getDropZoneUrl('next'); $selected_item = false; /* Build Menu Items */ $choices = (array) AppletInstance::getDropZoneUrl('choices[]'); $keys = (array) AppletInstance::getDropZoneValue('keys[]'); $menu_items = AppletInstance::assocKeyValueCombine($keys, $choices); $numDigits = 1; foreach ($keys as $key) { if (strlen($key) > $numDigits) { $numDigits = strlen($key); } } if ($digits !== false) { if (!empty($menu_items[$digits])) { $selected_item = $menu_items[$digits]; } else { if ($invalid_option) { $verb = AudioSpeechPickerWidget::getVerbForValue($invalid_option, null); $response->append($verb); $response->addRedirect(); } else { $response->addSay('You selected an incorrect option.'); $response->addRedirect();
<?php $ci =& get_instance(); /* Get the body of the SMS message */ $body = isset($_REQUEST['Body']) ? trim($ci->input->get_post('Body')) : null; $body = strtolower($body); $prompt = AppletInstance::getValue('prompt'); $keys = AppletInstance::getValue('keys[]'); $responses = AppletInstance::getValue('responses[]'); $menu_items = AppletInstance::assocKeyValueCombine($keys, $responses, 'strtolower'); $response = new TwimlResponse(); /* Display the menu item if we found a match - case insensitive */ if (array_key_exists($body, $menu_items) && !empty($menu_items[$body])) { $response_text = $menu_items[$body]; } else { /* Display the prompt if incorrect */ $response_text = $prompt; } $response->sms($response_text); $response->Respond();
<?php $body = isset($_REQUEST['Body']) ? trim($_REQUEST['Body']) : null; $keys = (array) AppletInstance::getValue('keys[]'); $responses = (array) AppletInstance::getDropZoneUrl('responses[]'); $menu_items = AppletInstance::assocKeyValueCombine($keys, $responses); $next = AppletInstance::getDropZoneUrl('invalid-option'); $response = new TwimlResponse(); foreach ($menu_items as $regex => $redirect) { if (!empty($regex) && preg_match("/" . $regex . "/i", $body)) { $next = $redirect; break; } } if (!empty($next)) { $response->redirect($next); } $response->respond();