darkclow4/laravel-waha-messages 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

darkclow4/laravel-waha-messages

Composer 安装命令:

composer require darkclow4/laravel-waha-messages

包简介

Laravel integration package for WAHA (WhatsApp HTTP API)

README 文档

README

A Laravel package for seamless integration with WAHA (WhatsApp HTTP API). Send messages, manage sessions, handle groups, contacts, and chats — all through a clean, fluent API.

Warning

Unofficial API Notice WAHA is an unofficial WhatsApp API. Please use this package responsibly. Sending messages too quickly, sending spam, or violating WhatsApp's Terms of Service may result in your WhatsApp number being permanently banned or blocked by Meta. Use at your own risk.

Requirements

  • PHP 8.3+
  • Laravel 11.x or above
  • A running WAHA instance

Installation

Add the package to your Laravel project:

composer require darkclow4/laravel-waha-messages

The service provider and facade are auto-discovered. To publish the config file:

php artisan vendor:publish --tag=waha-config

Configuration

Add the following to your .env file:

WAHA_URL=http://localhost:3000
WAHA_API_KEY=your-api-key
WAHA_SESSION=default
WAHA_TIMEOUT=30
WAHA_CONNECT_TIMEOUT=10
WAHA_RETRY_TIMES=3
WAHA_RETRY_SLEEP=100
Variable Description Default
WAHA_URL Base URL of your WAHA server http://localhost:3000
WAHA_API_KEY API key for authentication null
WAHA_SESSION Default session name default
WAHA_TIMEOUT Request timeout (seconds) 30
WAHA_CONNECT_TIMEOUT Connection timeout (seconds) 10
WAHA_RETRY_TIMES Number of retry attempts 3
WAHA_RETRY_SLEEP Delay between retries (ms) 100

Quick Start

use LaravelWaha\WahaMessages\Facades\Waha;

// Send a text message
Waha::messages()->sendText('1111111111111@c.us', 'Hello from Laravel!');

Usage

Sending Messages

Text Message

Waha::messages()->sendText('1111111111111@c.us', 'Hello World!');

// With a specific session
Waha::messages()->sendText('1111111111111@c.us', 'Hello!', 'my-session');

Image Message

Waha::messages()->sendImage(
    chatId: '1111111111111@c.us',
    url: 'https://example.com/photo.jpg',
    caption: 'Check out this image!',
);

Video Message

Waha::messages()->sendVideo(
    chatId: '1111111111111@c.us',
    url: 'https://example.com/video.mp4',
    caption: 'Watch this video!',
);

File / Document Message

Waha::messages()->sendFile(
    chatId: '1111111111111@c.us',
    url: 'https://example.com/report.pdf',
    filename: 'monthly-report.pdf',
);

Location Message

Waha::messages()->sendLocation(
    chatId: '1111111111111@c.us',
    latitude: -6.200000,
    longitude: 106.816666,
    title: 'Jakarta',
);

Contact vCard

Waha::messages()->sendContact(
    chatId: '1111111111111@c.us',
    contact: [
        'fullName' => 'John Doe',
        'phoneNumber' => '+1111111111111',
    ],
);

Mark as Seen

Waha::messages()->sendSeen('1111111111111@c.us');

Typing Indicator

// Start typing
Waha::messages()->startTyping('1111111111111@c.us');

// Stop typing
Waha::messages()->stopTyping('1111111111111@c.us');

Human-Like Messaging

Send messages that simulate real human behavior. The flow automatically executes in this order:

  1. Mark as seen — Read receipt appears on the chat
  2. Start typing — Typing indicator shows up
  3. Delay — Waits based on the message character count
  4. Stop typing — Typing indicator disappears
  5. Send message — The actual message is delivered
// Basic usage
Waha::humanLike()->sendText('1111111111111@c.us', 'Hello!');

// With a specific session
Waha::humanLike()->sendText('1111111111111@c.us', 'Hello!', 'my-session');

Configuring Typing Speed

You can fine-tune the typing delay using a fluent API:

