Deploy: 2026-05-21 18:24:56
This commit is contained in:
@@ -40,10 +40,11 @@ class WhatsAppController extends BaseController
|
|||||||
WhatsAppSession::updateState($session['id'], ['status' => 'connecting']);
|
WhatsAppSession::updateState($session['id'], ['status' => 'connecting']);
|
||||||
|
|
||||||
// Call Baileys Node.js Service on port 3722
|
// Call Baileys Node.js Service on port 3722
|
||||||
|
$appUrl = rtrim(getenv('APP_URL') ?: 'https://nabeh.intaleqapp.com', '/');
|
||||||
$nodeUrl = 'http://127.0.0.1:3722/api/sessions/start';
|
$nodeUrl = 'http://127.0.0.1:3722/api/sessions/start';
|
||||||
$payload = json_encode([
|
$payload = json_encode([
|
||||||
'session_key' => $session['session_key'],
|
'session_key' => $session['session_key'],
|
||||||
'webhook_url' => getenv('APP_URL') . '/api/whatsapp/webhook'
|
'webhook_url' => $appUrl . '/api/whatsapp/webhook'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$ch = curl_init($nodeUrl);
|
$ch = curl_init($nodeUrl);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace App\Models;
|
|||||||
*/
|
*/
|
||||||
class Campaign extends BaseModel
|
class Campaign extends BaseModel
|
||||||
{
|
{
|
||||||
protected string $table = 'campaigns';
|
protected static string $table = 'campaigns';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all campaigns for a company
|
* Get all campaigns for a company
|
||||||
|
|||||||
@@ -12,17 +12,17 @@ if (!fs.existsSync(SESSIONS_DIR)) {
|
|||||||
fs.mkdirSync(SESSIONS_DIR, { recursive: true });
|
fs.mkdirSync(SESSIONS_DIR, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET;
|
|
||||||
|
|
||||||
async function sendWebhook(webhook_url, payload) {
|
async function sendWebhook(webhook_url, payload) {
|
||||||
try {
|
try {
|
||||||
|
console.log(`Sending webhook to ${webhook_url} with state ${payload.state}`);
|
||||||
await axios.post(webhook_url, payload, {
|
await axios.post(webhook_url, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Webhook-Secret': WEBHOOK_SECRET
|
'X-Webhook-Secret': process.env.WEBHOOK_SECRET || 'fallback'
|
||||||
},
|
},
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
});
|
});
|
||||||
|
console.log(`Webhook sent successfully to ${webhook_url}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to send webhook to ${webhook_url}:`, err.message);
|
console.error(`Failed to send webhook to ${webhook_url}:`, err.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user