The ActivitySmith PHP SDK provides convenient access to the ActivitySmith API from PHP applications.
See API reference.
composer require activitysmith/activitysmith<?php
declare(strict_types=1);
use ActivitySmith\ActivitySmith;
$activitysmith = new ActivitySmith($_ENV['ACTIVITYSMITH_API_KEY']);$response = $activitysmith->notifications->send([
'title' => 'New subscription ๐ธ',
'message' => 'Customer upgraded to Pro plan',
]);
echo $response->getSuccess() ? 'true' : 'false';
echo PHP_EOL;
echo $response->getDevicesNotified();$start = $activitysmith->liveActivities->start([
'content_state' => [
'title' => 'Nightly database backup',
'subtitle' => 'create snapshot',
'number_of_steps' => 3,
'current_step' => 1,
'type' => 'segmented_progress',
'color' => 'yellow',
],
'channels' => ['devs', 'ops'], // Optional
]);
$activityId = $start->getActivityId();$update = $activitysmith->liveActivities->update([
'activity_id' => $activityId,
'content_state' => [
'title' => 'Nightly database backup',
'subtitle' => 'upload archive',
'current_step' => 2,
],
]);
echo $update->getDevicesNotified();$end = $activitysmith->liveActivities->end([
'activity_id' => $activityId,
'content_state' => [
'title' => 'Nightly database backup',
'subtitle' => 'verify restore',
'current_step' => 3,
'auto_dismiss_minutes' => 2,
],
]);
echo $end->getSuccess() ? 'true' : 'false';Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.
$response = $activitysmith->notifications->send([
'title' => 'New subscription ๐ธ',
'message' => 'Customer upgraded to Pro plan',
'channels' => ['sales', 'customer-success'], // Optional
]);Push notification redirection and actions are optional and can be used to redirect the user to a specific URL when they tap the notification or to trigger a specific action when they long-press the notification. Webhooks are executed by ActivitySmith backend.
$response = $activitysmith->notifications->send([
'title' => 'New subscription ๐ธ',
'message' => 'Customer upgraded to Pro plan',
'redirection' => 'https://crm.example.com/customers/cus_9f3a1d', // Optional
'actions' => [ // Optional (max 4)
[
'title' => 'Open CRM Profile',
'type' => 'open_url',
'url' => 'https://crm.example.com/customers/cus_9f3a1d',
],
[
'title' => 'Start Onboarding Workflow',
'type' => 'webhook',
'url' => 'https://hooks.example.com/activitysmith/onboarding/start',
'method' => 'POST',
'body' => [
'customer_id' => 'cus_9f3a1d',
'plan' => 'pro',
],
],
],
]);try {
$activitysmith->notifications->send([
'title' => 'New subscription ๐ธ',
]);
} catch (Throwable $err) {
echo 'Request failed: ' . $err->getMessage() . PHP_EOL;
}- PHP 8.1+
MIT



