wawebhook

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IncomingMessage = "INCOMING_MESSAGE"
	OutgoingMessage = "OUTGOING_MESSAGE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BotClientList

type BotClientList map[string]*WaBot

BotClientList defines the variable to store WaBot objects

type MessagePayload added in v0.0.10

type MessagePayload struct {
	From          string `json:"from"`
	To            string `json:"to"`
	Message       string `json:"message,omitempty"`
	ImageFileName string `json:"image_filename,omitempty"`
	ImageCaption  string `json:"image_caption,omitempty"`
}

func (*MessagePayload) Sanitize added in v0.0.10

func (p *MessagePayload) Sanitize()

Sanitize sanitizes message payload

func (*MessagePayload) Validate added in v0.0.10

func (p *MessagePayload) Validate() error

Validate validates message payload

type ReplyMessage

type ReplyMessage struct {
	Message       string
	WithImage     bool
	ImageFileName string
}

type WaBot

type WaBot struct {
	Client         *whatsmeow.Client
	Log            *logger.Logger
	HttpClient     *http.Client
	EventHandlerID uint32
	Phone          string
	WebhookUrl     string
	ImageDir       string
	EchoMsg        bool
	WHookEnabled   bool
}

WaBot defines the bot client

func LoginExistingWASession

func LoginExistingWASession(httpClient *http.Client, webhookUrl, imageDir string, container *sqlstore.Container,
	log *logger.Logger, jidStr, phone string, echoMsg, wHookEnabled bool) (*WaBot, error)

LoginExistingWASession logins with an existing session on the database

func NewWhatsappClient

func NewWhatsappClient(httpClient *http.Client, webhookUrl, imageDir string, container *sqlstore.Container, log *logger.Logger,
	phone, fileDir string, echoMsg, wHookEnabled bool, printTerminal bool) (*WaBot, error)

NewWhatsappClient initializes Whatsapp client

func (*WaBot) Register

func (wb *WaBot) Register()

Register registers a new event handler

func (*WaBot) SendImgMsg added in v0.0.10

func (wb *WaBot) SendImgMsg(recipient types.JID, uploadedImg *whatsmeow.UploadResponse, imgCaption, contentType string,
	fileLength uint64) error

SendImgMsg sends image-based message to designated whatsapp number

func (*WaBot) SendMsg

func (wb *WaBot) SendMsg(recipient types.JID, msg string) error

SendMsg sends message to designated whatsapp number

func (*WaBot) UploadImgToWhatsapp added in v0.0.10

func (wb *WaBot) UploadImgToWhatsapp(imgPath string) (*[]byte, *whatsmeow.UploadResponse, error)

UploadImgToWhatsapp uploads the prepared image to Whatsapp server

func (*WaBot) ValidateAndGetRecipient

func (wb *WaBot) ValidateAndGetRecipient(phone string, ignoreInContactList bool) (*types.JID, error)

ValidateAndGetRecipient validates the phone number

type WaManager

type WaManager struct {
	Container *sqlstore.Container
	Log       *logger.Logger
}

WaManager defines the whatsapp container

func NewContainer

func NewContainer(dbName string, log *logger.Logger) (*WaManager, error)

NewContainer builds whatsapp Container

type WebhookBody

type WebhookBody struct {
	PhoneOwner   string `json:"phone_owner"`
	EventType    string `json:"event_type"`
	MsgId        string `json:"msg_id"`
	MsgType      string `json:"msg_type"`
	Phone        string `json:"phone"`
	Name         string `json:"name"`
	Message      string `json:"message"`
	TargetJID    string `json:"target_jid"`
	TargetDevice string `json:"target_device"`
	Timestamp    string `json:"timestamp"`
}

Jump to

Keyboard shortcuts

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