Archive for the ‘Codeigniter’ Category

Oracle Service Cloud RightNowCX External Events / Custom Process: Curl a service on Save or Update

Thursday, February 16th, 2017
/*
* CPMObjectEventHandler: updateContact
* Package: OracleServiceCloud
* Objects: Contact
* Actions: Create, Update
* Version: 1.3
*/

use \RightNow\CPM\v1 as RNCPM;
use \RightNow\Connect\v1_3 as RNCPHP;

load_curl();

class updateContact implements RNCPM\ObjectEventHandler {

/**
* Apply CPM logic to object.
* @param int $runMode
* @param int $action
* @param object $contact
* @param int $cycle
*/
public static function apply($run_mode, $action, $contact, $n_cycles) {

if ($n_cycles != 0) return;

try {

$contact->CustomFields->c->contact_field_being_checked = new RNCPHP\NamedIDLabel();
$contact->CustomFields->c->contact_field_being_checked->ID = 2192; // Unregistered CPM
$header[] = "Content-Type: application/x-www-form-urlencoded";
$service_endpoint = 'http://INTERFACE-URL/cgi-bin/nikeagent.cfg/php/custom/scriptName.php?email=';

$noEmail = true;

foreach ($contact->Emails as $email) {
if ($email) {
$noEmail = false; // found an email

$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $service_endpoint . $email->Address,
CURLOPT_HEADER => 0,
CURLOPT_HTTPHEADER => $header,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0
));
$resp = curl_exec($ch);

if ($resp !== false) {
$respObj = json_decode($resp, true);
$regUserString = $respObj['contact_field_being_checked']; // 1 or empty, is boolean
if ($regUserString == 1) {
$contact->CustomFields->c->contact_field_being_checked->ID = 2189; // Registered CPM
}else{
}
}
curl_close($ch);
}
}

$contact->save(RNCPHP\RNObject::SuppressAll);
} catch (\Exception $e) {
throw $e;
}

return;
}
}

class updateContact_TestHarness implements RNCPM\ObjectEventHandler_TestHarness {
static $test_contact = null;

public static function setup() {
// TODO: Pass array of contacts
// Should pass an array of contacts with different
// emails and different orders of registered emails

// We want to create contacts on the fly, but
// you can't duplicate emails, so we should probably check
// if the email exists, and delete it - perhaps have a set test
// contact
try {
$contact = new RNCPHP\Contact;
$contact->Emails = new RNCPHP\EmailArray();
$contact->Emails[0] = new RNCPHP\Email();
$contact->Emails[0]->AddressType = new RNCPHP\NamedIDOptList();
$contact->Emails[0]->AddressType->LookupName = "Email - Primary";
$contact->Emails[0]->Address = "somebody@fastmail.jp";
$contact->Emails[0]->Invalid = false;
$contact->CRMModules = new RNCPHP\CRMModules();
$contact->CRMModules->Service = 1;
$contact->save(RNCPHP\RNObject::SuppressAll);

static::$test_contact = $contact;
} catch (\Exception $e) {
echo $e->getMessage();
}

return;
}

public static function fetchObject($action, $object_type) {
// Returned object is passed to apply()
return (static::$test_contact);
}

public static function validate($action, $object) {
if (RNCPM\ActionCreate == $action) {
if (assert($object->CustomFields->c->contact_field_being_checked->ID == 2189)) {
echo "Create test passed - " . $object->Emails[0]->Address . "\n";
return true;
} else {
echo "Create test FAILED - " . $object->Emails[0]->Address . "\n";
}
} elseif (RNCPM\ActionUpdate == $action) {
if (assert($object->CustomFields->c->contact_field_being_checked->ID == 2189)) {
echo "Update test passed - " . $object->Emails[0]->Address . "\n";
return true;
} else {
echo "Update test FAILED - " . $object->Emails[0]->Address . "\n";
}
} else {
echo "Invalid action";
}
}

public static function cleanup() {
// Delete temporary test contact
$contact = static::$test_contact;
$contact->destroy();

static::$test_contact = null;
}
}

Oracle Service Cloud RightNowCX Event subscribe Notes

Tuesday, August 30th, 2016

