承接 saythanks/laravel-whatsapp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

saythanks/laravel-whatsapp

最新稳定版本:v0.1.1

Composer 安装命令:

composer require saythanks/laravel-whatsapp

包简介

WhatsApp Cloud API Notification Channel for Laravel

README 文档

README

WhatsApp Cloud API Notification Channel for Laravel.

Installation

composer require saythanks/laravel-whatsapp

Publish the config file:

php artisan vendor:publish --tag="laravel-whatsapp-config"

Configuration

Add these to your .env:

WHATSAPP_ACCESS_TOKEN=your-meta-access-token
WHATSAPP_PHONE_NUMBER_ID=your-phone-number-id
WHATSAPP_BUSINESS_ACCOUNT_ID=your-business-account-id
WHATSAPP_WEBHOOK_VERIFY_TOKEN=your-webhook-verify-token

Optional settings:

WHATSAPP_API_VERSION=v22.0
WHATSAPP_API_BASE_URL=https://graph.facebook.com
WHATSAPP_DELIVERY_ENABLED=true
WHATSAPP_LOG_STATUS_UPDATES=false
WHATSAPP_STORE_CACHE_ENABLED=false
WHATSAPP_STORE_CACHE_TTL=86400

Usage

Sending Notifications

Add the routing method to your notifiable model:

public function routeNotificationForWhatsapp($notification)
{
    return $this->phone_number; // E.164 format without +
}

Create a notification with a toWhatsapp method:

use LaravelWhatsapp\Facades\LaravelWhatsapp;

class VoucherCreated extends Notification
{
    public function via($notifiable)
    {
        return ['whatsapp'];
    }

    // Text message (within 24h customer service window)
    public function toWhatsapp($notifiable)
    {
        return LaravelWhatsapp::message('Your voucher is ready!')
            ->userReferenceId('voucher-' . $this->voucher->getKey());
    }
}

Template Messages

For business-initiated conversations (outside 24h window), use template messages:

public function toWhatsapp($notifiable)
{
    return LaravelWhatsapp::template('voucher_created', 'en')
        ->bodyParameters([
            ['type' => 'text', 'text' => $recipientName],
            ['type' => 'text', 'text' => $voucherValue],
        ])
        ->userReferenceId('voucher-' . $this->voucher->getKey());
}

Templates must be pre-approved in your Meta Business Manager.

Webhooks

The package provides form requests for handling Meta webhook callbacks:

Status Updates (delivery reports):

use LaravelWhatsapp\Requests\WhatsappStatusUpdateRequest;

public function handleStatusUpdate(WhatsappStatusUpdateRequest $request)
{
    $dto = $request->toDto();
    // $dto->messageId, $dto->status, $dto->recipientId, $dto->getStatusEnum()
}

Incoming Messages (replies):

use LaravelWhatsapp\Requests\WhatsappIncomingMessageRequest;

public function handleIncomingMessage(WhatsappIncomingMessageRequest $request)
{
    $dto = $request->toDto();
    // $dto->messageId, $dto->from, $dto->textBody, $dto->senderName
}

Webhook Verification (Meta requires a GET verification handshake):

public function verify(Request $request)
{
    if ($request->query('hub_verify_token') === config('whatsapp.webhook_verify_token')) {
        return response($request->query('hub_challenge'), 200);
    }
    return response('Forbidden', 403);
}

Message Types

TypeUse CaseMethod
TextWithin 24h customer service windowLaravelWhatsapp::message('text')
TemplateBusiness-initiated (any time)LaravelWhatsapp::template('name', 'lang')

Message Status Enum

StatusDescription
sentMessage sent to WhatsApp servers
deliveredMessage delivered to recipient
readMessage read by recipient
failedMessage delivery failed

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

ngrok http https://website.test --host-header=website.test

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固