PHP code example of engagespot / php-sdk

1. Go to this page and download the library: Download engagespot/php-sdk 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/ */

    

engagespot / php-sdk example snippets


use Engagespot\EngagespotClient;

$apiKey = 'your-api-key';
$apiSecret = 'your-api-secret';
$signingKey = 'your-signing-key';

$dataRegion = 'us'; // Optional

// Create an instance of EngagespotClient
$engagespot = new EngagespotClient($apiKey, $apiSecret);

use Engagespot\EngagespotClient;

$config = [
    'apiKey' => 'your-api-key',
    'apiSecret' => 'your-api-secret',
    'signingKey' => 'your-signing-key',
    'baseUrl' => 'https://api.engagespot.co/v3'
];

// Create an instance of EngagespotClient
$engagespot = new EngagespotClient($config);

$notificationData = [
    'notification' => [
        'title' => 'Sample Title',
        'message' => 'Sample Message',
        'icon' => 'sample-icon',
        'url' => 'https://example.com',
        'templateId' => 1,
    ],
    'override' => [
        'channels' => ['inApp', 'webPush'],
        // other properties you want ot override
    ],
    'recipients' => ['[email protected]'],
    'category' => 'overrideCategory',
    'data' => [
        // custom data as you needed
        ],
    ],
];

$response = $engagespot->send($notificationData);

// Handle the response as needed
var_dump($response);

$notificationData = [
    'notification' => [
        'title' => 'Sample Title',
        'message' => 'Sample Message',
        'icon' => 'sample-icon',
        'url' => 'https://example.com',
        'templateIdentifier' => 'sampleTemplate',
        'category' => 'sampleCategory',
        'data' => [
            // custom data as you need
        ],
    ],
    'sendTo' => [
        'topics' => ['topic1', 'topic2'],
        'recipients' => ['[email protected]', '[email protected]'],
    ],
    'override' => [
        'channels' => ['inApp', 'webPush'],
        // other properties you want to override
    ],
];

 $response = $engagespot->send($notificationData);

use Engagespot\EngagespotClient;

$identifier = '[email protected]'; // your unique identifier
$profile = [
    'email' => '[email protected]',
    'any_key' => 'any_value'
];

$engagespot = new EngagespotClient($apiKey, $apiSecret);
$enagagespot->createOrUpdateUser($identifier, $profile);

 
$enagagespot->setSigningKey($signingKey);

use Engagespot\EngagespotClient;


$apiKey = 'your-api-key';
$apiSecret = 'your-api-secret';
$signingKey = 'your-signing-key';

// Create an instance of EngagespotClient
$engagespot = new EngagespotClient( [
    'apiKey' => $apiKey,
    'apiSecret' => $apiSecret,
    'signingKey' => $signingKey,
    'baseUrl' => 'https://api.engagespot.co/v3' // optional
]);

OR

// Create an instance of EngagespotClient
$engagespot = new EngagespotClient($apiKey, $apiSecret);
$enagagespot->setSigningKey($signingKey);


// Create JWT token for user
$userIdentifier = '[email protected]';
$token = $engagespot->generateUserToken($userIdentifier);

// Use the generated token as needed
var_dump($token);

$engagespot->setConfig('additionalConfig', 'value');


$signingKey = 'your-signing-key';
$enagagespot->setSigningKey($signingKey);


use Engagespot\EngagespotClient;

// Your Engagespot API credentials
$apiKey = 'your-api-key';
$apiSecret = 'your-api-secret';

// Create an instance of EngagespotClient
$client = new EngagespotClient($apiKey, $apiSecret);

$client->inapp()->fetch('john_doe_123', 1, 10);

$client->inapp()->markNotificationAsRead('notification_123');

$client->inapp()->markNotificationAsUnseen('notification_123');

$client->inapp()->markNotificationAsUnread('notification_123');

$client->inapp()->deleteNotification('notification_123');

use Engagespot\EngagespotClient;

// Your Engagespot API credentials
$apiKey = 'your-api-key';
$apiSecret = 'your-api-secret';

// Create an instance of EngagespotClient
$client = new EngagespotClient($apiKey, $apiSecret);

$client->topics()->create('New Topic', 'new-topic');

$client->topics()->update(123, 'Updated Topic Name');

$client->topics()->delete(123);

$users = [
    ['identifier' => 'user1', 'channels' => ['web']],
    ['identifier' => 'user2', 'channels' => ['email', 'push']],
];

$client->topics()->subscribeUser(123, $users);

$users = ['user1', 'user2'];

$client->topics()->unsubscribeUser(123, $users);

$client->topics()->updateChannel('user1', 123, ['email', 'push']);

$client->topics()->listSubscriptionsOfUser('user1');

use Engagespot\EngagespotClient;

// Your Engagespot API credentials
$apiKey = 'your-api-key';
$apiSecret = 'your-api-secret';

$dataRegion = 'us'; // Optional

// Create an instance of EngagespotClient
$client = new EngagespotClient($apiKey, $apiSecret);

$cancellationData = [
    'cancellationKey' => 'cancellationValue',
    'cancelFor' => [
        'recipients' => ['identifierOne', 'identifierTwo']
    ]

];
$client->workflows()->cancelRun('workflowIdentifier', $cancellationData);
bash
composer