Skip to content

This is a whatsapp bot that uses web.whatsapp to automate your messages and set reminders

Notifications You must be signed in to change notification settings

enesonus/whatsapp-bot

Repository files navigation

WhatsApp Bot for Scheduled Messages

Caution

This bot is currently not working properly due to changes in web.whatsapp and is not currently maintaned. If you want to contribute feel free to open a PR.

WhatsApp is an instant messaging application that's mostly used in mobile phones. It allows you to send a message any time of the day but you cannot schedule a message to be sent at a certain time.

This WhatsApp Bot can be used to schedule messages to be sent at a later time and you can configure it by texting yourself.

I have done this project to learn more about Kubernetes and UI testing. The ideal state could be to build a UI testing farm with Kubernetes clusters but I haven't gotten that far yet.

Architecture

At a high level, the architecture consists of a Selenium Grid running as a Deployment with a Service that the bot calls to execute actions on a Whatsapp Web browser instance. The bot itself is also deployed as a Deployment and a Service. For user's access, it also has an Ingress object that redirects the traffic to the bot.

You can learn more about the architecture in the following pages:

Getting Started

Clone the Repository

First we need to clone the repository.

git clone https://github.com/enesonus/whatsapp-bot/
cd whatsapp-bot

Create a Cluster

This section is mostly from kind documentation.

We'll use kind to create a new cluster. It requires custom configuration so that we can expose it to external traffic using Ingress NGINX.

cat <<EOF | kind create cluster --wait 5m --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP
EOF

kind cluster created

Once it's ready, install Ingress-Nginx. This will accept all the traffic coming into our virtual machine.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

Wait until it's complete.

kubectl wait --namespace ingress-nginx \
  --for=condition=ready pod \
  --selector=app.kubernetes.io/component=controller \
  --timeout=90s

Deploy

Right now, it runs only for a single phone number so you'll need to change it to your own mobile phone number.

  1. Go to cluster/manifests/whatsappbot.yaml and change 13479998877 to your phone number - the country code is included.
  2. Deploy everything into your cluster.
    kubectl apply -f cluster/manifests

You should see everything up and running when you run the following commands.

kubectl get pods
kubectl get services
kubectl get ingress

kubectl get

Access

Under Public Domain

You can set up your DNS record to point to the virtual machine that your kind cluster is running in. In order to do that, make sure you change all instances of enesonus.com with your own public domain.

Once you make the change, run kubectl apply -f cluster/manifests again.

Now, set up the DNS records for the following domains:

  • bot.<your domain>: A record pointing to your virtual machine IP address.
  • vnc.<your domain>: A record pointing to your virtual machine IP address.

Local Access

You can forward a port on the bot's Pod so that it's available in your local machine but note that this does not expose it to the public internet.

kubectl port-forward svc/whatsapp-bot 7575:7575

Go to http://127.0.0.1:7575 and you'll see the bot page.

Alternatives

You can use Cloudflare Tunnel to expose your Service to public via CloudFlare network.

Debug

In cluster/manifests/selenium.yaml, we deploy an Ingress resource so that you can connect to the Selenium to see what actions it take on its Chrome instance for better debugging.

Go to vnc.<your domain> to see what's the bot doing at any time.

About

This is a whatsapp bot that uses web.whatsapp to automate your messages and set reminders

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published