Chatbot Secure API Example: PHP

Here's an example implementation of the Chatbot API written in PHP. You'll need to substitute your valid codes from a Chatbot API subscription before this will work.

<?php
$apiKey = 'sample2IMEkzTj12';
$apiSecret = 'samplewdT4Blaax7mrFJE6SiyGCHF8Ij';

$message = array(
	'message' => array(
		'message' => 'How are you doing today?',
		'chatBotID' => 6,
		'timestamp' => time()
	),
	'user' => array(
		'firstName' => 'Tugger', 
		'lastName' => 'Sufani',
		'gender' => 'm',
		'externalID' => 'abc-639184572'
		)
);

// construct the data
$host = "https://www.personalityforge.com/api/chat/";
$messageJSON = json_encode($message);
$hash = hash_hmac('sha256', $messageJSON, $apiSecret);

$url = $host."?apiKey=".$apiKey."&hash=".$hash."&message=".urlencode($messageJSON);

// Make the call using cURL
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// make the call
$response = curl_exec($ch);
curl_close($ch);

echo 'Response JSON: '.$response.'<br>';

$responseObject = json_decode($response);
echo 'Response Object: <br>';
var_dump($responseObject);
?>

Back to the API Documentation

Back to API Pricing