[Tasker Tips & Tricks] Lord Sithek:
EDIT: This method can be considered deprecated as now there is much easier and more effective solution thanks to the great u/HunterXProgrammer from Reddit. Check it here:

https://www.reddit.com/r/tasker/comments/11wi2om

OLD SOLUTION:

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 44777666555@s.whatsapp.net "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 44777666555@s.whatsapp.net /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 44777666555-5544433322@g.us "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 44777666555@s.whatsapp.net "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 44777666555@s.whatsapp.net /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 44777666555-5544433322@g.us "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.