Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Trying to use whatsmeow as background service for WhatsApp

155 views
Skip to first unread message

Ted

unread,
Sep 3, 2024, 1:20:18 AM9/3/24
to comp.mobile.nokia.8110
Hi KaiOS hackers,

Just would like to share some ideas for another hobby project.

I am thinking about using whatsmeow (https://github.com/tulir/whatsmeow) as a background service for WhatsApp. It is written in Go, so a quick and easy POC I can think, if it works, will be to populate received messages into a channel, then consume through web service that can be called from a frontend webapp.

I am still relatively new to Linux so it is quick challenging...But the example shown in this link: https://pkg.go.dev/go.mau.fi/whatsmeow#example-package now works on my Cat B35.

What I did:
  1. Create a root for SSH
    • Create "passwd", "shadow", "group", "shells" into a writable location, then create symlinks in /system/etc/. (mine: /data/etc/)
    • Use busybox adduser to create "root", define a home directory (mine: /data) and default shell (/system/bin/sh)
    • Use busybox chpasswd to update password for the "root" account
    • Go into "passwd", change the uid to 0
    • Go into "shells" and add "/system/bin/sh"
  2. Put a statically linked Dropbear server into the filesystem and create the dropbear directory as required.
  3. Setup a runit service to run the Dropbear server on startup. Added a userinit script call into "/system/bin/b2g.sh" to start the SSH server by "exec busybox chpst -u root busybox runsv {the sv folder} &"
    • Forgot the "&" the first time. It held up the booting thread and the phone never loads pass the Cat splash screen. Be very careful when testing on devices that has no EDL support...
  4. Setup DNS and CA certs
    • Added "resolv.conf" and "nsswitch.conf" into my /data/etc/, then symlinks in /system/etc/.
      • In resolv.conf, the normal "nameserver 9.9.9.9........", with only one space after "nameserver".
      • In nsswitch.conf it is "hosts: files dns compat".
    • Downloaded the CA certs from https://android.googlesource.com/platform/system/ca-certificates/+/refs/heads/main/files/, then put them into /system/etc/ssl/certs/.
      • mkdir -p /system/etc/ssl/certs/ is needed.
      • chmod -R 644 certs/
  5. After that, just put a statically linked whatsmeow (it needs CGO_ENABLED=1) into a writable location and run it.
So far it can show the QR code for linking device, but I have not yet created a new WhatsApp account to test it out. I think I need to find a way to "htop" it and see if the performance is okay, then move on to write a web service method for delivering received messages and a simple webapp to consume them.

Ted

unread,
Sep 3, 2024, 1:43:48 PM9/3/24
to comp.mobile.nokia.8110
Just a very quick update.

Updated a bit the Go program to expose a web method for the browser to consume the messages. Yes, didn't build a webapp because I guess the output is easy enough to be handled by the browser. Result is like below:

1. Stdout from the Go program. White boxes are my phone number so please ignore. Sent one message - "Hello KaiOS!".
kaios_1.png

2. Viewing the message from the browser, in JSON format.
phone.png

3. busybox top
kaios_2.png

And the main.go is in the attachment. Simply added a slice for storing unread messages and HTTP web method on top of the whatsmeow example.
main.go

Ted

unread,
Sep 4, 2024, 5:54:51 AM9/4/24
to comp.mobile.nokia.8110
Looked a bit more into the "575m" VSZ - seems much more is reserved than used.

I guess I will setup a runit service for the app, then let it run and see if it can perform normally throughout the day. I can also build a frontend to test sending and receiving text messages, but may be after seeing some progress on my another hobby project that got stuck for a little bit...

memory.png

Ted

unread,
Sep 10, 2024, 4:11:54 PM9/10/24
to comp.mobile.nokia.8110
Just some updates on this experiment.

I have updated the program to use websocket for sending and receiving messages in real time, then set it up as a service and ran it for 2 days. Built a quick-and-dirty webapp to test the backend as well. It is not too bad - didn't feel any unusual lag and it consumed just 6-8% more battery per day, but I didn't have a lot of WhatsApp messages so didn't open the webapp frequently.

To be honest, putting the whatsmeow backend onto a cloud server makes more sense, but putting it inside the phone is technically possible. I think this satisfied my curiosity.

Here is a video in case you are interested in seeing if there is any delay in sending/receiving messages:

messages.jpg
Reply all
Reply to author
Forward
0 new messages