whatsapp_sender_flutter 0.0.4 copy "whatsapp_sender_flutter: ^0.0.4" to clipboard
whatsapp_sender_flutter: ^0.0.4 copied to clipboard

outdated

WhatsApp Sender is an unofficial API for Flutter to send bulk messages in Whatsapp

WhatsApp Sender #

af

WhatsApp Sender is an unofficial API for Flutter to send bulk messages in Whatsapp. It's not recommended using it in your company or for marketing purpose.

Buy Me A Book

Getting Started #

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  whatsapp_sender_flutter: ^0.0.3

Import it:

import 'package:whatsapp_sender_flutter/whatsapp_sender_flutter.dart';

Configuration #

For the first usage, wait for the automatic download of the .local-chromium folder in your project root. Without this folder the package will not work,this is because this package is based on puppeteer.

If automatic download doent't start

  1. Download .zip file
  • Mac download from here
  • Windows download from here
  • Linux download from here
  1. Extract and move the .local-chromium folder manually in your project root

Basic usage #

The process for sending messages is like for WhatsApp Web:

  1. Scan the qr code
  2. Start the sending

Render qrcode to scan #

For render qrcode to scan use package like pretty_qr_code.

   import 'package:pretty_qr_code/pretty_qr_code.dart';
   ...
   ValueListenableBuilder<String>(
     valueListenable: WhatsAppSender.qrCode,
     builder: (context, value, widget) {
              return value.isEmpty 
                     ? const SizedBox()
                      : PrettyQr(
                          size: 300,
                          data: value,
                          roundEdges: true,
                        );
                      },
  ),

The static variable WhatsAppSender.qrCode is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Start the sending #

After you have scanned the code, you can start the sending campaign.

All phones must contain the international prefix!

   await WhatsAppSender.sendTo(
         phones: [ "+391111111", "+391111111", "+391111111"],
         message: "Hello",
   );

Advanced usage #

Listen sending status #

   ValueListenableBuilder<String>(
     valueListenable: WhatsAppSender.status,
     builder: (context, value, widget) {
                return Text(value);
              },
  ),

The static variable WhatsAppSender.status is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Possible states of WhatsAppSender.status are:

  • WhatsAppSenderStatusMessage.initialize during WhatsApp initialization
  • WhatsAppSenderStatusMessage.scanQrCode during qr code scanning
  • WhatsAppSenderStatusMessage.sending during sending
  • WhatsAppSenderStatusMessage.done if seding is end
  • WhatsAppSenderStatusMessage.qrCodeExpirated if qrcode to scan is expirated

Listen the number of success sendings #

   ValueListenableBuilder<String>(
     valueListenable: WhatsAppSender.success,
     builder: (context, value, widget) {
                return Text(value.toString());
              },
  ),

The static variable WhatsAppSender.success is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Listen the number of fails sendings #

   ValueListenableBuilder<String>(
     valueListenable: WhatsAppSender.fails,
     builder: (context, value, widget) {
                return Text(value.toString());
              },
  ),

The static variable WhatsAppSender.fails is a ValueNotifier. You can use ValueListenableBuilder to listen changes.

Save your session #

   await WhatsAppSender.sendTo(
         phones: [ "+391111111", "+391111111", "+391111111"],
         message: "Hello",
         savedSessionDir: "./userData"
   );

To save the session you must indicate a folder name in savedSessionDir.

If you save the session you will no longer have to scan the qr code !

Do not indicate savedSessionDir if you want to be asked to scan the qr code at each sending.

Example #

import 'package:flutter/material.dart';
import 'package:pretty_qr_code/pretty_qr_code.dart';
import 'package:whatsapp_sender/whatsapp_sender.dart';

void main() {
  runApp(
    const MaterialApp(
      home: MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.send),
        onPressed: () async {
          showDialog(
            context: context,
            builder: (context) => AlertDialog(
              content: SingleChildScrollView(
                child: Column(
                  children: [
                    ValueListenableBuilder<String>(
                      valueListenable: WhatsAppSender.qrCode,
                      builder: (context, value, widget) {
                        return value.isEmpty
                            ? const SizedBox()
                            : PrettyQr(
                                size: 300,
                                data: value,
                                roundEdges: true,
                              );
                      },
                    ),
                    ValueListenableBuilder<String>(
                      valueListenable: WhatsAppSender.status,
                      builder: (context, value, widget) {
                        return Text(value);
                      },
                    ),
                    ValueListenableBuilder<int>(
                      valueListenable: WhatsAppSender.success,
                      builder: (context, value, widget) {
                        return Text("$value success");
                      },
                    ),
                    ValueListenableBuilder<int>(
                      valueListenable: WhatsAppSender.fails,
                      builder: (context, value, widget) {
                        return Text("$value fails");
                      },
                    ),
                  ],
                ),
              ),
            ),
          );
          await WhatsAppSender.sendTo(
            phones: [
              "+391111111111",
              "+391111111111",
              "+391111111111",
            ],
            message: "Hello",
          );
        },
      ),
      appBar: AppBar(
        title: const Text("WhatsApp sender"),
      ),
      body: const Center(
        child: Text("Press send button to start the sending"),
      ),
    );
  }
}

To Do #

  • Send text message ✔️
  • Send image (coming soon!)

License #

MIT

30
likes
0
pub points
77%
popularity

Publisher

unverified uploader

WhatsApp Sender is an unofficial API for Flutter to send bulk messages in Whatsapp

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, puppeteer

More

Packages that depend on whatsapp_sender_flutter