Waha::humanLike()
    ->msPerChar(100)     // 100ms per character (default: 300)
    ->minDelay(1000)     // Minimum 1 second delay (default: 2000ms)
    ->maxDelay(15000)    // Maximum 15 second delay (default: 10000ms)
    ->sendText('1111111111111@c.us', 'This message will take longer to "type"...');
Option Description Default
msPerChar(int) Milliseconds per character 300
minDelay(int) Minimum delay in ms 2000
maxDelay(int) Maximum delay in ms 10000

Tip: A short message like "Hi!" (3 chars × 300ms = 900ms) will use the minDelay instead. A very long message will be capped at maxDelay.

Session Management

// List all sessions
$sessions = Waha::sessions()->list();

// Create a new session
Waha::sessions()->create(['name' => 'my-session']);

// Start / Stop / Logout
Waha::sessions()->start('my-session');
Waha::sessions()->stop('my-session');
Waha::sessions()->logout('my-session');

// Get session details
$session = Waha::sessions()->get('my-session');

// Get QR code for authentication
$qr = Waha::sessions()->qr('my-session');

// Request authentication code
Waha::sessions()->requestCode('my-session', [
    'phoneNumber' => '1111111111111',
]);

// Update a session
Waha::sessions()->update('my-session', ['webhooks' => [...]]);

// Delete a session
Waha::sessions()->delete('my-session');

Chat Management

// Get chats overview
$chats = Waha::chats()->overview();

// Get messages from a specific chat
$messages = Waha::chats()->messages('1111111111111@c.us', limit: 50);

// Delete a chat
Waha::chats()->deleteChat('1111111111111@c.us');

// Use a specific session
$chats = Waha::chats()->overview('my-session');

Group Management

// List all groups
$groups = Waha::groups()->list();

// Create a group
Waha::groups()->create('Project Team', [
    '1111111111111@c.us',
    '1111111111112@c.us',
]);

// Get group details
$group = Waha::groups()->get('120363001234567890@g.us');

// Add participants
Waha::groups()->addParticipants('120363001234567890@g.us', [
    '1111111111113@c.us',
]);

// Remove participants
Waha::groups()->removeParticipants('120363001234567890@g.us', [
    '1111111111113@c.us',
]);

Contact Management

// List all contacts
$contacts = Waha::contacts()->list();

// Get a specific contact
$contact = Waha::contacts()->get('1111111111111@c.us');

// Check if a phone number exists on WhatsApp
$result = Waha::contacts()->checkExists('1111111111111');
// Returns: ['numberExists' => true, 'chatId' => '1111111111111@c.us']

// Get profile picture URL
$picture = Waha::contacts()->profilePicture('1111111111111@c.us');

Using the Client Directly

You can also inject WahaClient directly via dependency injection:

use LaravelWaha\WahaMessages\WahaClient;

class NotificationService
{
    public function __construct(
        private WahaClient $waha,
    ) {}

    public function sendAlert(string $phone, string $message): void
    {
        $this->waha->messages()->sendText("{$phone}@c.us", $message);
    }
}

Error Handling

The package throws specific exceptions for API errors:

use LaravelWaha\WahaMessages\Exceptions\WahaException;
use LaravelWaha\WahaMessages\Exceptions\WahaAuthenticationException;
use LaravelWaha\WahaMessages\Exceptions\WahaNotFoundException;

try {
    Waha::sessions()->get('non-existent');
} catch (WahaNotFoundException $e) {
    // Session not found (404)
    $e->getStatusCode();    // 404
    $e->getResponseBody();  // ['message' => '...']
} catch (WahaAuthenticationException $e) {
    // Invalid API key (401)
} catch (WahaException $e) {
    // Any other API error
}

Chat ID Format

WAHA uses the following chat ID formats:

Type Format Example
Individual {phone}@c.us 1111111111111@c.us
Group {id}@g.us 120363001234567890@g.us

Note: Phone numbers should include the country code without the + prefix.

License

MIT

darkclow4/laravel-waha-messages 适用场景与选型建议

darkclow4/laravel-waha-messages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「messaging」 「laravel」 「whatsapp」 「waha」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 darkclow4/laravel-waha-messages 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 darkclow4/laravel-waha-messages 我们能提供哪些服务?
定制开发 / 二次开发

基于 darkclow4/laravel-waha-messages 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-27