Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 3bab6ff80c7fdaf6f93247fcec9653fb1975e0f7 @chadsmith committed Jun 27, 2010
0 README
No changes.
@@ -0,0 +1,8 @@
+{
+ "name" : "New Call",
+ "sms_name" : "New Call",
+ "voice_title" : "New Call",
+ "sms_title" : "New Call",
+ "description" : "Call (someone else) from a flow.",
+ "type" : ["sms", "voice"]
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,17 @@
+<?php
+$ci =& get_instance();
+
+$number = AppletInstance::getValue('number');
+$id = AppletInstance::getValue('flow');
+$recipient = normalize_phone_to_E164(str_replace('%sender%', $_REQUEST['From'], AppletInstance::getValue('recipient')));
+
+$ci->twilio = new TwilioRestClient($ci->twilio_sid, $ci->twilio_token, $ci->twilio_endpoint);
+if(($flow = OpenVBX::getFlows(array('id' => $id, 'tenant_id' => $ci->tenant->id)))&&$flow[0]->values['data'])
+ $ci->twilio->request("Accounts/{$ci->twilio_sid}/Calls", 'POST', array('Caller' => $number, 'Called' => $recipient, 'Url' => site_url('twiml/start/voice/'.$id)));
+$response = new Response();
+
+$next = AppletInstance::getDropZoneUrl('next');
+if(!empty($next))
+ $response->addRedirect($next);
+
+$response->Respond();
@@ -0,0 +1,48 @@
+<?php
+ $user = OpenVBX::getCurrentUser();
+ $tenant_id = $user->values['tenant_id'];
+ $ci =& get_instance();
+ $ci->load->model('vbx_incoming_numbers');
+ $numbers = $ci->vbx_incoming_numbers->get_numbers(false);
+ $flows = OpenVBX::getFlows(array('tenant_id' => $tenant_id));
+ $selected = AppletInstance::getValue('number');
+ $selected_flow = AppletInstance::getValue('flow');
+?>
+<div class="vbx-applet">
+<?php if(count($numbers)): ?>
+ <div class="vbx-full-pane">
+ <h3>Caller ID</h3>
+ <fieldset class="vbx-input-container">
+ <select class="medium" name="number">
+<?php foreach($numbers as $number): ?>
+ <option value="<?php echo $number->phone; ?>"<?php echo $number->phone==$selected?' selected="selected" ':''; ?>><?php echo $number->name; ?></option>
+<?php endforeach; ?>
+ </select>
+ </fieldset>
+ <h3>Flow</h3>
+ <fieldset class="vbx-input-container">
+ <select class="medium" name="flow">
+<?php foreach($flows as $flow): ?>
+ <option value="<?php echo $flow->values['id']; ?>"<?php echo $flow->values['id']==$selected_flow?' selected="selected" ':''; ?>><?php echo $flow->values['name']; ?></option>
+<?php endforeach; ?>
+ </select>
+ </fieldset>
+ <h3>Recipient</h3>
+<?php if(AppletInstance::getFlowType() == 'sms'): ?>
+ <p>Use %sender% to substitute the sender's number or %number% for the number texted.</p>
+<?php endif; ?>
+ <fieldset class="vbx-input-container">
+ <input type="text" name="recipient" class="medium" value="<?php echo AppletInstance::getValue('recipient'); ?>" />
+ </fieldset>
+ </div>
+ <h2>Next</h2>
+ <p>After initiating the call, continue to the next applet</p>
+ <div class="vbx-full-pane">
+ <?php echo AppletUI::DropZone('next'); ?>
+ </div><!-- .vbx-full-pane -->
+<?php else: ?>
+ <div class="vbx-full-pane">
+ <h3>You do not have any phone numbers!</h3>
+ </div>
+<?php endif; ?>
+</div><!-- .vbx-applet -->
@@ -0,0 +1,8 @@
+{
+ "name" : "New Text",
+ "sms_name" : "New Text",
+ "voice_title" : "New Text",
+ "sms_title" : "New Text",
+ "description" : "Text (someone else) from a flow.",
+ "type" : ["sms", "voice"]
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,29 @@
+<?php
+$ci =& get_instance();
+
+$number = AppletInstance::getValue('number');
+$recipient = normalize_phone_to_E164(AppletInstance::getValue('recipient'));
+$message = AppletInstance::getValue('sms');
+
+if(AppletInstance::getFlowType() == 'voice'){
+ $caller = normalize_phone_to_E164($_REQUEST['Caller']);
+ $called = normalize_phone_to_E164($_REQUEST['Called']);
+ $message = str_replace(array('%caller%', '%number%'), array($caller, $called), $message);
+}
+else{
+ $from = normalize_phone_to_E164($_REQUEST['From']);
+ $to = normalize_phone_to_E164($_REQUEST['To']);
+ $message = str_replace(array('%sender%', '%number%', '%body%'), array($from, $to, $_REQUEST['Body']), $message);
+}
+
+require_once(APPPATH . 'libraries/twilio.php');
+$ci->twilio = new TwilioRestClient($ci->twilio_sid, $ci->twilio_token, $ci->twilio_endpoint);
+$response = $ci->twilio->request("Accounts/{$ci->twilio_sid}/SMS/Messages", 'POST', array('To' => $recipient, 'From' => $number, 'Body' => $message));
+
+$response = new Response();
+
+$next = AppletInstance::getDropZoneUrl('next');
+if(!empty($next))
+ $response->addRedirect($next);
+
+$response->Respond();
@@ -0,0 +1,42 @@
+<?php
+ $ci =& get_instance();
+ $ci->load->model('vbx_incoming_numbers');
+ $numbers = $ci->vbx_incoming_numbers->get_numbers(false);
+ $selected = AppletInstance::getValue('number');
+?>
+<div class="vbx-applet">
+<?php if(count($numbers)): ?>
+ <div class="vbx-full-pane">
+ <h3>Caller ID</h3>
+ <fieldset class="vbx-input-container">
+ <select class="medium" name="number">
+<?php foreach($numbers as $number): ?>
+ <option value="<?php echo $number->phone; ?>"<?php echo $number->phone==$selected?' selected="selected" ':''; ?>><?php echo $number->name; ?></option>
+<?php endforeach; ?>
+ </select>
+ </fieldset>
+ <h3>Recipient</h3>
+ <fieldset class="vbx-input-container">
+ <input type="text" name="recipient" class="medium" value="<?php echo AppletInstance::getValue('recipient'); ?>" />
+ </fieldset>
+ <h3>Message</h3>
+<?php if(AppletInstance::getFlowType() == 'voice'): ?>
+ <p>Use %caller% to substitute the caller's number or %number% for the number called.</p>
+<?php else: ?>
+ <p>Use %sender% to substitute the sender's number, %number% for the number texted or %body% for the message body.</p>
+<?php endif; ?>
+ <fieldset class="vbx-input-container">
+ <textarea name="sms" class="medium"><?php echo AppletInstance::getValue('sms'); ?></textarea>
+ </fieldset>
+ </div>
+ <h2>Next</h2>
+ <p>After sending the message, continue to the next applet</p>
+ <div class="vbx-full-pane">
+ <?php echo AppletUI::DropZone('next'); ?>
+ </div><!-- .vbx-full-pane -->
+<?php else: ?>
+ <div class="vbx-full-pane">
+ <h3>You do not have any phone numbers!</h3>
+ </div>
+<?php endif; ?>
+</div><!-- .vbx-applet -->
@@ -0,0 +1,60 @@
+<?php
+ $user = OpenVBX::getCurrentUser();
+ $tenant_id = $user->values['tenant_id'];
+ $ci =& get_instance();
+ if(($recipient = $_POST['recipient'])&&($number = $_POST['number'])&&($id = intval($_POST['flow']))){
+ require_once(APPPATH . 'libraries/twilio.php');
+ $ci->twilio = new TwilioRestClient($ci->twilio_sid, $ci->twilio_token, $ci->twilio_endpoint);
+ if($id&&($flow = OpenVBX::getFlows(array('id' => $id, 'tenant_id' => $tenant_id)))&&$flow[0]->values['data'])
+ $ci->twilio->request("Accounts/{$this->twilio_sid}/Calls", 'POST', array('Caller' => $number, 'Called' => normalize_phone_to_E164($_POST['recipient']), 'Url' => site_url('twiml/start/voice/'.$id)));
+ }
+ $flows = OpenVBX::getFlows(array('tenant_id' => $tenant_id));
+?>
+<style>
+ .vbx-subscriptions form {
+ padding:20px 5%;
+ }
+</style>
+<div class="vbx-content-main">
+ <div class="vbx-content-menu vbx-content-menu-top">
+ <h2 class="vbx-content-heading">Start Flow</h2>
+ </div><!-- .vbx-content-menu -->
+ <div class="vbx-table-section vbx-subscriptions">
+ <form method="post" action="">
+ <fieldset class="vbx-input-container">
+<?php if(count($callerid_numbers)): ?>
+ <p>
+ <label class="field-label">Number<br/>
+ <input type="text" name="recipient" class="medium" />
+ </label>
+ </p>
+<?php if(count($flows)): ?>
+ <p>
+ <label class="field-label">Flow<br/>
+ <select name="flow" class="medium">
+<?php foreach($flows as $flow): ?>
+ <option value="<?php echo $flow->values['id']; ?>"><?php echo $flow->values['name']; ?></option>
+<?php endforeach; ?>
+ </select>
+ </label>
+ </p>
+ <p>
+ <label class="field-label">Caller ID<br/>
+ <select name="number" class="medium">
+<?php foreach($callerid_numbers as $number): ?>
+ <option value="<?php echo $number->phone; ?>"><?php echo $number->name; ?></option>
+<?php endforeach; ?>
+ </select>
+ </label>
+ </p>
+ <p><button type="submit" class="submit-button"><span>Call</span></button></p>
+<?php else: ?>
+ <p>You do not have any flows!</p>
+<?php endif; ?>
+<?php else: ?>
+ <p>You do not have any phone numbers!</p>
+<?php endif; ?>
+ </fieldset>
+ </form>
+ </div>
+</div>
@@ -0,0 +1,12 @@
+{
+ "name" : "Outbound Flows",
+ "author" : "Chad Smith <chad@nospam.me>",
+ "description" : "Lets you call out with a flow or start calls and messages (to someone else) within a flow.",
+ "url" : "http://twitter.com/chadsmith",
+ "links" : [{
+ "menu" : "Outbound",
+ "url" : "outbound",
+ "script" : "outbound.php",
+ "label" : "Start Flow"
+ }]
+}

0 comments on commit 3bab6ff

Please sign in to comment.