whatsapp

package
Version: v0.18.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2021 License: MIT Imports: 10 Imported by: 0

README

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")
}

Documentation

Overview

Package whatsapp provides message notification integration for WhatsApp.

Usage:

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")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service encapsulates the WhatsApp client along with internal state for storing contacts.

func New

func New() (*Service, error)

New returns a new instance of a WhatsApp notification service.

func (*Service) AddReceivers

func (s *Service) AddReceivers(contacts ...string)

AddReceivers takes WhatsApp contacts and adds them to the internal contacts list. The Send method will send a given message to all those contacts.

func (*Service) LoginWithQRCode

func (s *Service) LoginWithQRCode() error

LoginWithQRCode provides helper for authentication using QR code on terminal. Refer: https://github.com/Rhymen/go-whatsapp#login for more information.

func (*Service) LoginWithSessionCredentials

func (s *Service) LoginWithSessionCredentials(clientID, clientToken, serverToken, wid string, encKey, macKey []byte) error

LoginWithSessionCredentials provides helper for authentication using whatsapp.Session credentials.

func (*Service) Send

func (s *Service) Send(ctx context.Context, subject, message string) error

Send takes a message subject and a message body and sends them to all previously set contacts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL