get('contacts'))-1); $contacts = $f3->get('contacts'); $groups = Api::get_groups(); $f3->set('groups', $groups); $group_types = Api::get_group_types(); $f3->set('group_types', $group_types); $f3->set('contact', $contacts[$rand_id]); $f3->set('random', rand(0, 2)); $f3->set('block_content', 'home.html'); } /* * Feedback page * Form for a feedback after a call * GET: show the form * POST: send the form to the campaign API and show thank you */ function feedbackform($f3, $args) { //GET if ($f3->get('VERB') == 'GET'){ $categories = Api::get_feedback_categories(); $f3->set('feedback_categories', $categories); $contact_id = $f3->get('POST.contact_id'); $f3->set("contact_id", $contact_id); $arguments = Api::get_arguments(); $f3->set('arguments', $arguments); $f3->set('block_content', 'feedbackform.html'); } //POST elseif ($f3->get('VERB') == 'POST'){ $contact_id = $f3->get('POST.contact_id'); $feedback = $f3->get('POST.feedback'); $category = $f3->get('POST.feedback_category'); //send feedback to campaign $f3->set('post_feedback_result', Api::post_feedback($contact_id, $feedback, $category)); $f3->set('block_content', 'thankyou.html'); } } /* * Feedback SIP function * Get a feedback from the SIP system - status of a call for instance * GET: get the call back */ function feedbacksip($f3, $args) { //GET } /* * call Page * Form to call * GET: show the form * POST: send the form and GET feedbackform */ function call($f3, $args) { //GET if ($f3->get('VERB') == 'GET') { $f3->set('contact', Api::get_contact($args['id'])); $f3->set('block_content', 'call.html'); } //POST elseif ($f3->get('VERB') == 'POST'){ // 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', GuzzleHttp\Psr7\copy_to_string($res->getBody())); $f3->set('VERB', 'GET'); $this->feedbackform($f3, $args); } catch (RequestException $e) { print_r(Psr7\str($e->getRequest())); if ($e->hasResponse()) { print_r(Psr7\str($e->getResponse())); } } } } function contactslist($f3, $args) { $contacts = Api::get_contacts(); $f3->set('contacts', $contacts); $f3->set('random', 2); $f3->set('block_content', 'contactslist.html'); } function argumentation($f3, $args) { $arguments = Api::get_arguments(); $f3->set('arguments', $arguments); $f3->set('block_content', 'argumentation.html'); } }; ;