Skip to content

Instantly share code, notes, and snippets.

@Natanel-Shitrit
Created November 25, 2023 02:19
Show Gist options
  • Select an option

  • Save Natanel-Shitrit/85bdb8152219adfc45f67a833b312c76 to your computer and use it in GitHub Desktop.

Select an option

Save Natanel-Shitrit/85bdb8152219adfc45f67a833b312c76 to your computer and use it in GitHub Desktop.
Schedule WhatsApp Messages (w/ Termux, Tasker-MdtestV5, crontab)

Background

The reason I made this is really stupid - basically I send alerts of various things to myself via WhatsApp Cloud API.
But in order to send messages via this API (for some stupid reason), the user must initiate the conversation. (and each conversation is 24 hours)

I'm too lazy to send a message every 24 hours to the bot - so let's automate this!

drawing

How do you even send WhatsApp messages?

I asked myself this exact question.

First, I tried to search for apps in the Google Play Store for "WhatsApp Message Schedualer"
the results? mostly privacy invading apps that read your whole WhatsApp history and sends it to some random chinese FTP...

The second option I had in mind was: "Someone must've an app and put it up on GitHub"
Yea... nothing really useful.

Then i stumbled upon some random repository - Tasker-MdtestV5
Truely god-sent moment, an easy interface for sending WhatsApp message (or really anything you want to do in WhatsApp) via Termux!!

This project uses a different project called whatsmeow, which is a Go library for the WhatsApp web multidevice API.,
An awesome project that reveresed engineered the WhatApp Web protocol and exports it as golang functions 😀

After a really easy setup (< 3 minutes) I was able to send messages! (Setup via Termux)

Example:

./mdtest --mode send send {NUMBER}@s.whatsapp.net Hello

why s.whatsapp.net? read here

Okay - finished the hard part, now I need to somehow run a command periodically.

Small Google search and we are there: Crontab On Termux

Installed cronie, and added this crontab:

0 0 * * * cd ~/whatsmeow5/mdtest && ./mdtest --mode send send {NUMBER}@s.whatsapp.net "Initiating new conversation" 2>&1 >~/whatsapp.log

And now we have a scheduled WhatsApp message!

10 seconds saved every day!

@chokorad
Copy link

chokorad commented Dec 7, 2023

Looks great, I've been able to send messages, but, can't figure out how to schedule messages, for example it's 6 am, and I want to send a message at 3pm automatically, no interaction, what would be the command? Can it be done through Tasker alone or you need termux!? Thanks!

@Natanel-Shitrit
Copy link
Author

Looks great, I've been able to send messages, but, can't figure out how to schedule messages, for example it's 6 am, and I want to send a message at 3pm automatically, no interaction, what would be the command? Can it be done through Tasker alone or you need termux!? Thanks!

You could set a cron like I've demonstrated in the gist.
If you want to use tasker only (idk if Tasker requires Termux), check out this Reddit post (I haven't used tasker so I can't really help you)

@chokorad
Copy link

chokorad commented Dec 7, 2023

Oh, but what would be the variables for setting up time with cron?

@Natanel-Shitrit
Copy link
Author

Natanel-Shitrit commented Dec 7, 2023

Oh, but what would be the variables for setting up time with cron?

Well, follow the steps in the gist and just change the time of the cron.

You can change the time of the cron by changing it from "0 0 * * *" (Which means at 00:00 every day)

Cron time helper: https://crontab.guru/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment