一个 Flutter 包,可实现与 WhatsApp Business API 的集成,使开发者能够从其 Flutter 应用程序直接发送消息、产品目录、媒体文件和位置数据。专为无缝跨平台通信设计,支持 Android、iOS、Web、macOS、Windows 和 Linux。该包简化了通过 WhatsApp 发送丰富内容的过程,非常适合客户互动、订单确认和自动化通知。基于官方 WhatsApp Business API 构建,确保消息传递的可靠性和安全性。
适合场景
发送订单确认
自动客户通知
共享产品目录
发送位置更新
共享媒体文件
客户支持消息
主要特点
支持包括文本、媒体和位置在内的消息类型
与 WhatsApp Business API 集成
跨平台兼容性
使用 Flutter pub 轻松设置
实时消息传递
产品目录共享
适合对象
电子商务应用
客户服务平台
商务沟通工具
自动化通知系统
需要 WhatsApp 集成的移动应用
使用建议
需要 WhatsApp Business API 访问权限
需要正确的身份验证设置
可能需要企业账户验证
速率限制适用
依赖稳定的互联网连接
遵守WhatsApp的政策
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
This Flutter package allows you to integrate the WhatsApp Business API into your Flutter applications. It enables sending messages, media, templates, managing business information, creating interactives and flows, sending catalog messages, and more. The package is updated to support the latest WhatsApp Business API v23.0.
Performance Improvements – Optimized core methods, now up to 3x faster than previous versions.
Web Platform Support – Now supports fully compatibility with Flutter Web for most features.
Service-Specific Methods – Each service now provides dedicated getters for cleaner and more explicit usage.
Flow Messages – Added support for interactive flow messages to improve user engagement.
Catalog & Product Messages – Send product details and catalog messages for e-commerce use cases.
Resumable Uploads – Support for creating and managing resumable upload sessions for large files.
Error Handling Enhancements – Improved and added WhatsAppException handling with detailed error types.
Bug Fixes – Resolved multiple issues affecting stability and reliability.
API Upgrade – Updated to support WhatsApp Business API v23.0 (stable).
Basic Usage
// Access token provided by Meta for WhatsApp Cloud APIconst accessToken = 'YOUR_ACCESS_TOKEN';
// Your WhatsApp Business phone number IDconst fromNumberId = 'YOUR_PHONE_NUMBER_ID';
// Create WhatsApp client instancefinal whatsapp = WhatsApp(accessToken, fromNumberId);
try {
// Send a simple text messagevar message = await whatsapp.sendMessage(
phoneNumber: 'RECEIPT_NUMBER', // Recipient's phone number in international format
text: 'Hi, how are you?', // Message content
);
// Message sent successfully// Get and print the unique ID of the sent messageprint('Message ID: ${message.getMessageId()}');
// Get and print the recipient numberprint('Message sent to: ${message.getContactId()}');
// Get and print the full API response bodyprint('API Response: ${message.getFullResponse()}');
} onWhatsAppExceptioncatch (e) {
// Message failed to send// Print HTTP error code returned by the APIprint('HTTP Code: ${e.statusCode}');
// Print exact error details from WhatsApp Cloud APIprint('API Error: ${e.message}');
// Print type of request error (e.g., validation, authorization, etc.)print('Request Error: ${e.errorType}');
} catch (e) {
print('Unexpected error: $e');
}
Have you found a bug or have a suggestion of how to enhance WhatsApp Package? Open an issue or pull request and we will take a look at it as soon as possible.
Report bugs or issues
You are welcome to open a ticket on github if any problems arise. New ideas are always welcome.