1. Go to this page and download the library: Download silon/silon-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/ */
silon / silon-sdk example snippets
use Silon\Client;
$client = new Client([
'apiKey' => 'sk_live_...', // Settings → API keys; or set SILON_API_KEY
'workspace' => 'acme', // => https://acme.silon.tech; or SILON_WORKSPACE / SILON_BASE_URL
]);
$sent = $client->messages->send([
'channel' => 'whatsapp',
'to' => ['client_id' => 'cust_001'],
'content' => ['body' => 'Your order has shipped 📦'],
]);
echo $sent->id, ' ', $sent->status; // e.g. "9f3e..." "queued"
// Approved WhatsApp template to a raw number
$client->messages->send([
'channel' => 'whatsapp',
'to' => ['phone_number' => '+12025550123'],
'whatsapp_template' => [
'name' => 'order_confirmed',
'language' => 'en',
'variables' => ['body_1' => 'Sara', 'body_2' => 'ORD-42'],
],
'provider' => 'meta_cloud',
]);
// Personalised batch — every row is its own message (same shape as a send()
// body minus `audience`); the top-level channel is the default, a row's own
// channel wins. Max 500 rows, all-or-nothing: any invalid row 422s the whole
// batch (`messages[3].to.phone_number`) and nothing is queued.
$batch = $client->messages->sendBatch([
'channel' => 'sms',
'messages' => [
['to' => ['phone_number' => '+96550001234'], 'content' => ['body' => 'Sara, table for 2 at 7pm.']],
['to' => ['phone_number' => '+96550001235'], 'content' => ['body' => 'Omar, table for 4 at 9pm.']],
[
'channel' => 'email',
'to' => ['email' => '[email protected]'],
'content' => ['subject' => 'Booking confirmed', 'body' => 'Lulu, table for 6 at 8pm.'],
],
],
]);
// Per-row envelopes come back in request order; poll each id individually.
// Inline batches have no GET endpoint — the per-row ids are the tracking key.
foreach ($batch->messages ?? [] as $row) {
$status = $client->messages->retrieve($row->id);
echo $row->id, ' ', $status->status, PHP_EOL;
}
// Batch from an uploaded CSV — request-level fields are row defaults, CSV
// columns override per row ({{name}} renders from the row). The rows expand
// asynchronously: the 202 is an aggregate (no per-row `messages`) and the
// returned id IS the bulk batch id.
$uploaded = $client->bulk->files->upload("phone_number,name\n+96550001234,Sara\n");
$fileBatch = $client->messages->sendBatch([
'file' => $uploaded->name,
'channel' => 'sms',
'content' => ['body' => 'Hello {{name}}'],
]);
echo $fileBatch->status, ' ', $fileBatch->row_count; // "queued" 1
$detail = $client->bulk->retrieve((int) $fileBatch->id); // per-row status
// Email broadcast to a client group
$result = $client->broadcasts->create([
'channel' => 'email',
'audience' => ['type' => 'client_group', 'slug' => 'vip'],
'content' => ['subject' => 'We saved you a seat', 'body' => '<h1>Hello</h1>'],
]);
echo $result->target_count, ' ', $result->skipped_count;
// Why rows were skipped, itemised (skipped_count stays the sum):
echo $result->skipped?->suppressed; // e.g. 2
// Track it
$broadcast = $client->broadcasts->retrieve($result->id);
foreach ($client->broadcasts->deliveries($result->id, ['limit' => 100])->autoPaging() as $delivery) {
echo $delivery->client_id, ' ', $delivery->status, PHP_EOL;
}
$scheduled = $client->messages->send([
'channel' => 'sms',
'to' => ['phone_number' => '+96550001234'],
'content' => ['body' => 'Doors open in an hour'],
'send_at' => new DateTimeImmutable('+1 hour'),
]);
echo $scheduled->status; // "scheduled"
// Changed your mind? Allowed while still "scheduled":
$canceled = $client->messages->cancel($scheduled->id);
echo $canceled->status; // "canceled" — never dispatches
use Silon\Client;
use Silon\Http\HttpClientInterface;
use Silon\Http\Request;
use Silon\Http\Response;
$client = new Client([
'apiKey' => 'sk_live_...',
'workspace' => 'acme',
'httpClient' => new class implements HttpClientInterface {
public function send(Request $request, float $timeout): Response
{
// ... adapt to Guzzle, a PSR-18 client, an on-prem CA, etc.
// Return a Response for any HTTP status; throw a
// Silon\Http\TransportException only when no response is produced.
}
},
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.