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

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

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

axolotesource/laravel-whatsapp-api

Composer 安装命令:

composer require axolotesource/laravel-whatsapp-api

包简介

This Laravel package facilitates sending WhatsApp messages seamlessly within your application. With easy integration, it empowers developers to incorporate WhatsApp messaging functionality, enhancing user engagement and communication in a straightforward manner.

README 文档

README

Latest Version Total Downloads License

Laravel package to easily send WhatsApp messages using the WhatsApp Cloud API (Graph API).

Table of Contents

Installation

composer require axolotesource/laravel-whatsapp-api

Publish the configuration file:

php artisan vendor:publish --provider="Axolotesource\LaravelWhatsappApi\LaravelWhatsappApiServiceProvider"

Environment variables (.env)

WHATSAPP_BUSINESS_ACCOUNT_ID=
WHATSAPP_BUSINESS_PHONE_NUMBER_ID=
WHATSAPP_BUSINESS_BEARER=
WHATSAPP_HOOK_VERIFY_TOKEN=
WHATSAPP_BUSINESS_API=https://graph.facebook.com/v23.0/
WHATSAPP_BUSINESS_TEST_NUMBER=
WHATSAPP_BUSINESS_TEST_MODE=false
DEFAULT_INITIAL_TEMPLETE=default
WHATSAPP_RAW_TEMPLETE=
TEMPLETE_IMAGEN_HEAD=
DISABLE_WHATSAPP_HOOK=false
REPLICATE_WHATSAPP_HOOK_URLS=[]

Features

Feature Status
Text messages
Templates with components
Interactive buttons (up to 3)
Interactive lists with sections
Images (by media ID)
Images (by URL)
Videos (by URL)
Raw messages
Image upload
Video upload
Retrieve media metadata
Query registered templates (WhatsAppTemplate)
Template pagination
Test / fake mode
Document sending ❌ (TODO)
Document upload ❌ (TODO)
Audio upload ❌ (TODO)
Sticker upload ❌ (TODO)
Audio messages
Sticker messages
Location messages
Contact messages
Reaction messages
Catalogs / multi-product
Flow messages
Webhook handling
Business profile

Usage

Sending templates

The first message to a new contact must be a Meta-approved template.

WhatsAppMessages::templete('521234567890')
    ->language('es_MX')
    ->addComponents([
        BodyComponent::create([
            Params::text('This is a test message')
        ]),
        ButtonComponent::create([
            Params::button('yes')
        ]),
        ButtonComponent::create([
            Params::button('no')
        ]),
        ButtonComponent::create(
            [
                Params::button('history/login?folio=123ABC')
            ],
            ButtonComponent::SUB_TYPE_URL
        ),
        ButtonComponent::create([
            Params::button('never')
        ])
    ]);

If you don't pass a template name, it will use the default_initial_templete config value.

Template components

  • BodyComponent – Message body
  • HeaderComponent – Header
  • ButtonComponent – Buttons (supports QUICK_REPLY and URL)

Parameters

Params::text(string $text, ?string $parameterName = null)
Params::button(string $payload)
Params::imageFromUrl(string $url)

Text messages

use Axolotesource\LaravelWhatsappApi\WhatsAppMessages\WhatsAppMessages;

WhatsAppMessages::text('521234567890')
    ->body('Hello, this is a text message')
    ->send();

// You can also disable URL previews
WhatsAppMessages::text('521234567890', false)
    ->body('Message without URL preview')
    ->send();

Using textMessage (replaces text, which is deprecated):

WhatsAppMessages::textMessage('521234567890')
    ->body('Hello world')
    ->send();

Interactive buttons

Up to 3 quick reply buttons.

WhatsAppMessages::interactiveButtons('521234567890')
    ->setHeaderText('Optional header')
    ->body('Message body')
    ->footer('Optional footer')
    ->addButton('Option 1', 1)
    ->addButton('Option 2', 2)
    ->addButton('Option 3', 3)
    ->send();

Also supports media headers:

WhatsAppMessages::interactiveButtons('521234567890')
    ->setHeaderImage('https://example.com/image.jpg')
    ->body('Message body')
    ->addButton('Yes', 'yes')
    ->addButton('No', 'no')
    ->send();

Interactive lists

WhatsAppMessages::interactiveList('521234567890')
    ->body('Choose an option:')
    ->button('View options')
    ->addSection('Section 1', [
        Row::create('Row title 1', 'id-1', 'Optional description'),
        Row::create('Row title 2', 'id-2'),
    ])
    ->addSection('Section 2', [
        Row::create('Row title 3', 'id-3'),
    ])
    ->send();

