PHP code example of bhaskarvyas001 / interakt-api-php
1. Go to this page and download the library: Download bhaskarvyas001/interakt-api-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bhaskarvyas001 / interakt-api-php example snippets
use Interakt\Track\Track;
Track::$apiKey = 'YOUR_API_KEY';
Track::$syncMode = false; // default is async queue flushed on shutdown
Track::$debug = true;
Track::user(
userId: 'user123',
countryCode: '+91',
phoneNumber: '9999999999',
traits: ['name' => 'John Doe', 'email' => '[email protected] ']
);
Track::event(
userId: 'user123',
event: 'Order Placed',
traits: ['orderValue' => '50.00'],
countryCode: '+91',
phoneNumber: '9999999999'
);
Track::flush();
use Interakt\Track\Track;
Track::$apiKey = 'YOUR_API_KEY';
$template = [
'name' => 'delivered_alert_101',
'languageCode' => 'en',
'bodyValues' => ['John', 'Order123'],
// optional: 'headerValues' => ['Header text or media url'],
// optional: 'buttonValues' => ['0' => ['payload0'], '1' => ['payload1']],
// optional: 'fileName' => 'invoice.pdf' // when header is a document
];
// sends the template message (async by default)
Track::sendTemplate('+91', '9999999999', $template, 'optional-callback-data', null);
$body = [
'countryCode' => '+91',
'phoneNumber' => '9999999999',
'type' => 'Template',
'template' => $template,
'callbackData' => 'some_callback_data',
];
Track::message($body);
use Interakt\Track\Webhook;
$secret = 'YOUR_WEBHOOK_SECRET';
$payload = file_get_contents('php://input');
$headers = getallheaders();
$signature = $headers['Interakt-Signature'] ?? ($headers['interakt-signature'] ?? '');
if (!Webhook::verify($secret, $payload, $signature)) {
http_response_code(401);
echo 'invalid signature';
exit;
}
$data = json_decode($payload, true);
// handle webhook types in $data['type'] and $data['data']
http_response_code(200);
bash
composer