teguh02/waha-php
Composer 安装命令:
composer require teguh02/waha-php
包简介
Unofficial WhatsApp HTTP API (WAHA) PHP Client - Complete implementation of WAHA API
README 文档
README
Unofficial PHP client library for WAHA (WhatsApp HTTP API) - a powerful solution to interact with WhatsApp Web through HTTP API.
Features
✅ Complete API Coverage - Support for all WAHA endpoints
- 📤 Send Messages: Text, Image, Video, Voice, File, Location, Contact, Poll
- 📥 Receive Messages: Webhooks and Event Handling
- 💬 Chats Management: List, Archive, Read, Delete
- 👤 Contacts Management: Get, Update, Block, Check Existence
- 👥 Groups Management: Create, Manage, Admin Controls
- 🟢 Status Management: Send and Manage WhatsApp Status
- 📢 Channels Management: Create and Manage Channels
- 🔐 Session Management: Create, Start, Stop, QR Code
- And much more!
✅ Simple & Intuitive - Clean, PHPic API design ✅ Type Hints - Full type hints for better IDE support ✅ Error Handling - Comprehensive error handling ✅ Documentation - Complete documentation and examples
Installation
Using Composer (Recommended)
composer require teguh02/waha-php
Or install from source:
git clone https://github.com/teguh02/waha-php.git
cd waha-php
composer install
Quick Start
1. Start WAHA Server
First, you need to have WAHA server running. Follow the Quick Start Guide:
docker pull devlikeapro/waha
docker run -it --env-file .env -v "$(pwd)/sessions:/app/.sessions" --rm -p 3000:3000 --name waha devlikeapro/waha
2. Use the PHP Client
<?php use WahaPhp\Client; require_once 'vendor/autoload.php'; // Initialize the client $client = new Client( 'http://localhost:3000', 'your-api-key-here' // Optional, if you set WAHA_API_KEY ); // Send a text message $result = $client->messages()->sendText( 'default', '1234567890@c.us', 'Hello from PHP! 👋' ); var_dump($result);
3. Create Session with QR Code
// Create a new session $session = $client->sessions()->create( name: 'my_session', config: [ 'webhooks' => [[ 'url' => 'https://your-webhook-url.com/webhook', 'events' => ['message'] ]] ] ); // Get QR code for authentication $qrCode = $client->sessions()->getQr('my_session', acceptJson: true); echo "QR Code (Base64): " . $qrCode['data'] . "\n"; // Scan the QR code with your WhatsApp app // The session status will change to WORKING
4. Receive Messages with Webhooks
Create a webhook server:
<?php use WahaPhp\Client; $client = new Client('http://localhost:3000', 'your-api-key'); // Handle webhook (example with Slim framework) $app->post('/webhook', function ($request, $response) use ($client) { $data = $request->getParsedBody(); if ($data['event'] === 'message') { $payload = $data['payload']; $fromNumber = $payload['from']; $messageText = $payload['body'] ?? ''; echo "Received: $messageText from $fromNumber\n"; // Reply to the message $client->messages()->sendText( $data['session'], $fromNumber, "You said: $messageText" ); } return $response->withJson(['status' => 'ok']); });
Complete Examples
Send Different Types of Messages
use WahaPhp\Client; $client = new Client('http://localhost:3000', 'your-api-key'); // Send text message $client->messages()->sendText( 'default', '1234567890@c.us', 'Hello World!' ); // Send image with URL $client->messages()->sendImage( 'default', '1234567890@c.us', ['url' => 'https://example.com/image.jpg', 'mimetype' => 'image/jpeg'], 'Check this out!' ); // Send image from file $client->messages()->sendImage( 'default', '1234567890@c.us', 'path/to/image.jpg', 'My image' ); // Send video $client->messages()->sendVideo( 'default', '1234567890@c.us', ['url' => 'https://example.com/video.mp4', 'mimetype' => 'video/mp4'] ); // Send voice message $client->messages()->sendVoice( 'default', '1234567890@c.us', ['url' => 'https://example.com/voice.opus', 'mimetype' => 'audio/ogg; codecs=opus'] ); // Send document $client->messages()->sendFile( 'default', '1234567890@c.us', ['url' => 'https://example.com/document.pdf', 'mimetype' => 'application/pdf'] ); // Send location $client->messages()->sendLocation( 'default', '1234567890@c.us', 38.8937255, -77.0969763, 'My Location' ); // Send contact $client->messages()->sendContact( 'default', '1234567890@c.us', [[ 'fullName' => 'John Doe', 'organization' => 'Company', 'phoneNumber' => '+91 11111 11111', 'whatsappId' => '911111111111' ]] ); // Send poll $client->messages()->sendPoll( 'default', '1234567890@c.us', [ 'name' => 'How are you?', 'options' => ['Awesome!', 'Good!', 'Not bad!'], 'multipleAnswers' => false ] );
Manage Sessions
// List all active sessions $sessions = $client->sessions()->list(); // List all sessions including stopped ones $allSessions = $client->sessions()->list(allSessions: true); // Get specific session $session = $client->sessions()->getSession('default'); // Create session $newSession = $client->sessions()->create( name: 'my_session', config: ['webhooks' => []] ); // Start session $client->sessions()->start('my_session'); // Stop session $client->sessions()->stop('my_session'); // Restart session $client->sessions()->restart('my_session'); // Logout session $client->sessions()->logout('my_session'); // Delete session $client->sessions()->delete('my_session'); // Get QR code $qr = $client->sessions()->getQr('default', acceptJson: true); // Request pairing code $codeInfo = $client->sessions()->requestCode('default', '12132132130'); echo "Pairing code: " . $codeInfo['code'] . "\n";
Manage Chats
// List all chats $chats = $client->chats()->list('default'); // Get chat picture $picture = $client->chats()->getPicture('default', '1234567890@c.us'); // Archive chat $client->chats()->archive('default', '1234567890@c.us'); // Unarchive chat $client->chats()->unarchive('default', '1234567890@c.us'); // Mark as unread $client->chats()->unread('default', '1234567890@c.us'); // Read messages $client->chats()->readMessages('default', '1234567890@c.us'); // Get messages $messages = $client->chats()->getMessages('default', '1234567890@c.us', limit: 100); // Get specific message $message = $client->chats()->getMessage( 'default', '1234567890@c.us', 'message_id_here' ); // Delete chat $client->chats()->delete('default', '1234567890@c.us');
Manage Contacts
// List all contacts $contacts = $client->contacts()->listAll('default'); // Get specific contact $contact = $client->contacts()->getContact('default', '1234567890'); // Update contact $client->contacts()->update( 'default', '1234567890@c.us', 'John', 'Doe' ); // Check if phone exists $result = $client->contacts()->checkExists('default', '1234567890'); if ($result['numberExists']) { echo "Chat ID: " . $result['chatId'] . "\n"; } // Get contact about $about = $client->contacts()->getAbout('default', '1234567890'); // Get profile picture $profilePic = $client->contacts()->getProfilePicture('default', '1234567890'); // Block contact $client->contacts()->block('default', '1234567890@c.us'); // Unblock contact $client->contacts()->unblock('default', '1234567890@c.us');
Manage Groups
// List all groups $groups = $client->groups()->list('default'); // Get specific group $group = $client->groups()->get('default', '1234567890@g.us'); // Create group $newGroup = $client->groups()->create( 'default', 'My New Group', ['1234567890@c.us'] ); // Update group name $client->groups()->updateSubject('default', '1234567890@g.us', 'Updated Name'); // Update group description $client->groups()->updateDescription('default', '1234567890@g.us', 'Description'); // Get invite code $inviteCode = $client->groups()->getInviteCode('default', '1234567890@g.us'); // Revoke invite code $client->groups()->revokeInviteCode('default', '1234567890@g.us'); // Get participants $participants = $client->groups()->getParticipants('default', '1234567890@g.us'); // Add participants $client->groups()->addParticipants( 'default', '1234567890@g.us', ['9876543210@c.us'] ); // Remove participants $client->groups()->removeParticipants( 'default', '1234567890@g.us', ['9876543210@c.us'] ); // Promote to admin $client->groups()->promoteAdmin( 'default', '1234567890@g.us', ['9876543210@c.us'] ); // Demote from admin $client->groups()->demoteAdmin( 'default', '1234567890@g.us', ['9876543210@c.us'] ); // Leave group $client->groups()->leave('default', '1234567890@g.us');
Manage Status (Stories)
// Send text status $client->status()->sendText('default', 'My status update'); // Send image status $client->status()->sendImage( 'default', ['url' => 'https://example.com/image.jpg', 'mimetype' => 'image/jpeg'] ); // Send video status $client->status()->sendVideo( 'default', ['url' => 'https://example.com/video.mp4', 'mimetype' => 'video/mp4'] ); // Send voice status $client->status()->sendVoice( 'default', ['url' => 'https://example.com/voice.opus', 'mimetype' => 'audio/ogg; codecs=opus'] ); // Delete status $client->status()->delete('default', 'message_id_here'); // Get new message ID $messageId = $client->status()->getNewMessageId('default');
Manage Channels
// List all channels $channels = $client->channels()->list('default'); // Get specific channel $channel = $client->channels()->get('default', 'channel_id'); // Create channel $newChannel = $client->channels()->create('default', 'My Channel', 'Description'); // Get channel messages $messages = $client->channels()->getMessages('default', 'channel_id', limit: 100); // Delete channel $client->channels()->delete('default', 'channel_id');
Message Reactions and Actions
// Add reaction $client->messages()->addReaction( 'default', 'message_id_here', '👍' ); // Remove reaction $client->messages()->addReaction( 'default', 'message_id_here', '' ); // Star message $client->messages()->starMessage( 'default', '1234567890@c.us', 'message_id_here' ); // Unstar message $client->messages()->starMessage( 'default', '1234567890@c.us', 'message_id_here', star: false ); // Edit message $client->messages()->editMessage( 'default', '1234567890@c.us', 'message_id_here', 'Updated message' ); // Delete message $client->messages()->deleteMessage( 'default', '1234567890@c.us', 'message_id_here' ); // Forward message $client->messages()->forwardMessage( 'default', '1234567890@c.us', 'message_id_here' ); // Pin message $client->messages()->pinMessage( 'default', '1234567890@c.us', 'message_id_here' ); // Unpin message $client->messages()->unpinMessage( 'default', '1234567890@c.us', 'message_id_here' );
Error Handling
use WahaPhp\Client; use WahaPhp\Exception\WahaAuthenticationException; use WahaPhp\Exception\WahaNotFoundException; try { $client = new Client('http://localhost:3000', 'wrong-key'); $result = $client->messages()->sendText( 'default', '1234567890@c.us', 'Hello' ); } catch (WahaAuthenticationException $e) { echo "Authentication failed\n"; } catch (WahaNotFoundException $e) { echo "Resource not found\n"; } catch (\Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
Requirements
- PHP 8.0+
- Guzzle HTTP library
- Composer
- WAHA server running (see Quick Start Guide)
Documentation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Support
- Packagist: https://packagist.org/packages/teguh02/waha-php
- GitHub Issues: https://github.com/teguh02/waha-php/issues
- WAHA Documentation: https://waha.devlike.pro
Important Disclaimer
This is an UNOFFICIAL community project and is not affiliated, associated, authorized, endorsed by, or in any way officially connected with:
- WhatsApp LLC or any of its subsidiaries or affiliates
- WAHA (devlikeapro) team
The official WhatsApp website can be found at whatsapp.com.
The official WAHA documentation can be found at waha.devlike.pro.
"WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
Usage Warning
This library interacts with WhatsApp through unofficial means. There are risks associated with using unofficial WhatsApp clients:
- Account suspension or banning
- Security risks
- Data privacy concerns
- No official support
Use at your own risk. For business applications, we recommend using the official WhatsApp Business API.
teguh02/waha-php 适用场景与选型建议
teguh02/waha-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「client」 「whatsapp」 「waha」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 teguh02/waha-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 teguh02/waha-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 teguh02/waha-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-01