RightNow.Event.subscribe("evt_chatCobrowseAcceptResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatCobrowseStatusResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_fileUploadUpdateResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatNotifyFattachUpdateResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatPostResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatEngagementParticipantAddedResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatEngagementParticipantRemovedResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatEngagementConcludedResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatCobrowseInvitationResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatReconnectUpdateResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatAgentAbsentUpdateResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatAgentStatusChangeResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatPostCompletion",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatEventBusInitializedResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatConnectResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatFetchUpdateResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatStateChangeResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatSetParametersResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatValidateParametersResponse",function(e, f){console.log(e,f);},null);
RightNow.Event.subscribe("evt_chatCheckAnonymousResponse",function(e, f){console.log(e,f);},null);

example:

RightNow.Event.subscribe("evt_chatStateChangeResponse",function(e,f){
if(f[0].data.currentState && f[0].data.currentState == 2) {
window.chatID = RightNow.Chat.Controller.ChatCommunicationsController._engagementID;
}
},null);

Oracle Service Cloud RightNowCX Configuration for Developer Chatting with Self

Tuesday, August 30th, 2016

-> Chat starts

-> Triggers Rules evaluation

-> Rule matches regex on email submitted

-> Routes the chat to a particular queue

-> Queue is assigned to a profile

-> Profile is assigned to dev

Now you can submit a chat request via the page/UI, and receive it via the console, or let it sit to develop “waiting”/unconnected experience!

Oracle Service Cloud RightnowCX Custom Controller: Lookup Contact, Create Incident

Tuesday, August 30th, 2016

<?php

namespace Custom\Controllers;

/************* Agent Authentication ***************/
require_once( get_cfg_var("doc_root")."/ConnectPHP/Connect_init.php" );
initConnectAPI();

use RightNow\Connect\v1_2 as RNCPHP;

class GSChatIncident extends \RightNow\Controllers\Base
{

function __construct()
{
parent::__construct();
}

public function createContactIncident() {

try{
\RightNow\Libraries\AbuseDetection::check();

//$incident->SiteInterface = new RNCPHP\NamedIDLabel();
//$incident->SiteInterface->ID = 111;

$email = $_POST['email'];
$cID = (int)$_POST['countryID'];
$languageID = (int)$_POST['langID'];

$CI = &get_instance();
$contactmodelobj=$CI->load->model('standard/Contact_model');

$found = $this->Contact_model->lookupContactByEmail($email, null, null)->result;

if($found != null && is_int($found) && $found != false){
$creatingContact = $found;
} else {
$creatingContact = 1;
}

$incident = new RNCPHP\Incident();
$incident->Subject = "Chat cancelled";
$incident->CustomFields->c->system_source->ID = 2156;
$incident->CustomFields->c->country = new RNCPHP\NamedIDLabel();
$incident->CustomFields->c->country = $cID;
$incident->Language = $languageID;
$incident->PrimaryContact = RNCPHP\Contact::fetch($creatingContact); //Required field to create an incident through connect PHP
$incident->save(RNCPHP\RNObject::SuppressAll);
}

catch (Exception $err ){
echo $err->getMessage();
}
}
}
?>

Oracle Service Cloud RightNow CX PHP Connect API write to Custom Business Object example Custom Controller

Tuesday, August 30th, 2016

url: /cc/GSChatLog/createChatLog


<?php

namespace Custom\Controllers;

/************* Agent Authentication ***************/
require_once( get_cfg_var("doc_root")."/ConnectPHP/Connect_init.php" );
initConnectAPI();
use RightNow\Connect\v1_2 as RNCPHP;

class GSChatLog extends \RightNow\Controllers\Base
{

function __construct()
{
parent::__construct();
}

public function createChatLog() {

try{
\RightNow\Libraries\AbuseDetection::check();

$email = $_POST['email'];
$cID = (int)$_POST['countryID'];
$languageID = (int)$_POST['langID'];
$name = $_POST['name'];
$referrerUrl = $_POST['referrerUrl'];
$siteID = $_POST["siteID"];
$platformID = $_POST["platformID"];
$chatStatus = $_POST["chatStatus"];
$chatID = $_POST["chatID"];
$lob = strtoupper($_POST["lob"]);

$log = new RNCPHP\ContactUs\chat_log();
$log->chat_id = $chatID;
$log->chat_log_status = $chatStatus;
$log->site_id = $siteID;
$log->chat_group = 2156;
$log->referring_url = $referrerUrl;
$log->interface = $platformID;
$log->email_address = $email;
$log->name = $name;
$log->language_id = $languageID;
$log->country_id = $cID;
$log->lob_id = $lob;
$log->save();

catch (Exception $err ){
echo $err->getMessage();
}
}
}
?>

Oracle Service Cloud RightNow CX PHP Connect API Analytics Report example

Tuesday, August 30th, 2016

$report_id = ..74..;
$report = RNCPHP\AnalyticsReport::fetch($report_id);

$report_filter = new RNCPHP\AnalyticsReportSearchFilter;
$report_filter->Name = 'chats.email';
$report_filter->Values = array($email);
$filters = new RNCPHP\AnalyticsReportSearchFilterArray;
$filters[] = $report_filter;

$report_result = $report->run(0,$filters);

while($reportRow = $report_result->next())
{
print_r($reportRow);
$chatID = (int)$reportRow['chat_id'];
}

Eureka Call Library Oracle RightNow get article count per category

Saturday, July 25th, 2015
/**
* Description: Get all categories, display in a list with number of articles in each, alphabetical listing of category level 3
* Date: March 2013
* Classes: GetAllCategories, Generator, Category, CategoryDepot
* Brief Technical:
* Page calls CallLibraryCatList widget
* widget view instantiates GetAllCategories Class, which uses Prodcat model to retrieve categories object
* GetAllCategories Class in turn activates Generator Class
* Generator Class utilizes Category & Category Depot Classes, converting the categories object into instantiated individual category objects that can leverage each other, and then be displayed
*/
class GetAllCategories{
	public $CI;
	public $catListObject;
	public $currentTier = -1;
	public $tier3 = array();
	public $lastLevel = -1;
	public $newLevel = -1;
	public $categoryDepot;

	function __construct() {
		$this->CI =& get_instance();
		$this->CI->load->model('standard/Prodcat_model');
		$this->catListObject = $this->CI->Prodcat_model->getHierPopup(14);
		$this->categoryDepot = new Generator;
		$this->iterateConvert();
	}

	// loops through the returned categories, and uses Generator Class to organize as Category Objects
	function iterateConvert() {
		for( $i=0; $i < count($this->catListObject); $i++ ) {
			if($this->catListObject[$i]['hier_list'] == 588)
			{
				$this->newLevel = $this->catListObject[$i]['level'];

				if ( $this->newLevel < 3 && $this->lastLevel == 3 ) {
					// sort tier 3 alphabetically, then add to collection
					foreach ($this->tier3 as $key => $row) {
						$title[$key] = $row[0];
						$href[$key] = $row['href_list'];
						$level[$key] = $row['level'];
					}
					array_multisort($title, SORT_ASC, $href, SORT_ASC, $level, SORT_ASC, $this->tier3);
					foreach($this->tier3 as $key => $catObject) {
						// create and add tiers 1 & 2 to collection
						$this->categoryDepot->generateCategory($catObject);
					}
					unset($this->tier3);
				}
				if($this->newLevel != 3) {
					// create and add tiers 1 & 2 to collection
					$this->categoryDepot->generateCategory($this->catListObject[$i]);
				}
				if($this->newLevel == 3) {
					// collect tier 3 items
					$this->tier3[] = $this->catListObject[$i];
				}

				$this->lastLevel = $this->newLevel;
				}
			}

			$this->categoryDepot->renderCollection();
		}
	}

class Generator{
	public $categoryDepot;
	public $CI;

	function __construct() {
		$this->categoryDepot = new CategoryDepot;
		$this->CI =& get_instance();
		$this->CI->load->model('custom/AnswersInCategoriesCounter_model');
	}

	function generateCategory($catSent) {
		$category = new Category;
		$category->setTier($catSent['level']);
		$category->setTitle($catSent[0]);
		$categoryArray = $category->setCategories($catSent['hier_list']);
		$finalCategory = $category->getFinalCategory();
		$articleCount = $this->CI->AnswersInCategoriesCounter_model->getCountOfAnswersByCat($finalCategory);
		if($finalCategory != 588 || 0 || null) {
			$this->categoryDepot->addToCollection($category);
		}
		foreach($categoryArray as $key => $categoryId) {
			$this->categoryDepot->updateCategoryArticleCounts($categoryId, $articleCount);
		}
	}	

	function renderCollection() {
		return $this->categoryDepot->getCollection();
	}
}

/**
* $catListObject[$i]['level'] / 0-3
* $catListObject[$i]['hier_list'] / Categories
* $catListObject[$i][0]
*/
class Category {
	public $tier;
	public $categoriesList;
	public $categoryArray;
	public $finalCategory;
	public $title;
	public $parentCategory;
	public $articleCount;
	public $articleTotal;

	function __construct() {
		//echo "Category instantiated";
	}

	function setTier($input) {
		$this->tier = $input;
	}
	
	function setCategories($input) {
		$this->categoriesList = $input;
		$this->setCategoryArray();
		$this->setParentCategory();
		$this->setFinalCategory();
		return $this->categoryArray;
	}

	function setCategoryArray() {
		$this->categoryArray = explode(',',$this->categoriesList);
	}

	function setParentCategory() {
		$itemLevel = $this->tier - 1;
		$this->parentCategory = $this->categoryArray[$itemLevel];
	}

	function setFinalCategory() {
		$this->finalCategory = $this->categoryArray[$this->tier];
	}

	function setTitle($input) {
		$this->title = $input;
	}

	function setArticleCount($input) {
		$newSet = array_unique(array_merge((array)$this->articleCount,(array)$input));
		$this->articleCount = $newSet;
		$this->setArticleTotal();
	}

	function getFinalCategory() { return $this->finalCategory; }
	
	function setArticleTotal() {
		$this->articleTotal = count($this->articleCount);
		return $this->articleTotal;
	}
}

// archives Category Objects, updates each Class's article count, and returns/displays the Collection
class CategoryDepot {
	public $collection;
	public $baseURL = '/app/list_call_library_no_search/r_id/108720/p/646/c/';
	public $currentTier = -1;

	function __construct() {
	}

	function addToCollection($input) {
		$this->collection[] = $input;
	}

	function getCollection() {
		foreach($this->collection as $category) {
			// if articleCount is 0, don't even show count
			if($category->articleTotal != 0){ $articleCount = " (" . $category->articleTotal . ")"; }else{ $articleCount = ''; }

			if($category->tier > $currentTier) {
				$currentTier = $category->tier;
				echo "<ul><li><a href='" . $this->baseURL . $category->categoriesList . "' class='noIntercept'>" . $category->title . $articleCount . "</a>";
			} elseif( $category->tier == $currentTier ) {
				echo "</li><li class='level_" . $category->tier . "'><a href='" . $this->baseURL . $category->categoriesList . "'>" . $category->title . $articleCount . "</a>";
			} elseif($category->tier < $currentTier) {
				$numberToClose = ($currentTier - $category->tier);
				$currentTier = $tier;
				switch ( $numberToClose ) {
					case 1:
						echo "</li></ul></li></ul><ul><li><a href='" . $this->baseURL . $categoriesList . "' class='noIntercept'>" . $category->title . $articleCount . "</a>";
					break;
					case 2:
						echo "</li></ul></li></ul></li></ul><ul><li><a href='" . $this->baseURL . $categoriesList . "' class='noIntercept'>" . $category->title . $articleCount . "</a>";
					break;
				}
			}
		}
	}

	// accepts a finalCategory int and the amount to increment that object's article count
	function updateCategoryArticleCounts($categoryId, $articleCount) {
		foreach ( $this->collection as $category ) {
			if ( $categoryId == $category->finalCategory ) {
				$category->setArticleCount($articleCount);
				break;
			}
		}
	}
}

Oracle RightNow getNamedValues, get all possible values for answer Object attributes, re-making the console

Thursday, May 16th, 2013

$fields = array(“AccessLevels”, “AnswerType”,”Language”, “StatusWithType.Status”, “Categories”, “Products”);
foreach($fields as $key => $field){
$temp = array();
$$field = array();
$parameter = RNCPHP\ConnectAPI::getNamedValues(“RightNow\\Connect\\v1_2\\Answer”, $field);
foreach($parameter as $key => $value){
$temp[$value->ID] = $value->LookupName;
}
$$field = $temp;
if($field == ‘StatusWithType.Status’){ $StatusWithType = $temp; }
}
// Prove it
foreach($StatusWithType as $key => $value){ echo $key . “, ” . $value . “<br />”; }

// Now fill in the answer creation/edit form values with these values