Sending images

By media ID (requires uploading the file first):

$media = WhatsAppMedia::image('/local/path/image.jpg')->upload();

WhatsAppMessages::image('521234567890', $media)
    ->send();

By URL:

WhatsAppMessages::imageByUrl('521234567890', 'https://example.com/image.jpg')
    ->send();

Sending video by URL

WhatsAppMessages::videoByUrl('521234567890', 'https://example.com/video.mp4')
    ->send();

Uploading media

use Axolotesource\LaravelWhatsappApi\WhatsAppMessages\WhatsAppMedia;

// Upload image
$media = WhatsAppMedia::image('/path/image.jpg')->upload();

// Upload video
$media = WhatsAppMedia::video('/path/video.mp4')->upload();

// Retrieve media metadata by ID
$media = WhatsAppMedia::retrieve('MEDIA_ID')->get();

Raw messages

For fully custom requests:

WhatsAppMessages::raw([
    'type' => 'text',
    'text' => [
        'body' => 'Hello {{name}}'
    ],
], '521234567890', ['name' => 'John'])
    ->send();

Querying registered templates on Meta

WhatsAppTemplate allows you to retrieve information about templates registered in your WhatsApp Business account.

use Axolotesource\LaravelWhatsappApi\WhatsAppMessages\WhatsAppTemplate;

Get all templates

$templates = WhatsAppTemplate::all(); // Collection of TemplateDTO

Filters

// By status
WhatsAppTemplate::where('status', 'APPROVED')->get();

// By category
WhatsAppTemplate::where('category', 'UTILITY')->get();

// By name
WhatsAppTemplate::where('name', 'my_template')->get();

// By language
WhatsAppTemplate::where('language', 'es_MX')->get();

// Multiple values
WhatsAppTemplate::whereIn('status', ['APPROVED', 'PENDING'])->get();

Selecting fields

WhatsAppTemplate::select(['name', 'status', 'category', 'language', 'components'])->get();

Available fields: id, name, status, category, language, components, last_updated_time, quality_score, rejected_reason.

Limit results

WhatsAppTemplate::limit(10)->get();

Pagination

$list = WhatsAppTemplate::list(); // TemplateList

foreach ($list->data() as $template) {
    echo $template->name . ' - ' . $template->status;
}

if ($list->hasNextPage()) {
    $nextPage = $list->nextPage();
}

TemplateDTO

Each template is returned as a TemplateDTO with the following properties:

Property Type Description
id string Template ID
name string Template name
status string Status (APPROVED, PENDING, REJECTED, etc.)
category string Category (MARKETING, UTILITY, AUTHENTICATION)
language string Language code
components array Array of ComponentDTO

Fake mode

WhatsAppMessages::fake();
WhatsAppTemplate::all(); // returns simulated data

Test mode

// Activate to send all messages to the test number
WhatsAppMessages::fake();

When WHATSAPP_BUSINESS_TEST_MODE=true, all messages are automatically redirected to WHATSAPP_BUSINESS_TEST_NUMBER.

toArray() method

You can get the payload without sending it:

$payload = WhatsAppMessages::text('521234567890')
    ->body('Hello')
    ->toArray();

API Reference

Method Description
WhatsAppMessages::text($to, $previewUrl) Simple text message
WhatsAppMessages::textMessage($to, $previewUrl) Text message (replaces text)
WhatsAppMessages::templete($to, $templateName) Send approved template
WhatsAppMessages::interactiveButtons($to) Interactive buttons (up to 3)
WhatsAppMessages::interactiveList($to) Interactive list with sections
WhatsAppMessages::image($to, Media $media) Image by media ID
WhatsAppMessages::imageByUrl($to, $url) Image by URL
WhatsAppMessages::videoByUrl($to, $url) Video by URL
WhatsAppMessages::raw($request, $to, $params) Raw payload with variable replacement
WhatsAppMessages::test($to) Send "hello_world" test template
WhatsAppMessages::fake() Enable fake responses for testing
WhatsAppTemplate::all() Get all registered templates
WhatsAppTemplate::get() Get templates with filters
WhatsAppTemplate::list() Get templates with pagination (TemplateList)
WhatsAppTemplate::where($field, $value) Filter by status, category, name, language
WhatsAppTemplate::whereIn($field, $values) Filter by multiple values
WhatsAppTemplate::select($fields) Select specific fields
WhatsAppTemplate::limit($n) Limit number of results

License

MIT

axolotesource/laravel-whatsapp-api 适用场景与选型建议

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

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

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

围绕 axolotesource/laravel-whatsapp-api 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-11