1
0
mirror of https://github.com/nikoksr/notify.git synced 2024-11-24 08:22:18 +02:00
notify/service/whatsapp
2022-09-12 08:50:15 +02:00
..
doc.go style(fmt): make fmt 2022-08-04 15:58:38 +02:00
mock_whatsappClient.go refactor(send): Add context.Context to parameter list of Send method 2021-02-18 03:33:30 +01:00
README.md refactor(send): Add context.Context to parameter list of Send method 2021-02-18 03:33:30 +01:00
whatsapp_test.go test(go): allow for parallel tests 2022-04-22 20:45:29 +02:00
whatsapp.go refactor(constructor): simplify returning service 2022-09-12 08:50:15 +02:00

WhatsApp

go.dev reference

Prerequisites

You will need a registered WhatsApp phone number to be used as source for sending WhatsApp messages.

Usage

In the current implementation, authentication is implemented using 2 ways:

  1. Scanning QR code from terminal using a registered WhatsApp device.

    • Go to WhatsApp on your device.
    • Click on the ellipsis icon (3 vertical dots) on top right, then click on "WhatsApp Web".
    • Click on the "+" icon and scan the QR code from terminal.

Refer: Login (go-whatsapp) and sigalor/whatsapp-web-reveng for more details.

  1. Providing the Session credentials explicitly.
package main

import (
        "log"

        "github.com/nikoksr/notify"
        "github.com/nikoksr/notify/service/whatsapp"
)

func main() {
        whatsappSvc, err := whatsapp.New()
        if err != nil {
                log.Fatalf("whatsapp.New() failed: %s", err.Error())
        }

        err = whatsappSvc.LoginWithQRCode()
        if err != nil {
                log.Fatalf("whatsappSvc.LoginWithQRCode() failed: %s", err.Error())
        }

        whatsappSvc.AddReceivers("Contact1")

        notifier := notify.New()
        notifier.UseServices(whatsappSvc)

        err = notifier.Send(context.Background(), "subject", "message")
        if err != nil {
                log.Fatalf("notifier.Send() failed: %s", err.Error())
        }

        log.Println("notification sent")
}