whatsauth

package module
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 14 Imported by: 72

README

whatsauth

golang websocket package for whatsapp authentication

Usage

go get github.com/whatsauth/whatsauth

In the main pakcage

package main

import (
	"log"

	"github.com/aiteung/musik"
	"github.com/gofiber/fiber/v2/middleware/cors"
	"gitlab.com/informatics-research-center/auth-service/config"

	"github.com/whatsauth/whatsauth"

	"github.com/gofiber/fiber/v2"
	"gitlab.com/informatics-research-center/auth-service/url"
)

func main() {
	go whatsauth.RunHub()
	site := fiber.New()
	site.Use(cors.New(config.Cors))
	url.Web(site)
	log.Fatal(site.Listen(musik.Dangdut()))
}

In the URL package

package url

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/websocket/v2"
	"gitlab.com/informatics-research-center/auth-service/controller"
	"os"
)

func Web(page *fiber.App) {
	//API from user whatsapp message from iteung gowa
	page.Post("/api/whatsauth/request", controller.PostWhatsAuthRequest)                
	page.Post("/api/whatsauth/request/role", controller.PostWhatsAuthRole)

	//websocket whatsauth to serve wauthjs frontend
	page.Get("/ws/whatsauth/qr", websocket.New(controller.WsWhatsAuthQR))

}

In the controller package

package controller

import (
	"fmt"

	"github.com/aiteung/athelper"
	"gitlab.com/informatics-research-center/auth-service/model"

	"github.com/aiteung/atmodel"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/websocket/v2"
	"github.com/whatsauth/watoken"
	"github.com/whatsauth/whatsauth"
	"gitlab.com/informatics-research-center/auth-service/config"
)

func WsWhatsAuthQR(c *websocket.Conn) { //simpati unpas lama
	whatsauth.RunSocket(c, config.PublicKey, config.Usertables[:], config.Ulbimariaconn)
}

func PostWhatsAuthRequest(c *fiber.Ctx) error { //receiver whtasapp message token
	if string(c.Request().Host()) == config.Internalhost || string(c.Request().Host()) == "127.0.0.1:7777" {
		var req whatsauth.WhatsauthRequest
		var ntfbtn atmodel.NotifButton
		err := c.BodyParser(&req)
		if err != nil {
			return err
		}
		app := watoken.GetAppSubDomain(req.Uuid)
		getapptried := 0
		for (getapptried < 17) && (app == "") {
			app = watoken.GetAppSubDomain(req.Uuid)
			getapptried += getapptried
		}

		if app == "siapbaak" {
			ntfbtn = whatsauth.RunModuleLegacy(req, config.PrivateKey, config.SiapUserTables[:], config.Ulbimssqlconn)
			fmt.Println(ntfbtn)
		} else if config.CheckIsAkademik(app) {
			ntfbtn = whatsauth.RunWithUsernames(req, config.PrivateKey, config.Usertables[:], config.Ulbimariaconn)
		} else {
			ntfbtn = whatsauth.RunWithUsernames(req, config.PrivateKey, config.AptimasTables[:], config.AptimasConn)
		}
		if app == "" {
			ntfbtn.Message.Message.FooterText = ntfbtn.Message.Message.FooterText + req.Uuid
		}
		return c.JSON(ntfbtn)
	} else {
		var ws whatsauth.WhatsauthStatus
		ws.Status = string(c.Request().Host())
		return c.JSON(ws)
	}
}

func PostWhatsAuthRole(c *fiber.Ctx) error { //receiver whtasapp message token
	if string(c.Request().Host()) != config.Internalhost || string(c.Request().Host()) == "127.0.0.1:7777" {
		var ws whatsauth.WhatsauthStatus
		ws.Status = string(c.Request().Host())
		return c.JSON(ws)
	}
	req := new(whatsauth.WhatsAuthRoles)
	err := c.BodyParser(req)
	if err != nil {
		return err
	}
	var ntfbtn atmodel.NotifButton
	app := watoken.GetAppSubDomain(req.Uuid)
	if app == "siapbaak" {
		ntfbtn := whatsauth.SelectedRoles(*req, config.PrivateKey, config.SiapUserTables[:], config.Ulbimssqlconn)
		fmt.Println(ntfbtn)
	} else if config.CheckIsAkademik(app) {
		ntfbtn = whatsauth.SelectedRoles(*req, config.PrivateKey, config.Usertables[:], config.Ulbimariaconn)
	} else {
		ntfbtn = whatsauth.SelectedRoles(*req, config.PrivateKey, config.AptimasTables[:], config.AptimasConn)
	}
	fmt.Printf("\nreturn button from auth : %+q \n", ntfbtn)
	return c.JSON(ntfbtn)
}

Tagging

develop and publish new version of whatsauth

git tag v0.2.6
git push origin --tags
go list -m github.com/whatsauth/[email protected]

Environment

Setting up environment

GOPROXY=proxy.golang.org

Documentation

Index

Constants

View Source
const Keyword string = "wh4t5auth0"

Variables

View Source
var Clients = make(map[string]*websocket.Conn) // Note: although large maps with pointer-like types (e.g. strings) as keys are slow, using pointers themselves as keys is acceptable and fast
View Source
var Register = make(chan Client) // Register channel for Client Struct
View Source
var SendMesssage = make(chan Message)
View Source
var Unregister = make(chan string)

Functions

func ButtonMessageToMessage added in v0.0.90

func ButtonMessageToMessage(btm atmessage.ButtonsMessage, prefixurlapiwa string) string

func ButtonMessageWhatsauth added in v0.0.84

func ButtonMessageWhatsauth(waclient *whatsmeow.Client, Info *types.MessageInfo, Message *waProto.Message, urlwauthrole string)

func EventReadSocket added in v0.0.83

func EventReadSocket(roomId string, PublicKey string, usertables []LoginInfo, db *sql.DB)

func FilterWhatsauthButton added in v0.0.84

func FilterWhatsauthButton(Info *types.MessageInfo, Message *waProto.Message) (filter bool)

func GenerateButtonMessage added in v0.0.83

func GenerateButtonMessage(header string, content string, footer string) (btnmsg atmodel.ButtonsMessage)

func GenerateButtonMessageCustom added in v0.0.83

func GenerateButtonMessageCustom(
	uuid string,
	header string,
	content string,
	footer string,
	button []string,
) (btnmsg atmodel.ButtonsMessage)

func GetHashPasswordfromUsername added in v0.0.9

func GetHashPasswordfromUsername(username string, usertables []LoginInfo, db *sql.DB) (hashpassword string)

func GetListUsernamefromPhonenumber added in v0.0.83

func GetListUsernamefromPhonenumber(phone_number string, usertables []LoginInfo, db *sql.DB) (usernames []string)

func GetUserIdfromUsername added in v0.0.9

func GetUserIdfromUsername(username string, usertables []LoginInfo, db *sql.DB) (userid string)

func GetUsernamefromPhonenumber added in v0.0.9

func GetUsernamefromPhonenumber(phone_number string, usertables []LoginInfo, db *sql.DB) (username string)

func HandlerWhatsauth added in v0.0.84

func HandlerWhatsauth(waclient *whatsmeow.Client, Info *types.MessageInfo, Message *waProto.Message, urlwauthreq string, urlwauthrole string, prefixurlapiwa string)

func HasKeyword added in v0.0.84

func HasKeyword(Info *types.MessageInfo, Message *waProto.Message) (whmsg bool)

func HasRoleKeyword added in v0.1.92

func HasRoleKeyword(Info *types.MessageInfo, Message *waProto.Message) (whmsg bool)

func KeyGenerator added in v0.2.9

func KeyGenerator(roomId string, PublicKey string)

func MessageWhatsauth added in v0.1.92

func MessageWhatsauth(waclient *whatsmeow.Client, Info *types.MessageInfo, Message *waProto.Message, urlwauthrole string)

