apipedia/php-sdk
Composer 安装命令:
composer require apipedia/php-sdk
包简介
PHP SDK for Apipedia API - WhatsApp, Telegram, SMS, AI Chat and more
README 文档
README
A comprehensive PHP SDK for the Apipedia API, providing seamless integration for WhatsApp, Telegram, SMS, AI Chat, and more messaging services.
Features
- 📱 WhatsApp Messaging - Send text, media, and files
- 🤖 Telegram Bot Integration - Messages, images, documents, buttons, locations
- 📨 SMS Services - Regular, VIP, OTP, and VVIP SMS
- 🧠 AI Chat Integration - Intelligent conversational AI
- 🔗 Chainable API - Fluent interface for complex workflows
- 📊 Message Tracking - Status monitoring and delivery receipts
- 👥 Bulk Messaging - Send to multiple recipients efficiently
- 🔄 Cross-platform - Send AI responses across multiple channels
Installation
Install the package via Composer:
composer require apipedia/php-sdk
Requirements
- PHP 7.4 or higher
- cURL extension
- JSON extension
- Guzzle HTTP client
Quick Start
Basic Usage
<?php require_once 'vendor/autoload.php'; use Apipedia\Apipedia; // Initialize with your credentials $apipedia = new Apipedia('your_app_key', 'your_auth_key'); // Or use the helper function $apipedia = apipedia('your_app_key', 'your_auth_key'); // Send a WhatsApp message $result = $apipedia->whatsapp('628123456789', 'Hello from PHP SDK!'); echo "Message sent with ID: " . $result->getResult()['message_id'];
API Documentation
WhatsApp Messaging
Send Text Message
$apipedia->whatsapp('628123456789', 'Hello World!');
Send Message with Media
// With image URL $apipedia->whatsapp('628123456789', 'Check this image!', 'https://example.com/image.jpg'); // With local file $apipedia->whatsapp('628123456789', 'Here is a document', '/path/to/document.pdf');
Bulk Messaging
Bulk V1 - Same Message to Multiple Recipients
$phoneNumbers = ['628123456789', '628987654321', '628555666777']; $apipedia->bulkV1($phoneNumbers, 'Important announcement for everyone!');
Bulk V2 - Different Messages to Multiple Recipients
$phoneNumbers = ['628123456789', '628987654321']; $messages = ['Hello John!', 'Hello Jane!']; $apipedia->bulkV2($phoneNumbers, $messages);
Telegram Integration
Send Text Message
$apipedia->telegramSendMessage('@yourchannel', 'Hello Telegram!');
Send Image
$apipedia->telegramSendImage( '@yourchannel', 'https://example.com/image.jpg', 'Image caption here' );
Send Location
$apipedia->telegramSendLocation('@yourchannel', -6.2088, 106.8456);
Send Interactive Buttons
$buttons = [ [ ['text' => 'Visit Website', 'url' => 'https://example.com'], ['text' => 'Contact Support', 'callback_data' => 'support'] ], [ ['text' => 'More Info', 'callback_data' => 'info'] ] ]; $apipedia->telegramSendButtons('@yourchannel', 'Choose an option:', $buttons);
Send Document
$apipedia->telegramSendDocument( '@yourchannel', 'https://example.com/document.pdf', 'Important document', 'report.pdf' );
SMS Services
Regular SMS
$apipedia->smsRegular('628123456789', 'Your regular SMS message');
VIP SMS
$apipedia->smsVIP('628123456789', 'Priority VIP message');
OTP SMS
$otpCode = rand(100000, 999999); $apipedia->smsOTP('628123456789', "Your OTP code is: {$otpCode}");
VVIP SMS
$apipedia->smsVVIP('628123456789', 'Critical VVIP message');
AI Chat Integration
$response = $apipedia->aiChat( 'What is the weather like today?', 'weather_agent', 'text' ); echo $response->getResult()['response'];
Chainable API - Cross-Platform Messaging
One of the most powerful features of this SDK is the ability to chain API calls, allowing you to send AI-generated responses across multiple platforms:
// AI generates content and sends to WhatsApp $apipedia ->aiChat('Generate a daily motivation quote', 'motivation_agent') ->toWhatsApp('628123456789', '🌟 Daily Motivation: '); // AI processes data and sends to multiple platforms $apipedia ->aiChat('Summarize today\'s sales report', 'analytics_agent') ->toWhatsApp('628123456789', '📊 Sales Update: ') ->toTelegram('@salesteam', '📈 Team Update: ') ->toSMS('628987654321', 'SALES: ');
Message Status and Tracking
Get Profile Information
$profile = $apipedia->getProfile(); echo json_encode($profile->getResult());
Update Presence Status
$apipedia->updatePresence('628123456789', 'typing', 5000);
Check Message Status
// Get all message statuses $result = $apipedia->getMessageStatusAll('message_id_here'); echo json_encode($result->getResult()); // Get last status $result = $apipedia->getLastStatus('message_id_here'); echo json_encode($result->getResult()); // Get last receipt status $result = $apipedia->getLastReceiptStatus('message_id_here'); echo json_encode($result->getResult());
API Endpoints Used:
- Get all statuses:
GET https://waconsole.apipedia.id/api/messages/status/all - Get last status:
GET https://waconsole.apipedia.id/api/status/last - Get last receipt:
GET https://waconsole.apipedia.id/api/messages/status/last/receipt
Advanced Examples
Customer Support Bot
// Automated customer support workflow $customerQuery = "I need help with my order #12345"; $response = $apipedia ->aiChat($customerQuery, 'support_agent') ->toWhatsApp('628123456789', '🤖 Support: ') ->toTelegram('@support_logs', '📝 Query Log: ');
Multi-Channel Notifications
// Send order notifications across all channels $orderUpdate = $apipedia ->aiChat('Generate shipping notification for order #67890', 'notification_agent'); // Send to customer via WhatsApp $orderUpdate->toWhatsApp('628123456789', '📦 Shipping Update: '); // Log to Telegram channel $orderUpdate->toTelegram('@order_logs', '📋 Order #67890: '); // Send SMS backup $orderUpdate->toSMS('628123456789', 'SHIPPING: ');
Bulk Campaign with Personalization
$customers = [ ['phone' => '628123456789', 'name' => 'John'], ['phone' => '628987654321', 'name' => 'Jane'], ['phone' => '628555666777', 'name' => 'Bob'] ]; foreach ($customers as $customer) { $personalizedMessage = $apipedia ->aiChat("Generate a personalized welcome message for {$customer['name']}", 'marketing_agent'); $personalizedMessage->toWhatsApp($customer['phone'], '🎉 Welcome '); }
Error Handling
The SDK throws RuntimeException for API errors and InvalidArgumentException for invalid parameters:
try { $result = $apipedia->whatsapp('invalid_number', 'Test message'); } catch (InvalidArgumentException $e) { echo "Invalid argument: " . $e->getMessage(); } catch (RuntimeException $e) { echo "API error: " . $e->getMessage(); }
Configuration
Custom HTTP Client
You can customize the HTTP client behavior:
use GuzzleHttp\Client; $customClient = new Client([ 'timeout' => 60, 'verify' => false, // Only for development ]); $apipedia = new Apipedia('app_key', 'auth_key'); // Use reflection to set custom client if needed
Environment Variables
For better security, store your credentials in environment variables:
$apipedia = new Apipedia( $_ENV['APIPEDIA_APP_KEY'], $_ENV['APIPEDIA_AUTH_KEY'] );
Testing
Run the test suite:
# Run all tests composer test # Run tests with coverage composer test-coverage # Run code style checks composer phpcs # Fix code style issues composer phpcs-fix # Run static analysis composer phpstan
API Reference
Method Chaining
All methods return the Apipedia instance, allowing for fluent chaining:
$result = $apipedia ->method1() ->method2() ->method3() ->getResult();
Available Methods
| Method | Description | Returns |
|---|---|---|
whatsapp($to, $message, $media = null) |
Send WhatsApp message | Apipedia |
bulkV1($numbers, $message) |
Bulk send same message | Apipedia |
bulkV2($numbers, $messages) |
Bulk send different messages | Apipedia |
telegramSendMessage($receiver, $body) |
Send Telegram message | Apipedia |
telegramSendImage($receiver, $imageUrl, $caption = '') |
Send Telegram image | Apipedia |
telegramSendLocation($receiver, $lat, $lng) |
Send Telegram location | Apipedia |
telegramSendButtons($receiver, $body, $buttons) |
Send Telegram buttons | Apipedia |
telegramSendDocument($receiver, $docUrl, $caption = '', $filename = '') |
Send Telegram document | Apipedia |
smsRegular($to, $msg) |
Send regular SMS | Apipedia |
smsVIP($to, $msg) |
Send VIP SMS | Apipedia |
smsOTP($to, $msg) |
Send OTP SMS | Apipedia |
smsVVIP($to, $msg) |
Send VVIP SMS | Apipedia |
aiChat($message, $agentId, $format = 'text') |
AI chat interaction | Apipedia |
toWhatsApp($to, $prefix = '') |
Chain to WhatsApp | Apipedia |
toTelegram($receiver, $prefix = '') |
Chain to Telegram | Apipedia |
toSMS($to, $prefix = '') |
Chain to SMS | Apipedia |
getProfile() |
Get profile information | Apipedia |
updatePresence($receiver, $presence, $duration = null) |
Update presence | Apipedia |
getMessageStatusAll($messageId) |
Get all message statuses | Apipedia |
getLastStatus($messageId) |
Get last message status | Apipedia |
getLastReceiptStatus($messageId) |
Get last receipt status | Apipedia |
getResult() |
Get last API response | array|null |
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Support
- 📧 Email: support@apipedia.id
- 📚 Documentation: https://docs.apipedia.id
- 🐛 Issues: GitHub Issues
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for a list of changes and version history.
Made with ❤️ by the Apipedia Team
apipedia/php-sdk 适用场景与选型建议
apipedia/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sms」 「messaging」 「notification」 「chat」 「whatsapp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 apipedia/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 apipedia/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 apipedia/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
PHP SDK for Mobile Message SMS API
Extensible library for building notifications and sending them via different delivery channels.
Azure service bus Transport
Official PHP client for NATS messaging system
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-25