msgly-official / msgly-sdk-php
There is no license information available for the latest version (v1.0.1) of this package.
PHP SDK for Msgly API
v1.0.1
2026-08-01 08:38 UTC
Requires
- php: >=7.4
- guzzlehttp/guzzle: ^7.0
This package is not auto-updated.
Last update: 2026-08-02 07:22:46 UTC
README
Official PHP SDK for integrating with the Msgly API. Easily send WhatsApp OTP messages, single text messages, and manage templates in PHP 7.4+.
Requirements
- PHP 7.4 or higher
- Composer
ext-jsonextension
Installation
Install via Composer:
composer require msgly/msgly-sdk-php
Quick Start
1. Initialize Client
require_once 'vendor/autoload.php'; use Msgly\MsglyClient; use Msgly\Exceptions\MsglyException; $msgly = new MsglyClient([ 'base_url' => 'https://api.msgly.id', // Optional, defaults to https://api.msgly.id 'client_id' => 'YOUR_CLIENT_ID', 'client_secret' => 'YOUR_CLIENT_SECRET', ]);
2. Send OTP (Mode 1: OTP Rotation Aktif)
Jika OTP Rotation diaktifkan di akun Anda oleh Admin, Anda tidak perlu menentukan template_id. Cukup kirim code, dan server Msgly akan secara otomatis merotasi template WhatsApp secara acak.
try { $result = $msgly->message()->sendOTP([ 'xid' => uniqid('otp_'), // Required: Unique transaction ID 'to' => '6281234567890', // Required: Destination number (62...) 'code' => '482910', // OTP Code to substitute into template ]); print_r($result); } catch (MsglyException $e) { echo "Error sending OTP (Rotation): " . $e->getMessage(); }
3. Send OTP (Mode 2: Manual Template Selection)
Jika OTP Rotation TIDAK aktif, Anda wajib menentukan template_id dan array params secara manual.
try { $result = $msgly->message()->sendOTP([ 'xid' => uniqid('otp_'), 'to' => '6281234567890', 'template' => [ 'template_id' => 'c8f7a1b2-3c4d-5e6f-7a8b-9c0d1e2f3a4b', 'params' => ['482910'], ], ]); print_r($result); } catch (MsglyException $e) { echo "Error sending OTP (Manual): " . $e->getMessage(); }
4. Manage Templates (List & Get Detail)
try { // List templates (supports 'page', 'per_page', 'search') $templates = $msgly->template()->list(['search' => 'OTP', 'page' => 1, 'per_page' => 10]); print_r($templates); // Get specific template detail by ID if (!empty($templates['data']['data'])) { $templateId = $templates['data']['data'][0]['id']; $detail = $msgly->template()->getById($templateId); print_r($detail); } } catch (MsglyException $e) { echo "Error fetching templates: " . $e->getMessage(); }
License
MIT License