func RunHub added in v0.0.83

func RunHub()

func RunModule added in v0.0.83

func RunModule(waclient *whatsmeow.Client, Info *types.MessageInfo, Message *waProto.Message, urlwauthreq string, prefixurlapiwa string)

func RunModuleLegacy added in v0.0.84

func RunModuleLegacy(req WhatsauthRequest, PrivateKey string, usertables []LoginInfo, db *sql.DB) atmodel.NotifButton

func RunSocket added in v0.0.83

func RunSocket(c *websocket.Conn, PublicKey string, usertables []LoginInfo, db *sql.DB) (Id string)

func RunSocketGenerator added in v0.2.8

func RunSocketGenerator(c *websocket.Conn, PublicKey string) (Id string)

func RunWithUsernames added in v0.0.83

func RunWithUsernames(req WhatsauthRequest, PrivateKey string, usertables []LoginInfo, db *sql.DB) atmodel.NotifButton

func SelectedRoles added in v0.0.83

func SelectedRoles(
	req WhatsAuthRoles,
	PrivateKey string,
	usertables []LoginInfo,
	db *sql.DB,
) (notifbtn atmodel.NotifButton)

func SendMessageTo

func SendMessageTo(ID string, msg string) (res bool)

func SendStructTo added in v0.0.5

func SendStructTo(ID string, strc interface{}) (res bool)

func UpdatePasswordfromUsername added in v0.0.9

func UpdatePasswordfromUsername(username string, usertables []LoginInfo, db *sql.DB) (newPassword string)

Types

type Client added in v0.0.83

type Client struct {
	Id   string
	Conn *websocket.Conn

} // Register Conn socket with ID

type LoginInfo added in v0.0.7

type LoginInfo struct {
	Userid   string `json:"user_id,omitempty" bson:"user_id,omitempty"`
	Username string `json:"user_name,omitempty" bson:"user_name,omitempty"`
	Password string `json:"user_pass,omitempty" bson:"user_pass,omitempty"`
	Phone    string `json:"phone,omitempty" bson:"phone,omitempty"`
	Login    string `json:"login,omitempty" bson:"login,omitempty"`
	Uuid     string `json:"uuid,omitempty" bson:"uuid,omitempty"`
}

func GetLoginInfofromPhoneNumber added in v0.0.9

func GetLoginInfofromPhoneNumber(phonenumber string, usertables []LoginInfo, db *sql.DB) (response LoginInfo)

func GetRolesByPhonenumber added in v0.0.83

func GetRolesByPhonenumber(
	phoneNumber string,
	userRoles string,
	usertables []LoginInfo,
	db *sql.DB,
) (loginInfo LoginInfo)

type Message added in v0.0.83

type Message struct {
	Id      string
	Message string

} // To send message to Id

type WhatsAuthRoles added in v0.0.83

type WhatsAuthRoles struct {
	Uuid        string `json:"uuid,omitempty" bson:"uuid,omitempty"`
	Phonenumber string `json:"phonenumber,omitempty" bson:"phonenumber,omitempty"`
	Roles       string `json:"roles,omitempty" bson:"roles,omitempty"`
}

type Whatsauth added in v0.0.83

type Whatsauth struct {
	Uuid string `json:"uuid"`
}

type WhatsauthMessage added in v0.0.7

type WhatsauthMessage struct {
	Id      string    `json:"id,omitempty" bson:"id,omitempty"`
	Message LoginInfo `json:"message,omitempty" bson:"message,omitempty"`
}

type WhatsauthRequest added in v0.0.7

type WhatsauthRequest struct {
	Uuid        string `json:"uuid,omitempty" bson:"uuid,omitempty"`
	Phonenumber string `json:"phonenumber,omitempty" bson:"phonenumber,omitempty"`
	Delay       uint32 `json:"delay,omitempty" bson:"delay,omitempty"`
}

type WhatsauthStatus added in v0.0.7

type WhatsauthStatus struct {
	Status string `json:"status,omitempty" bson:"status,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL