A new way to automate sending Whatsapp messages via Tasker

Search This thread

Lord Sithek

Senior Member
Dec 19, 2018
1,226
625
Xiaomi Redmi Note 4
Huawei Watch 2
For a long long time I've been searching for a way to automate sending Whatsapp messages via Tasker. The previous method with inserting text into database doesn't work with newer Whatsapp versions and so far nobody was able/willing to fix it. But now, thanks to the whatsmeow library and the undeserved kindness of u/Black616Angel from Reddit, we finally have a working solution!

ROOT IS NOT REQUIRED, although it certainly makes things much easier.


REQUIREMENTS:

(1)
Tasker

(2) Termux

(3) [FOR ROOTED USERS] A file manager with root access. I recommend MiXplorer.

(4) [FOR NON-ROOTED USERS] Termux:Tasker plugin (detailed configuration description here)

(5) One free place in Whatsapp multidevice feature

(6) A second device from which you will scan the QR code


INITIAL TERMUX SETUP:

(1)
Open Termux, run apt update && apt upgrade and approve all when asked

(2) Run pkg install git

(3) Run git clone https://github.com/tulir/whatsmeow (this will clone the needed repository from Github to your device)

(4) Run pkg install golang and approve all when asked (it will download necessary tools to your device, around 800 MB)


PROCEDURE FOR ROOTED USERS:

(1)
Open MiXplorer and go to /data/data/com.termux/files/home/whatsmeow/mdtest directory. Select main.go file and open it as text (in MiXplorer: OPEN AS... > Text > Text Editor). Find the line no. 114 (or very close) which should contain these signs: }(). Make a new line below and paste the following text there:

args := os.Args[1:] if len(args) > 0 { handleCmd(strings.ToLower(args[0]), args[1:]) return }

Save the file and exit.

(2) Go back to Termux and enter cd whatsmeow/mdtest. Run go build command. Wait for the operation to be finished.

(3) Run ./mdtest command. If all has been done correct so far, you should see a QR code. Make a screenshot of it and send it to your secondary device. Then open Whatsapp on your main device, tap three dots in the right-upper corner, select Linked devices, select LINK A DEVICE and scan the QR code from your second device. You should see a new device linked, described as whatsmeow.

[Please note that the after a short while a new QR code is generated and the previous one gets invalid, so make this operation quickly.]

Go back to Termux. Exit the whatsmeow program by selecting CTRL on the Termux panel and tapping "c" on the keyboard.

(4) Open Tasker, create a task (name it as you wish) and add Run Shell action. In the Command field put the following text:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net <your_message>

Edit above text according to your information. Example:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send [email protected] "My test message"

[If your message contains multiple lines, don't forget to put " sign at the beginning and the end of the message.]

You can also send images instead of just a text (optionally with a caption). Open Tasker, create a task (name it as you wish) and add Run Shell action. In the Command field put the following text:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net </exact/path/of/your/image.jpg> <[optional] any caption>

Edit above text according to your information. Example:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg [email protected] /storage/emulated/0/image_example.jpg "My caption"

Mark Use root box. Go back to the task and run it by tapping the Play icon. If the message has been delivered to your recepient, you succeeded!

(5) If you want to send a message to a group instead of a single contact, you will need a precise jid ODE]number of this group. You can get it this way:

Make a test task in Tasker. Create a Shortcut action. Tap on the Magnifying glass icon and select Whatsapp: Whatsapp field, then select your group. In the command line of the Tasker action a string of signs will appear, among others the jid number of your group. It is located between jid= and %40.

Make another task (name it as you wish) with the Run Shell action. In the Command field put the following text:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send <jid_number_of_your_group>@g.us <your_message>

Edit above text according to your information. Example:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send [email protected] "My test message"

You can also send images to your groups instead of just a text. To do that, follow the pattern for the individual contact, but use the jid number of the group.

Mark Use root box. Go back to the task and run it by tapping the Play icon. If the message has been delivered to your recepient, you succeeded!

Now you can link your task to any profile as well as create additional tasks in order to automatically send different messages. Enjoy!


PROCEDURE FOR NON-ROOTED USERS:

(1)
In Termux, enter cd whatsmeow/mdtest command. Then enter nano main.go command. The file editor will open. Find this block of text:

c := make(chan os.Signal) input := make(chan string) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { defer close(input) scan := bufio.NewScanner(os.Stdin) for scan.Scan() { line := strings.TrimSpace(scan.Text()) if len(line) > 0 { input <- line } } }()

Below this block of text make a new line and paste the following text there:

args := os.Args[1:] if len(args) > 0 { handleCmd(strings.ToLower(args[0]), args[1:]) return }

Save the file by selecting CTRL on the Termux panel and tapping "o" on the keyboard. Confirm by tapping ENTER. Exit the file by selecting CTRL on the Termux panel and tapping "x" on the keyboard.

(2) Make sure you are in the ~/whatsmeow/mdtest directory. Then run go build command. Wait for the operation to be finished.

(3) Run ./mdtest command. If all has been done correctly so far, you should see a QR code. Make a screenshot of it and send it to your secondary device. Then open Whatsapp on your main device, tap three dots in the right-upper corner, select Linked devices, select LINK A DEVICE and scan the QR code from your second device. You should see a new device linked, described as whatsmeow.

[Please note that the after a short while a new QR code is generated and the previous one gets invalid, so make this operation quickly.]

(4) Go back to Termux. Exit the whatsmeow program by selecting CTRL on the Termux panel and tapping "c" on the keyboard. You should return to the ~/whatsmeow/mdtest directory. Go back to the main directory by entering cd - command.

(5) Setup Tasker:Termux plugin. In Termux, enter the following commands:

$ mkdir -p /data/data/com.termux/files/home/.termux/tasker $ chmod 700 -R /data/data/com.termux/files/home/.termux

Now, you have to grant Tasker the permission to run commands in Termux environment. You can do this in two ways:

- grant the permission manually in the device settings. Look at:

Android Settings > Apps > Tasker > Permissions > Additional permissions > Run commands in Termux environment

[The exact place of this permission may vary depending on the device model and software.]

- run the following commands on PC via Android Debug Bridge (ADB):

$ adb shell $ pm grant net.dinglisch.android.taskerm com.termux.permission.RUN_COMMAND

[We assume you know how to use ADB. If not, please consult this page.]

(6) Go back to Termux. Enter cd .termux/tasker command. Make a new .txt file (name it as you wish) by entering nano <name_of_your_file>.txt command. In the editor, put the following text inside:

cd whatsmeow/mdtest ./mdtest send <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net <your_message>

Edit above text according to your information. Example:

cd whatsmeow/mdtest ./mdtest send [email protected] "My test message"

