Commit 12a27e41 authored by okhin's avatar okhin 🚴

FIX #4 creating the call to the backend-sip works (but we now have issues there)

parent d8792629
......@@ -35,6 +35,12 @@ class Api {
return json_decode($json, true);
}
// Asking for a single contact
static function get_contact($id) {
$json = Api::get("campaigns/" . CAMPAIGN_ID . "/contacts/" . $id);
return json_decode($json, true);
}
// Asking for complete list of groups
static function get_groups() {
$json = Api::get("campaigns/" . CAMPAIGN_ID . "/groups");
......
<?php
use \Firebase\JWT\JWT;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
class Main extends Controller {
/*
......@@ -14,7 +18,7 @@ class Main extends Controller {
$contacts = $f3->get('contacts');
$f3->set('contact', $contacts[$rand_id]);
$f3->set('random', rand(0, 2));
$f3->set('block_content','home.html');
$f3->set('block_content', 'home.html');
}
/*
......@@ -32,12 +36,6 @@ class Main extends Controller {
$contact_id = $f3->get('POST.contact_id');
$f3->set("contact_id", $contact_id);
// Generate a jwt token
$token = JWT::encode(array('api' => JWT_TOKEN), JWT_KEY);
//TODO: create call
//TODO: start call
$f3->set('block_content', 'feedbackform.html');
}
//POST
......@@ -68,16 +66,37 @@ class Main extends Controller {
function call($f3, $args) {
//GET
if ($f3->get('VERB') == 'GET') {
$f3->set('contact', Api::get_contact()); //$args['id']
$f3->set('contact', Api::get_contact($args['id']));
$f3->set('block_content', 'call.html');
}
//POST
elseif ($f3->get('VERB') == 'POST'){
//GET feedbackform
$f3->set('VERB', 'GET');
$this->feedbackform($f3, $args);
}
// Create the call
// Generate a jwt token
$token = JWT::encode(array('api' => JWT_TOKEN), JWT_KEY);
// To get the callee, we have the callee_id in the form. Using that
// to load the callee and retrieve its number.
$contact = Api::get_contact($args['id']);
$f3->set('contact', $contact);
$data = array('api' => 'piphone', 'caller' => $f3->get('POST.phone'), 'callee' => $contact['phone'], 'token' => $token);
// We want to generate a UNIQUE-ID (doesn't need to be cryptogaphically unique though
$call_id = uniqid();
$f3->set('CALL_ID', $call_id);
// Create the call
$client = new GuzzleHttp\Client(['base_uri' => SIP_API]);
try {
$res = $client->post("calls/$call_id", ['query' => $data]);
$f3->set('call', json_decode($res->getBody()));
$f3->set('VERB', 'GET');
$this->feedbackform($f3, $args);
} catch (RequestException $e) {
echo Psr7\str($e->getRequest());
if ($e->hasResponse()) {
echo Psr7\str($e->getResponse());
}
}
}
}
function contactslist($f3, $args) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment