140 lines
4.4 KiB
PHP
140 lines
4.4 KiB
PHP
<?php
|
|
/**
|
|
* Webhook Logger for Nano Banana Pro
|
|
* Sends user actions and generated images to Make.com webhook
|
|
*/
|
|
|
|
/**
|
|
* Send action data to webhook
|
|
*
|
|
* @param array $data Data to send to webhook
|
|
* @return array ['success' => bool, 'http_code' => int, 'response' => string]
|
|
*/
|
|
function sendToWebhook($data) {
|
|
// Webhook URL (Make.com integration)
|
|
$webhookUrl = 'https://hook.us1.make.celonis.com/sbhcpk0athbdbxxmgijxc5sbwtjsg33h';
|
|
|
|
// Add timestamp
|
|
$data['timestamp'] = date('Y-m-d H:i:s');
|
|
$data['timezone'] = date_default_timezone_get();
|
|
|
|
// Log webhook send attempt
|
|
error_log("Sending to webhook: " . json_encode(array_keys($data)));
|
|
|
|
try {
|
|
$ch = curl_init($webhookUrl);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Content-Type: application/json'
|
|
]);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 10 second timeout
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
|
|
|
$response = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$curlError = curl_error($ch);
|
|
@curl_close($ch);
|
|
|
|
if ($curlError) {
|
|
error_log("Webhook cURL Error: " . $curlError);
|
|
return [
|
|
'success' => false,
|
|
'http_code' => 0,
|
|
'error' => $curlError
|
|
];
|
|
}
|
|
|
|
if ($httpCode === 200 || $httpCode === 201 || $httpCode === 202) {
|
|
error_log("Webhook sent successfully (HTTP $httpCode)");
|
|
return [
|
|
'success' => true,
|
|
'http_code' => $httpCode,
|
|
'response' => $response
|
|
];
|
|
} else {
|
|
error_log("Webhook failed (HTTP $httpCode): " . $response);
|
|
return [
|
|
'success' => false,
|
|
'http_code' => $httpCode,
|
|
'response' => $response
|
|
];
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
error_log("Webhook exception: " . $e->getMessage());
|
|
return [
|
|
'success' => false,
|
|
'error' => $e->getMessage()
|
|
];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Log image generation to webhook
|
|
*
|
|
* @param string $prompt The prompt used
|
|
* @param string $imageBase64 Base64 encoded image
|
|
* @param string $mimeType Image MIME type
|
|
* @param array $settings Generation settings
|
|
* @param string $userEmail User email
|
|
* @param string $actionType Type of action (generate, edit, upload)
|
|
*/
|
|
function logImageGeneration($prompt, $imageBase64, $mimeType, $settings, $userEmail, $actionType = 'generate') {
|
|
$webhookData = [
|
|
'client' => 'Internal', // Hardcoded for Nano Banana Pro
|
|
'deliverableNumber' => 'NANO-' . time(), // Auto-generated
|
|
'userEmail' => $userEmail,
|
|
'generationType' => 'Nano Banana Pro - Imagen 3',
|
|
'actionType' => $actionType, // generate, edit, upload
|
|
'prompt' => $prompt,
|
|
'settings' => $settings,
|
|
'imageFile' => 'data:' . $mimeType . ';base64,' . $imageBase64
|
|
];
|
|
|
|
return sendToWebhook($webhookData);
|
|
}
|
|
|
|
/**
|
|
* Log prompt enhancement to webhook
|
|
*
|
|
* @param string $originalPrompt Original scene description
|
|
* @param string $enhancedPrompt AI-enhanced prompt
|
|
* @param array $settings Studio settings (camera, lens, application, etc.)
|
|
* @param string $userEmail User email
|
|
*/
|
|
function logPromptEnhancement($originalPrompt, $enhancedPrompt, $settings, $userEmail) {
|
|
$webhookData = [
|
|
'client' => 'Internal',
|
|
'deliverableNumber' => 'NANO-PROMPT-' . time(),
|
|
'userEmail' => $userEmail,
|
|
'generationType' => 'Nano Banana Pro - Prompt Enhancement',
|
|
'actionType' => 'prompt_enhancement',
|
|
'originalPrompt' => $originalPrompt,
|
|
'enhancedPrompt' => $enhancedPrompt,
|
|
'settings' => $settings
|
|
];
|
|
|
|
return sendToWebhook($webhookData);
|
|
}
|
|
|
|
/**
|
|
* Log user action to webhook (general purpose)
|
|
*
|
|
* @param string $action Action name
|
|
* @param array $data Action data
|
|
* @param string $userEmail User email
|
|
*/
|
|
function logUserAction($action, $data, $userEmail) {
|
|
$webhookData = [
|
|
'client' => 'Internal',
|
|
'deliverableNumber' => 'NANO-ACTION-' . time(),
|
|
'userEmail' => $userEmail,
|
|
'generationType' => 'Nano Banana Pro - User Action',
|
|
'action' => $action,
|
|
'data' => $data
|
|
];
|
|
|
|
return sendToWebhook($webhookData);
|
|
}
|