This is a simple Golang Model-Controller template using Functions Framework for Go and mongodb.com as the database host. It is compatible with Google Cloud Function CI/CD deployment.
Start here: Just Fork this repo
The first thing to do is prepare a Mongo database using this template:
-
Sign up for mongodb.com and create one instance of Data Services of mongodb.
-
Go to Network Access menu > + ADD IP ADDRESS > ALLOW ACCESS FROM ANYWHERE

-
Download MongoDB Compass, connect with your mongo string URI from mongodb.com
-
Import this json into reply collection.



-
Create a profile collection, and insert this JSON document with your 30-day token and WhatsApp number.


{ "token": "v4.public.asdasfafdfsdfsdf", "phonenumber": "62881022526506", "secret": "secretkamuyangpanjangdanrumit089u08j32", "url": "https://asia-southeast2-awangga.cloudfunctions.net/logiccoffee/webhook/nomor/62881022526506", "urlapitext": "https://api.wa.my.id/api/v2/send/message/text", "urlapiimage": "https://api.wa.my.id/api/send/message/image", "urlapidoc": "https://api.wa.my.id/api/send/message/document", "urlqrlogin": "https://api.wa.my.id/api/whatsauth/request", "qrkeyword": "wh4t5auth0", "publickey": "0d6171e848ee9efe0eca37a10813d12ecc9930d6f9b11d7ea594cac48648f022", "botname": "lofe", "triggerword": "lofe", "telegramtoken": "", "telegramname": "" }
This boilerplate has several folders with different functions, such as:
- .github: GitHub Action yml configuration.
- config: all apps configuration like database, API, token.
- controller: all of the endpoints functions
- model: all of the type structs used in this app
- helper: helper folder with a list of functions only called by others file
- route: all routes URL
To get an auth in Google Cloud, you can do the following:
-
Open Cloud Shell Terminal, type this command line per line:
# Get a List of Project IDs in Your GCP Account gcloud projects list --format="value(projectId)" # Set Project ID Variable PROJECT_ID=yourprojectid # Create a service account gcloud iam service-accounts create "whatsauth" --project "${PROJECT_ID}" # Create JSON key for GOOGLE_CREDENTIALS variable in GitHub repo gcloud iam service-accounts keys create "key.json" --iam-account "whatsauth@${PROJECT_ID}.iam.gserviceaccount.com" # Read the key JSON file and copy the output, including the curl bracket, go to step 5. cat key.json # Authorize service account to act as admin in Cloud Run service gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:whatsauth@${PROJECT_ID}.iam.gserviceaccount.com --role=roles/run.admin # Authorize service account to delete artifact registry gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:whatsauth@${PROJECT_ID}.iam.gserviceaccount.com --role=roles/artifactregistry.admin # Authorize service account to deploy cloud function gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:whatsauth@${PROJECT_ID}.iam.gserviceaccount.com --role=roles/cloudfunctions.developer
-
Open Menu Cloud Build>settings, select the Service Account created by step 1, and enable Cloud Function Developer.


-
Go to the GitHub repository; in the settings, menu>secrets>action, add GOOGLE_CREDENTIALS vars with the value from the key.json file.
-
Add other Vars into the secret>action menu:
MONGOSTRING=mongodb+srv://user:pass@gocroot.wedrfs.mongodb.net/ WAQRKEYWORD=yourkeyword WEBHOOKURL=https://asia-southeast1-PROJECT_ID.cloudfunctions.net/gocroot/webhook/inbox WEBHOOKSECRET=yoursecret WAPHONENUMBER=62811111
-
Edit function name in main.yml (optional).
- Go to the WhatsAuth signup page and scan with your WhatsApp camera menu for login.
- Input the webhook URL(https://yourappname.alwaysdata.net/whatsauth/webhook) and your secret from the WEBHOOKSECRET setting environment on Always Data.

- Follow this instruction, at the end of the instruction, you will get 30 days token using this request
- Save the token into MongoDB, open iteung db, and insert this JSON document with your 30-day token and WhatsApp number.
{ "token":"v4.public.asoiduasoijfiun98erjg98egjpoikr", "phonenumber":"6281111222333" }
To continue using the WhatsAuth service, we must obtain a new token every three weeks before it expires in 30 days.
- Open Menu Cloud Scheduler. You can just search it like the screenshot.

- Click Create Job Input every 29 days; next, choose Target type HTTP, input refresh token URL from cloud function, HTTP method Get.


- Completing create schedule
If you want to upgrade apps, please delete (go.mod) and (go.sum) files first, then type the command in your terminal or cmd :
go mod init gocroot
go mod tidy