[If your message contains multiple lines, don't forget to put " sign at the beginning and the end of the message.]

You can also send images instead of just a text (optionally with a caption). In Termux, enter cd .termux/tasker command. Make a new .txt file (name it as you wish) by entering nano <name_of_your_file>.txt command. In the editor, put the following text inside:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net </exact/path/of/your/image.jpg> <[optional] any caption>

Edit above text according to your information. Example:

cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg [email protected] /storage/emulated/0/image_example.jpg "My caption"

Save the file by selecting CTRL on the Termux panel and tapping "o" on the keyboard. Confirm by tapping ENTER. Exit the file by selecting CTRL on the Termux panel and tapping "x" on the keyboard.

(7) If you want to send a message to a group instead of a single contact, you will need the precise jid number of this group. You can get it this way:

Make a test task in Tasker. Create a Shortcut action. Tap on the Magnifying glass icon and select Whatsapp: Whatsapp field, then select your group. In the command line of the Tasker action a string of signs will appear, among others the jid number of your group. It is located between jid= and %40.

In Termux, enter cd .termux/tasker command. Make a new .txt file (name it as you wish) by entering nano <name_of_your_file>.txt command. In the editor, put the following text inside:

cd whatsmeow/mdtest ./mdtest send <jid_number_of_your_group>@g.us <your_message>

Edit above text according to your information. Example:

cd whatsmeow/mdtest ./mdtest send [email protected] "My test message"

You can also send images to your groups instead of just a text. To do that, follow the pattern for the individual contact, but use the jid number of the group.

Save the file by selecting CTRL on the Termux panel and tapping "o" on the keyboard. Confirm by tapping ENTER. Exit the file by selecting CTRL on the Termux panel and tapping "x" on the keyboard.

(8) Test your setup. Open Tasker and create a task with Plugin > Termux:Tasker action. Go to Configuration and in the Executable field at the top start typing the name of the file you have created (the full name should be shown as soon as you start typing). Select the file, then click on Save icon. Go back to the task and run it by tapping the Play icon. If the message has been delivered to your recepient, you succeeded!

Now you can link your task to any profile as well as create additional files in the ~/.termux/tasker directory in order to automatically send different messages. Enjoy!

PS. Credits go to whatsmeow creators as well as u/Black616Angel from Reddit who contributed massively to this method and without his help it wouldn't be possible at all. Check this Reddit thread for the reference.
 
Last edited:
  • Like
Reactions: eeeemc

BinkXDA

Senior Member
Mar 1, 2012
355
117
Wow! What a write-up! Amazingly painful way just to send a message via WhatsApp. I really wish these messaging providers made things more open.
 

Lord Sithek

Senior Member
Dec 19, 2018
1,226
625
Xiaomi Redmi Note 4
Huawei Watch 2
Wow! What a write-up! Amazingly painful way just to send a message via WhatsApp. I really wish these messaging providers made things more open.
There are many autoresponders available on the market, INITIATING a message is difficult because Whatsapp doesn't provide API. This way isn't a simplest one, but at least it works with screen off using web interface.
 

westenlive

Senior Member
Feb 2, 2010
235
17
There are many autoresponders available on the market, INITIATING a message is difficult because Whatsapp doesn't provide API. This way isn't a simplest one, but at least it works with screen off using web interface.
You finally managed to find a system to be able to send messages using Tasker

I need to ask you a question.

When I send messages with this system the person receiving cannot see the text correctly.

A warning comes out that says so:
Screenshot_2022-10-06-11-32-16-43.jpg




how can this problem be solved?


Thank you very much
 

Lord Sithek

Senior Member
Dec 19, 2018
1,226
625
Xiaomi Redmi Note 4
Huawei Watch 2
You finally managed to find a system to be able to send messages using Tasker

I need to ask you a question.

When I send messages with this system the person receiving cannot see the text correctly.

A warning comes out that says so:
View attachment 5728319



how can this problem be solved?


Thank you very much
I've seen that before, but honestly I have no idea why is this happening... Maybe unlinking and linking whatsmeow again would help or recreating Tasker action
 

Lord Sithek

Senior Member
Dec 19, 2018
1,226
625
Xiaomi Redmi Note 4
Huawei Watch 2

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    For a long long time I've been searching for a way to automate sending Whatsapp messages via Tasker. The previous method with inserting text into database doesn't work with newer Whatsapp versions and so far nobody was able/willing to fix it. But now, thanks to the whatsmeow library and the undeserved kindness of u/Black616Angel from Reddit, we finally have a working solution!

    ROOT IS NOT REQUIRED, although it certainly makes things much easier.


    REQUIREMENTS:

    (1)
    Tasker

    (2) Termux

    (3) [FOR ROOTED USERS] A file manager with root access. I recommend MiXplorer.

    (4) [FOR NON-ROOTED USERS] Termux:Tasker plugin (detailed configuration description here)

    (5) One free place in Whatsapp multidevice feature

    (6) A second device from which you will scan the QR code


    INITIAL TERMUX SETUP:

    (1)
    Open Termux, run apt update && apt upgrade and approve all when asked

    (2) Run pkg install git

    (3) Run git clone https://github.com/tulir/whatsmeow (this will clone the needed repository from Github to your device)

    (4) Run pkg install golang and approve all when asked (it will download necessary tools to your device, around 800 MB)


    PROCEDURE FOR ROOTED USERS:

    (1)
    Open MiXplorer and go to /data/data/com.termux/files/home/whatsmeow/mdtest directory. Select main.go file and open it as text (in MiXplorer: OPEN AS... > Text > Text Editor). Find the line no. 114 (or very close) which should contain these signs: }(). Make a new line below and paste the following text there:

    args := os.Args[1:] if len(args) > 0 { handleCmd(strings.ToLower(args[0]), args[1:]) return }

    Save the file and exit.

    (2) Go back to Termux and enter cd whatsmeow/mdtest. Run go build command. Wait for the operation to be finished.

    (3) Run ./mdtest command. If all has been done correct so far, you should see a QR code. Make a screenshot of it and send it to your secondary device. Then open Whatsapp on your main device, tap three dots in the right-upper corner, select Linked devices, select LINK A DEVICE and scan the QR code from your second device. You should see a new device linked, described as whatsmeow.

    [Please note that the after a short while a new QR code is generated and the previous one gets invalid, so make this operation quickly.]

    Go back to Termux. Exit the whatsmeow program by selecting CTRL on the Termux panel and tapping "c" on the keyboard.

    (4) Open Tasker, create a task (name it as you wish) and add Run Shell action. In the Command field put the following text:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net <your_message>

    Edit above text according to your information. Example:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send [email protected] "My test message"

    [If your message contains multiple lines, don't forget to put " sign at the beginning and the end of the message.]

    You can also send images instead of just a text (optionally with a caption). Open Tasker, create a task (name it as you wish) and add Run Shell action. In the Command field put the following text:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net </exact/path/of/your/image.jpg> <[optional] any caption>

    Edit above text according to your information. Example:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg [email protected] /storage/emulated/0/image_example.jpg "My caption"

    Mark Use root box. Go back to the task and run it by tapping the Play icon. If the message has been delivered to your recepient, you succeeded!

    (5) If you want to send a message to a group instead of a single contact, you will need a precise jid ODE]number of this group. You can get it this way:

    Make a test task in Tasker. Create a Shortcut action. Tap on the Magnifying glass icon and select Whatsapp: Whatsapp field, then select your group. In the command line of the Tasker action a string of signs will appear, among others the jid number of your group. It is located between jid= and %40.

    Make another task (name it as you wish) with the Run Shell action. In the Command field put the following text:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send <jid_number_of_your_group>@g.us <your_message>

    Edit above text according to your information. Example:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest send [email protected] "My test message"

    You can also send images to your groups instead of just a text. To do that, follow the pattern for the individual contact, but use the jid number of the group.

    Mark Use root box. Go back to the task and run it by tapping the Play icon. If the message has been delivered to your recepient, you succeeded!

    Now you can link your task to any profile as well as create additional tasks in order to automatically send different messages. Enjoy!


    PROCEDURE FOR NON-ROOTED USERS:

    (1)
    In Termux, enter cd whatsmeow/mdtest command. Then enter nano main.go command. The file editor will open. Find this block of text:

    c := make(chan os.Signal) input := make(chan string) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { defer close(input) scan := bufio.NewScanner(os.Stdin) for scan.Scan() { line := strings.TrimSpace(scan.Text()) if len(line) > 0 { input <- line } } }()

    Below this block of text make a new line and paste the following text there:

    args := os.Args[1:] if len(args) > 0 { handleCmd(strings.ToLower(args[0]), args[1:]) return }

    Save the file by selecting CTRL on the Termux panel and tapping "o" on the keyboard. Confirm by tapping ENTER. Exit the file by selecting CTRL on the Termux panel and tapping "x" on the keyboard.

    (2) Make sure you are in the ~/whatsmeow/mdtest directory. Then run go build command. Wait for the operation to be finished.

    (3) Run ./mdtest command. If all has been done correctly so far, you should see a QR code. Make a screenshot of it and send it to your secondary device. Then open Whatsapp on your main device, tap three dots in the right-upper corner, select Linked devices, select LINK A DEVICE and scan the QR code from your second device. You should see a new device linked, described as whatsmeow.

    [Please note that the after a short while a new QR code is generated and the previous one gets invalid, so make this operation quickly.]

    (4) Go back to Termux. Exit the whatsmeow program by selecting CTRL on the Termux panel and tapping "c" on the keyboard. You should return to the ~/whatsmeow/mdtest directory. Go back to the main directory by entering cd - command.

    (5) Setup Tasker:Termux plugin. In Termux, enter the following commands:

    $ mkdir -p /data/data/com.termux/files/home/.termux/tasker $ chmod 700 -R /data/data/com.termux/files/home/.termux

    Now, you have to grant Tasker the permission to run commands in Termux environment. You can do this in two ways:

    - grant the permission manually in the device settings. Look at:

    Android Settings > Apps > Tasker > Permissions > Additional permissions > Run commands in Termux environment

    [The exact place of this permission may vary depending on the device model and software.]

    - run the following commands on PC via Android Debug Bridge (ADB):

    $ adb shell $ pm grant net.dinglisch.android.taskerm com.termux.permission.RUN_COMMAND

    [We assume you know how to use ADB. If not, please consult this page.]

    (6) Go back to Termux. Enter cd .termux/tasker command. Make a new .txt file (name it as you wish) by entering nano <name_of_your_file>.txt command. In the editor, put the following text inside:

    cd whatsmeow/mdtest ./mdtest send <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net <your_message>

    Edit above text according to your information. Example:

    cd whatsmeow/mdtest ./mdtest send [email protected] "My test message"

    [If your message contains multiple lines, don't forget to put " sign at the beginning and the end of the message.]

    You can also send images instead of just a text (optionally with a caption). In Termux, enter cd .termux/tasker command. Make a new .txt file (name it as you wish) by entering nano <name_of_your_file>.txt command. In the editor, put the following text inside:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg <receipient_number_preceded_by_a_country_calling_code_without_"+"_sign">@s.whatsapp.net </exact/path/of/your/image.jpg> <[optional] any caption>

    Edit above text according to your information. Example:

    cd /data/data/com.termux/files/home/whatsmeow/mdtest && ./mdtest sendimg [email protected] /storage/emulated/0/image_example.jpg "My caption"

    Save the file by selecting CTRL on the Termux panel and tapping "o" on the keyboard. Confirm by tapping ENTER. Exit the file by selecting CTRL on the Termux panel and tapping "x" on the keyboard.

    (7) If you want to send a message to a group instead of a single contact, you will need the precise jid number of this group. You can get it this way:

    Make a test task in Tasker. Create a Shortcut action. Tap on the Magnifying glass icon and select Whatsapp: Whatsapp field, then select your group. In the command line of the Tasker action a string of signs will appear, among others the jid number of your group. It is located between jid= and %40.

    In Termux, enter cd .termux/tasker command. Make a new .txt file (name it as you wish) by entering nano <name_of_your_file>.txt command. In the editor, put the following text inside:

    cd whatsmeow/mdtest ./mdtest send <jid_number_of_your_group>@g.us <your_message>

    Edit above text according to your information. Example:

    cd whatsmeow/mdtest ./mdtest send [email protected] "My test message"

    You can also send images to your groups instead of just a text. To do that, follow the pattern for the individual contact, but use the jid number of the group.

    Save the file by selecting CTRL on the Termux panel and tapping "o" on the keyboard. Confirm by tapping ENTER. Exit the file by selecting CTRL on the Termux panel and tapping "x" on the keyboard.

    (8) Test your setup. Open Tasker and create a task with Plugin > Termux:Tasker action. Go to Configuration and in the Executable field at the top start typing the name of the file you have created (the full name should be shown as soon as you start typing). Select the file, then click on Save icon. Go back to the task and run it by tapping the Play icon. If the message has been delivered to your recepient, you succeeded!

    Now you can link your task to any profile as well as create additional files in the ~/.termux/tasker directory in order to automatically send different messages. Enjoy!

    PS. Credits go to whatsmeow creators as well as u/Black616Angel from Reddit who contributed massively to this method and without his help it wouldn't be possible at all. Check this Reddit thread for the reference.
    1
    I've seen that before, but honestly I have no idea why is this happening... Maybe unlinking and linking whatsmeow again would help or recreating Tasker action
    ephemeral messages is the problem.
    if they are enabled by this problem, by disabling ephemeral messages the problem is not there

    cmq thanks for this great tool.