一個 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.