Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added RegEx applet

  • Loading branch information...
commit 07ead349dab7c0d1769e3f97e2d44e6f7172f587 1 parent e17a387
@chadsmith authored
View
16 README.md
@@ -1,4 +1,4 @@
-# Advance SMS matching for OpenVBX
+# Advanced SMS matching for OpenVBX
Similar to the Menu applet, except you can respond to an SMS keyword with an entire flow instead of a single message.
@@ -8,8 +8,20 @@ Similar to the Menu applet, except you can respond to an SMS keyword with an ent
[1]: https://github.com/chadsmith/OpenVBX-Plugin-Match/archives/master
-## Usage
+## Usage (Basic)
1. Add the Match applet to your SMS flow
2. Enter one or more keywords to match (case insensitive) and an applet for each keyword
3. (Optional) Enter a default applet in case none of the keywords match
+
+## Usage (Advanced)
+
+1. Add the RegEx applet to your SMS flow
+2. Enter one or more regular expressions to match (case insensitive) and an applet for each match
+3. (Optional) Enter a default applet in case none of the keywords match
+
+Example RegEx:
+
+ ^(join|subscribe|enroll|start)
+
+Would match messages that begin with join, subscribe, enroll or start.
View
5 applets/regex/applet.json
@@ -0,0 +1,5 @@
+{
+ "name" : "RegEx",
+ "description" : "A regex keyword based matching response system",
+ "type" : ["sms"]
+}
View
BIN  applets/regex/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
47 applets/regex/script.js
@@ -0,0 +1,47 @@
+$(document).ready(function() {
+ // Disable all the template row inputs
+ $('.regex-applet tr.hide input').attr('disabled', 'disabled');
+
+ $('.regex-applet input.keypress').live('change', function(event) {
+ var row = $(this).parents('tr');
+ $('input[name=^responses]', row).attr('name', 'keys['+$(this).val()+']');
+ });
+
+ $('.regex-applet .action.add').live('click', function(event) {
+ event.preventDefault();
+ var row = $(this).closest('tr');
+ var newRow = $('tfoot tr', $(this).parents('.regex-applet')).html();
+ newRow = $('<tr>' + newRow + '</tr>')
+ .show()
+ .insertAfter(row);
+ $('.flowline-item').droppable(Flows.events.drop.options);
+ $('td', newRow).flicker();
+ $('.flowline-item input', newRow).attr('name', 'responses[]');
+ $('input.keypress', newRow).attr('name', 'keys[]');
+ $('input', newRow).removeAttr('disabled').focus();
+ $(event.target).parents('.options-table').trigger('change');
+ return false;
+ });
+
+ $('.regex-applet .action.remove').live('click', function() {
+ var row = $(this).closest('tr');
+ var bgColor = row.css('background-color');
+ row.animate(
+ {
+ backgroundColor : '#FEEEBD'
+ },
+ 'fast')
+ .fadeOut('fast', function() {
+ row.remove();
+ });
+
+ return false;
+ });
+
+ $('.regex-applet .options-table').live('change', function() {
+ var first = $('tbody tr', this).first();
+ $('.action.remove', first).hide();
+ });
+
+ $('.regex-applet .options-table').trigger('change');
+});
View
20 applets/regex/twiml.php
@@ -0,0 +1,20 @@
+<?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 Response();
+
+foreach($menu_items as $regex => $redirect)
+ if(preg_match("/" . $regex . "/i", $body)) {
+ $next = $redirect;
+ break;
+ }
+
+if(!empty($next))
+ $response->addRedirect($next);
+
+$response->Respond();
View
61 applets/regex/ui.php
@@ -0,0 +1,61 @@
+<?php
+$defaultNumberOfChoices = 2;
+$keys = (array) AppletInstance::getValue('keys[]', array('1' => '', '2' => '') );
+$responses = (array) AppletInstance::getValue('responses[]');
+?>
+
+<div class="vbx-applet regex-applet">
+
+ <h2>RegEx Options</h2>
+ <table class="vbx-menu-grid options-table">
+ <thead>
+ <tr>
+ <td>RegEx</td>
+ <td>&nbsp;</td>
+ <td>Applet</td>
+ <td>Add &amp; Remove</td>
+ </tr>
+ </thead>
+ <tfoot>
+ <tr class="hide">
+ <td>
+ <fieldset class="vbx-input-container">
+ <input class="keypress small" type="text" name="new-keys[]" value="" autocomplete="off" />
+ </fieldset>
+ </td>
+ <td>then</td>
+ <td>
+ <?php echo AppletUI::dropZone('new-responses[]', 'Drop applet here'); ?>
+ </td>
+ <td>
+ <a href="" class="add action"><span class="replace">Add</span></a> <a href="" class="remove action"><span class="replace">Remove</span></a>
+ </td>
+ </tr>
+ </tfoot>
+ <tbody>
+ <?php foreach($keys as $id => $key): ?>
+ <tr>
+ <td>
+ <fieldset class="vbx-input-container">
+ <input class="keypress small" type="text" name="keys[]" value="<?php echo $key ?>" autocomplete="off" />
+ </fieldset>
+ </td>
+ <td>then</td>
+ <td>
+ <?php echo AppletUI::dropZone('responses['.($id).']', 'Drop applet here'); ?>
+ </td>
+ <td>
+ <a href="" class="add action"><span class="replace">Add</span></a> <a href="" class="remove action"><span class="replace">Remove</span></a>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table><!-- .vbx-menu-grid -->
+ <h3>Oops! The message text didn't match any of our choices.</h3>
+ <p>What should we do?</p>
+ <?php echo AppletUI::dropZone('invalid-option'); ?>
+ <br />
+</div><!-- .vbx-applet -->
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.