twilio / OpenVBX

OpenVBX is a web-based open source phone system for business.
http://openvbx.org
Other
699 stars 342 forks source link

Browser Phone API #372

Closed kaburkett closed 6 years ago

kaburkett commented 8 years ago

I am trying to post data to a plugin that calls the browser phone javascript function.. this is what the simple plugin looks like:

<div class="vbx-plugin">
if ($_POST['calltonum'] != null){
echo '<h3> post successful </h3>';
$calltonum = $_POST['calltonum'];
$callfromnum = $_POST['callfromnum'];
$htmlstring = '<script> $(document).ready(function(){OpenVBX.clientDial({"to": '. echo     $calltonum.',"callerid": '. echo $callfromnum.'});});</script>';
    echo $htmlstring;
}
else{
    echo '<h3> calltonum post was null</h3>';
}
</div>

where an html form submits directly to the plugin like:

<form method="POST" action="http://myurl.com/p/call_via_post" target"_blank">

All I am getting is internal 500 errors, and redirection to the voicemail screen. I am authenticated already when I make these requests from my html page. Any quick thoughts?

Thanks

kaburkett commented 8 years ago

update:

I am trying to POST two pieces of data from an external webapp to OpenVBX

calltonum:(phone number in format +12345678902)
callfromnum:(phone number in format +12345678902)

Once the data is in the app I am trying to use this feature: http://www.openvbx.org/docs/browserphone/api/

OpenVBX.clientDial({
 'to': calltonum,
 'callerid': callfromnum
});

I have verified this Javascript function works from a plugin, but havent been able to successfully post the data to a plugin yet. I was originally afraid I would run into authentication issues, but quickly found if I have an open session already- and post data directly to a function inside a custom controller with a class that extends the User_Controller... it receives the post data and passes it to the view just fine.

Right now, my issue is that when I load the view- the page requests '/' to load which redirects the browser to /messages/inbox. I am getting a js error:

Uncaught ReferenceError: $ is not defined(anonymous function) @ dosomethingplease:116

when trying to use the browserphone api leading me to believe jquery hasnt been loaded in the template.

Here is the code I currently have:

dialbrowser.php created in /controllers

<?php 

class dialbrowserException extends Exception {}

class dialbrowser extends User_Controller {
public function __construct()
{
    parent::__construct();  
}
public function index()
{
    return $this->dosomethingplease();
}
public function dosomethingplease()
{
    $data = $this->init_view_data();
    $this->template->add_js('assets/j/plugins/call-and-sms-dialogs.js');
    $this->template->add_js('assets/j/plugins/jquery.address-1.0.min.js');
    $data = array('calltonum' => $this->input->post('calltonum'), 'callfromnum' => $this->input->post('callfromnum'));

    $this->respond('title','dialnow', $data);
}    
}

?>

.

dialnow.php created in /views

<div class="vbx-content-main">

<div class="vbx-content-menu vbx-content-menu-top">
    <h2 class="vbx-content-heading">Test-a-roo</h2>
</div><!-- .vbx-content-menu -->

<div class="vbx-content-container">
    <div class="vbx-content-section">
        <div class="vbx-form">
            <h3>Receipt of Number passed:</h3>
                <div>
                    And here we made it the whole way.... didnt think we could do it huh? 
                    <?php 
                    echo "lets do this for sanity's sake... to: ".$calltonum." and from: ".$callfromnum." ...see no issues with the data!";
                    $html = "<script> $('document').ready(function(){OpenVBX.clientDial({'to': '".$calltonum."', 'callerid': '".$callfromnum."'});}); </script>";
                    echo $html;
                    ?>
                </div>
        </div>
    </div><!-- .vbx-content-section -->
</div><!-- .vbx-content-container -->

</div><!-- .vbx-content-main -->

and I can currently post to /dialbrowser/index or /dialbrowser/dosomethingplease successfully, and the data populates in the view.

Since I am extending the User_Controller- shouldnt all the critical jquery/javascript already be loaded successfully?

kaburkett commented 8 years ago

@Gipetto

rubaiet commented 6 years ago

Somehow the document ready is not working in plugin page. You should try window.onload instead of $('document').ready So the line will be: $html = "<script> window.onload=function(){OpenVBX.clientDial({'to': '".$calltonum."', 'callerid': '".$callfromnum."'});}; </script>";