搜尋套件、儲存庫與 APP 分類

套件詳情v2.1.2

whatsapp_bot_flutter

使用 Puppeteer 和 WhatsApp 網頁抓取的 WhatsApp 機器人,支援 Flutter 桌面/網頁和 Dart 項目

WebmacOSWindowsLinux
近 30 天下載
296
喜歡數
73
Pub 分數
160

安裝套件

flutter pub add whatsapp_bot_flutter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個Flutter/Dart套件,透過Puppeteer進行網頁擷取,實現WhatsApp機器人功能,專為桌面與Web應用程式設計。它允許開發者利用無頭瀏覽器功能,自動化與WhatsApp Web的互動。此套件支援在Web、macOS、Windows及Linux上的跨平台部署,非常適合建構自訂訊息工具。它能順暢整合至Flutter專案中,提供Dart邏輯與基於瀏覽器的WhatsApp互動之間的橋樑。

適用情境

  • 自動化客戶支援訊息
  • 批量訊息廣播
  • 計畫 WhatsApp 通知
  • 互動式聊天機器人介面
  • 基於桌面的 WhatsApp 自動化

主要特色

  • Puppeteer驅動的WhatsApp Web爬取
  • 跨平台支援(Web、macOS、Windows、Linux)
  • Flutter 和 Dart 項目整合
  • 無頭瀏覽器自動化
  • 即時訊息處理
  • 輕便且容易設定

適合對象

  • 開發桌面/網頁版 WhatsApp 機器人
  • 需要自動化訊息解決方案的團隊
  • 需要 WhatsApp 集成但沒有官方 API 的項目
  • 教育或原型設計用例

使用建議

  • 依賴 WhatsApp Web 的公開介面(可能在更新後失效)
  • 需要通過二維碼進行用戶身份驗證
  • 潛在的速率限制或來自WhatsApp的封禁
  • 未獲得 WhatsApp 官方支援
  • 依賴於跨平台的穩定 Puppeteer 性能

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Whatsapp bot flutter

whatsapp_bot_flutter_logo

whatsapp_bot_flutter version

whatsapp_bot_flutter_mobile version

whatsapp_bot_flutter_web version

Getting Started

We can use this library in Flutter as well as Pure dart projects , checkout dart_example

First launch on Desktop apps will take some time, it will download chromium files locally, using puppeteer

Usage

Get WhatsappClient using connect method

Either link with QRCode (default) and get QrCode in onQrCode callback or set linkWithPhoneNumber, and get code in onPhoneLinkCode callback

// use WhatsappBotFlutterMobile.connect for Android/IOS platforms
WhatsappClient? whatsappClient = await WhatsappBotFlutter.connect(
  onConnectionEvent: (ConnectionEvent event) {
    print(event.toString());
  },
  onQrCode: (String qr, Uint8List? imageBytes) {
    // use imageBytes to display in flutter : Image.memory(imageBytes)
    print(WhatsappBotFlutter.convertStringToQrCode(qr));
  },
);

We have these modules to access whatsappClient features :

WhatsappClient.chat
WhatsappClient.contact
WhatsappClient.profile
WhatsappClient.group

Use sendTextMessage to send a text message

phone parameter can be of this format : countryCode+phoneNumber , eg : 91xxxxxxxxxx , or we can get phone from messageEvents in this format : countryCode+phone+"@c.us"

await whatsappClient.chat.sendTextMessage(
    phone: "------",
    message: "Test Message",
);

Use sendFileMessage to send a File

await whatsappClient.chat.sendFileMessage(
    phone: "------",
    fileBytes: fileBytes, // Pass file bytes
    caption: "Test Message", // Optional
    fileType: fileType, // document, image, audio
);

To get whatsapp connection Events , subscribe to whatsappClient.connectionEventStream

whatsappClient.connectionEventStream.listen((event) {
  // Connection Events : authenticated,logout,connected.....
});

To get new Messages

whatsappClient.on(WhatsappEvent.chat_new_message, (data) {
    List<Message> messages = Message.parse(data);
    // replyMessageId  is optional , add this to send a reply message
    whatsappClient.chat.sendTextMessage(
      phone: message.from,
      message: "Hey !",
      replyMessageId: message.id,
    );
});

We can listen to multiple events like this

whatsappClient.on(WhatsappEvent.EVENT_NAME, (data) {})

To stop listening to an event

whatsappClient.off(WhatsappEvent.EVENT_NAME);

Features

Supported Whatsapp features : - Create multiple whatsapp clients
  • Login with QR
  • Auto refresh QrCode
  • Logout
  • Keep session
  • Listen to whatsapp events
  • Reject calls
  • Send text message
  • Send image, audio & document
  • Send location message
  • Send poll in groups
  • Send contact card
  • Reply to a message
  • Archive/Unarchive chats
  • Mute/Unmute chat
  • Clear chat
  • Delete chat
  • Get lastSeen
  • Get chats
  • Mark messages as seen
  • Mark message as unread
  • Pin/Unpin chat
  • Delete messages
  • Download media
  • Get messages
  • Get profile picture
  • Get status
  • Get contacts
  • Get status of loggedIn user
  • Set status
  • check if logged in user have business account
  • Set profile picture of logged in user
  • and many more..

Mobile Setup (Android/IOS)

To setup on Android , make sure to checkout flutter_inappwebview documentation for Android and IOS setup Android sdk:minSdkVersion cannot be smaller than version 19

Desktop setup (Windows/Mac/Linux)

For Macos , Enable outgoing and incoming connections, If getting sandbox issue , try disabling sandbox mode comment this out in macos/Runner/*.entitlements:

<key>com.apple.security.app-sandbox</key>
<true/>

Should run out of the box in Windows and Linux

Web setup

checkout web demo app : https://rohitsangwan01.github.io/whatsapp_bot_flutter

To run natively on Web, checkout whatsapp_bot_flutter_web

We can use browserless, Create a free account there and get API_TOKEN from browserless, and use this url to connect : wss://chrome.browserless.io?token=API_TOKEN

Or we can run puppeteer, and get browserWsEndpoint from there and pass into the connect method, checkout this example

then pass this browserWsEndpoint in connect method, and also requires wppJsContent, we can download this file from here, add this file in assets and pass like this,

await WhatsappBotFlutter.connect(
    browserWsEndpoint: "BROWSER_WS_ENDPOINT_URL",
    wppJsContent: await rootBundle.loadString("assets/wpp.js"),
);

We can use this on Mobile or Desktop platforms as well , to connect to a chrome server hosted somewhere else

If we have to access this webSocket url locally on Mobile or other platforms , we can use ngrok to expose our local Websocket url to internet

Resources

Thanks to wa-js for exporting functions from WhatsApp Web

Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at https://whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.

Note

Its just initial version, I can't guarantee you will not be blocked by using this method, try to avoid primary whatsapp numbers. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.

所屬分類

依賴

依賴清單 2 項

  • puppeteer^3.8.0
  • whatsapp_bot_platform_interface^2.0.2

原始碼儲存庫

使用此套件的專案

暫無相關資料。