bootdesk/chat-sdk-adapter-whatsapp 问题修复 & 功能扩展

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

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

bootdesk/chat-sdk-adapter-whatsapp

Composer 安装命令:

composer require bootdesk/chat-sdk-adapter-whatsapp

包简介

WhatsApp adapter for bootdesk/chat-sdk-core

README 文档

README

WhatsApp Business API adapter for the laravel-bootdesk multi-platform messaging framework.

Install

composer require bootdesk/chat-sdk-adapter-whatsapp

Requires a PSR-18 HTTP client (guzzlehttp/guzzle, symfony/http-client, etc.) and a PSR-17 factory (nyholm/psr7 bundled).

Configuration

Variable Description Example
access_token WhatsApp Cloud API Access Token EAAx...
http_client PSR-18 HTTP client instance new GuzzleHttp\Client
phone_number_id Phone Number ID 9876543210
app_secret Meta App Secret abc123...
verify_token Webhook Verify Token my-verify-token
use BootDesk\ChatSDK\WhatsApp\WhatsAppAdapter;

$adapter = new WhatsAppAdapter(
    accessToken: env('WHATSAPP_ACCESS_TOKEN'),
    httpClient: new \GuzzleHttp\Client,
    phoneNumberId: env('WHATSAPP_PHONE_NUMBER_ID'),
    appSecret: env('WHATSAPP_APP_SECRET'),
    verifyToken: env('WHATSAPP_VERIFY_TOKEN'),
);

Laravel

The ChatServiceProvider auto-binds Psr\Http\Client\ClientInterface to GuzzleHttp\Client. Add to config/chat.php:

'whatsapp' => [
    'access_token'    => env('WHATSAPP_ACCESS_TOKEN'),
    'phone_number_id' => env('WHATSAPP_PHONE_NUMBER_ID'),
    'app_secret'      => env('WHATSAPP_APP_SECRET'),
    'verify_token'    => env('WHATSAPP_VERIFY_TOKEN'),
],

Quick Example

// Send a message to a phone number
$adapter->postMessage('whatsapp:+15551234567', 'Hello from laravel-bootdesk!');

Text Formatting

WhatsApp supports *bold*, _italic_, ~strikethrough~, `monospace`, code blocks , bullet lists (*/-), numbered lists (1.), and quotes (>). The SDK's WhatsAppFormatConverter automatically converts standard markdown (**bold**, ~~strike~~) to WhatsApp format when sending, and converts WhatsApp syntax back to standard markdown when receiving.

Template Messages

WhatsApp supports pre-approved message templates for notifications, alerts, and marketing. Send them via PostableMessage::template():

use BootDesk\ChatSDK\WhatsApp\WhatsAppTemplate;

$adapter->postMessage(
    'whatsapp:phone123:5511999999999',
    PostableMessage::template(
        WhatsAppTemplate::create('order_confirmation', 'en_US')
            ->bodyParam('John')
            ->bodyParam('#12345')
            ->buttonParam('Track Order', 'track_payload')
    )
);

WhatsAppTemplate API

Method Description
create(string $name, string $language) Factory with template name and language code
positional() Use positional {{1}}, {{2}} format (default)
named() Use named {{first_name}} format; bodyParam() then takes (text, parameterName)
bodyParam(string $text, ?string $parameterName = null) Adds a body parameter; pass parameterName for named format
headerImage(string $link) Header image media
headerVideo(string $link) Header video media
headerDocument(string $link, ?string $filename) Header document media
headerText(string $text) Header text parameter
buttonParam(string $label, string $payload = '', string $subtype = 'quick_reply') Button parameter; payload defaults to label if omitted

Serializes to WhatsApp API format:

{
  "type": "template",
  "template": {
    "name": "order_confirmation",
    "language": { "code": "en_US" },
    "components": [
      {
        "type": "body",
        "parameters": [
          { "type": "text", "text": "John" },
          { "type": "text", "text": "#12345" }
        ]
      },
      {
        "type": "button",
        "sub_type": "quick_reply",
        "index": 0,
        "parameters": [{ "type": "quick_reply", "payload": "track_payload" }]
      }
    ]
  }
}

Named parameters

Templates using {{first_name}} instead of {{1}}:

WhatsAppTemplate::create('order_confirmation', 'en_US')
    ->named()
    ->bodyParam('Jessica', 'first_name')
    ->bodyParam('SKBUP2-4CPIG9', 'order_number');

Sends parameter_name on each parameter and parameter_format: "named" at the template level. Omit ->named() (or call ->positional()) for positional {{1}} format.

Falls back to markdown text via __toString() when an adapter doesn't support templates.

Thread ID Format

Format Description
whatsapp:{phoneNumberId} One thread per phone number (missing user ID uses fallback)
whatsapp:{phoneNumberId}:{userPhoneNumber} Thread with known phone number
whatsapp:{phoneNumberId}:{bsuid} Thread identified by Business-Scoped User ID

Webhook

WhatsApp Cloud API sends webhook payloads. Verify requests using HMAC signature verification with the app secret.

BSUID (Business-Scoped User ID) Support

As of May 2026, WhatsApp supports BSUIDs — a user identifier independent of phone numbers. The adapter transparently handles both identifiers:

  • Inbound: reads from (phone) with fallback to from_user_id (BSUID)
  • Outbound: detects BSUID format (XX.xxxx) and uses recipient instead of to
  • Thread IDs: use whatever identifier was available in the webhook

Feature Matrix

Feature Supported
Post messages
Edit messages
Delete messages
Reactions
Slash commands
Typing indicator
Fetch messages
Fetch thread info
Fetch channel info
Get user
Open DM
Stream

Notes

WhatsApp Business API only. No edit or delete support in the WhatsApp Cloud API.

Documentationn

Full API documentation: https://bootdesk.github.io/chat-sdk

License

MIT

bootdesk/chat-sdk-adapter-whatsapp 适用场景与选型建议

bootdesk/chat-sdk-adapter-whatsapp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 190 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 bootdesk/chat-sdk-adapter-whatsapp 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-18