bahricanli/whatsapp-bridge 问题修复 & 功能扩展

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

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

bahricanli/whatsapp-bridge

最新稳定版本:v1.0.2

Composer 安装命令:

composer require bahricanli/whatsapp-bridge

包简介

Laravel notification channel for WhatsApp via Baileys Bridge

README 文档

README

Latest Version License: MIT

Laravel notification channel for sending WhatsApp messages via a self-hosted Baileys bridge.

Designed as a parallel channel alongside bahricanli/netgsm — the API is intentionally similar for easy integration.

Requirements

Installation

composer require bahricanli/whatsapp-bridge

Laravel's auto-discovery registers the service provider automatically.

Publish the config file:

php artisan vendor:publish --tag=whatsapp-bridge-config

Configuration

Add the following to your .env:

WHATSAPP_BRIDGE_URL=http://localhost:3000
WHATSAPP_BRIDGE_API_KEY=           # optional
WHATSAPP_BRIDGE_TIMEOUT=10

Or edit config/whatsapp-bridge.php directly.

Usage

1. Direct usage (no notification system)

use NotificationChannels\WhatsAppBridge\WhatsAppFacade as WhatsApp;
use NotificationChannels\WhatsAppBridge\WhatsAppMessage;

// Shorthand
WhatsApp::sendMessage('905551234567', 'Doğrulama kodunuz: 4821');

// Fluent message
WhatsApp::sendMessage(
    WhatsAppMessage::create('Doğrulama kodunuz: 4821')->to('905551234567')
);

2. As a Laravel notification channel

In your notification class:

use Illuminate\Notifications\Notification;
use NotificationChannels\WhatsAppBridge\WhatsAppChannel;
use NotificationChannels\WhatsAppBridge\WhatsAppMessage;

class PhoneVerificationNotification extends Notification
{
    public function __construct(private string $code) {}

    public function via($notifiable): array
    {
        return [WhatsAppChannel::class];
    }

    public function toWhatsApp($notifiable): WhatsAppMessage
    {
        return WhatsAppMessage::create("Doğrulama kodunuz: {$this->code}");
        // Recipient is pulled from routeNotificationForWhatsAppBridge()
    }
}

In your notifiable model (e.g. User):

public function routeNotificationForWhatsAppBridge(): string
{
    return $this->phone_number; // e.g. 905551234567
}

3. Parallel with NetGSM

Send via both SMS and WhatsApp simultaneously:

public function via($notifiable): array
{
    return [
        \NotificationChannels\Netgsm\NetgsmChannel::class,
        \NotificationChannels\WhatsAppBridge\WhatsAppChannel::class,
    ];
}

public function toNetgsm($notifiable): string
{
    return "Doğrulama kodunuz: {$this->code}";
}

public function toWhatsApp($notifiable): WhatsAppMessage
{
    return WhatsAppMessage::create("Doğrulama kodunuz: {$this->code}");
}

Phone Number Formats

The library normalizes phone numbers automatically:

Input Stored as
905551234567 905551234567
+905551234567 905551234567
0905551234567 905551234567
05551234567 905551234567
5551234567 905551234567

Events

Event Fired
SendingMessage Before a message is sent
MessageWasSent After successful delivery
use NotificationChannels\WhatsAppBridge\Events\MessageWasSent;

Event::listen(MessageWasSent::class, function (MessageWasSent $event) {
    Log::info('WhatsApp sent', [
        'to'      => $event->message->to,
        'content' => $event->message->content,
    ]);
});

Bridge Status Check

use NotificationChannels\WhatsAppBridge\WhatsAppFacade as WhatsApp;

$status = WhatsApp::status();
// ['ok' => true, 'connected' => true, 'sessions' => 3]

License

MIT — see LICENSE.md.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固