hypersender

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Hypersender Logo

Go Reference Latest Stable Version Go Report Card License

Introduction

The official Go SDK for the Hypersender WhatsApp API, SMS API, and OTP API. Send WhatsApp messages from Golang, send SMS from your own Android phone, and verify users with one-time codes. No dependencies beyond the standard library.

Installation

You can install the package with go get (Go 1.24+):

go get github.com/hypersender/hypersender-go
import "github.com/hypersender/hypersender-go"

client := hypersender.NewClient() // reads HYPERSENDER_WHATSAPP_API_KEY and HYPERSENDER_WHATSAPP_INSTANCE_ID
res, err := client.WhatsApp.SendText(ctx, "201234567890@c.us", "Hello from Go!", nil)

Official Documentation

You can find the official documentation at Hypersender Go SDK Documentation, and the full API reference on pkg.go.dev.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Documentation

Overview

Package hypersender is the official Go client for the Hypersender WhatsApp API, SMS API, and OTP API.

client := hypersender.NewClient() // reads HYPERSENDER_* environment variables
res, err := client.WhatsApp.SendText(ctx, "201234567890@c.us", "Hello from Go!", nil)

Every method takes a context, sends one request, and returns the API's JSON response as a Result (or []Result for list endpoints). Failed requests return an *Error with the HTTP status code and the API's message.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/hypersender/hypersender-go"
)

func main() {
	// Reads HYPERSENDER_WHATSAPP_API_KEY and HYPERSENDER_WHATSAPP_INSTANCE_ID.
	client := hypersender.NewClient()

	res, err := client.WhatsApp.SendText(context.Background(), "201234567890@c.us", "Hello from Go!", nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res["queued_request_uuid"])
}

Index

Examples

Constants

View Source
const DefaultBaseURL = "https://app.hypersender.com/api"

DefaultBaseURL is the Hypersender API base URL.

View Source
const Version = "1.0.0"

Version is the SDK version, sent in the User-Agent header.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool returns a pointer to v, for optional boolean fields where false must be sent explicitly.

Types

type Client

type Client struct {
	WhatsApp   *WhatsAppService
	SMS        *SMSService
	OTP        *OTPService
	Enterprise *EnterpriseService
}

Client is a Hypersender API client. Create one with NewClient and reuse it; it is safe for concurrent use.

func NewClient

func NewClient(opts ...Option) *Client

NewClient returns a client configured from the environment and the given options. Options override environment variables.

Example
package main

import (
	"github.com/hypersender/hypersender-go"
)

func main() {
	client := hypersender.NewClient(
		hypersender.WithWhatsApp("your-api-key", "your-instance-id"),
		hypersender.WithSMS("your-sms-api-key", "your-sms-instance-id"),
	)
	_ = client
}

type ContactCard

type ContactCard struct {
	FullName     string `json:"fullName,omitempty"`
	PhoneNumber  string `json:"phoneNumber,omitempty"`
	Organization string `json:"organization,omitempty"`
	WhatsAppID   string `json:"whatsappId,omitempty"`
	VCard        string `json:"vcard,omitempty"` // a raw vCard instead of the fields above
}

ContactCard is a contact to share with SendContactCard.

type ContactsService

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

ContactsService looks up and saves WhatsApp contacts. Use it as client.WhatsApp.Contacts.

func (*ContactsService) CheckContactExists

func (c *ContactsService) CheckContactExists(ctx context.Context, phone string) (Result, error)

CheckContactExists checks if a phone number has WhatsApp. phone has the country code, without + or spaces, e.g. "201234567890". The result has numberExists and chatId.

Example
package main

import (
	"context"
	"log"

	"github.com/hypersender/hypersender-go"
)

func main() {
	client := hypersender.NewClient()
	ctx := context.Background()

	res, err := client.WhatsApp.Contacts.CheckContactExists(ctx, "201234567890")
	if err != nil {
		log.Fatal(err)
	}
	if res["numberExists"] == true {
		client.WhatsApp.SendText(ctx, res["chatId"].(string), "Welcome!", nil)
	}
}

func (*ContactsService) GetAllContacts

func (c *ContactsService) GetAllContacts(ctx context.Context, opts *GetAllContactsOptions) (Result, error)

GetAllContacts lists the instance's contacts.

func (*ContactsService) GetAllKnownLIDs

func (c *ContactsService) GetAllKnownLIDs(ctx context.Context, opts *GetAllKnownLIDsOptions) ([]Result, error)

GetAllKnownLIDs lists the LID to phone number mappings the instance knows.

func (*ContactsService) GetContact

func (c *ContactsService) GetContact(ctx context.Context, chatID string) (Result, error)

GetContact returns a contact by phone number or chat ID ("123@c.us" or "123@lid").

func (*ContactsService) GetLIDByPhoneNumber

func (c *ContactsService) GetLIDByPhoneNumber(ctx context.Context, phoneNumber string) (Result, error)

GetLIDByPhoneNumber finds the LID linked to a phone number ("3333333@c.us" or "3333333").

func (*ContactsService) GetLIDsCount

func (c *ContactsService) GetLIDsCount(ctx context.Context) (Result, error)

GetLIDsCount returns how many LID mappings the instance knows.

func (*ContactsService) GetPhoneNumberByLID

func (c *ContactsService) GetPhoneNumberByLID(ctx context.Context, lid string) (Result, error)

GetPhoneNumberByLID resolves a LID ("1111111@lid") to its phone number chat ID.

func (*ContactsService) GetProfilePicture

func (c *ContactsService) GetProfilePicture(ctx context.Context, chatID string) (Result, error)

GetProfilePicture returns the URL of a contact's WhatsApp profile picture.

func (*ContactsService) UpsertContact

func (c *ContactsService) UpsertContact(ctx context.Context, chatID, firstName string, opts *UpsertContactOptions) (Result, error)

UpsertContact creates a contact, or updates its name if it already exists.

type CreateInstanceOptions

type CreateInstanceOptions struct {
	WebhookURL string `json:"webhook_url,omitempty"` // an https URL
}

CreateInstanceOptions are the optional fields for CreateInstance.

type EnterpriseService

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

EnterpriseService manages WhatsApp instances on an Enterprise account. Use it as client.Enterprise. The instance ID is passed on each call instead of being set on the client.

func (*EnterpriseService) CreateInstance

func (e *EnterpriseService) CreateInstance(ctx context.Context, phone, name string, opts *CreateInstanceOptions) (Result, error)

CreateInstance creates a WhatsApp instance. phone is E.164 ("+201234567890"). The result has the instance id and a qr_code to scan with the phone.

func (*EnterpriseService) GetInstanceHealth

func (e *EnterpriseService) GetInstanceHealth(ctx context.Context, instanceID string) (Result, error)

GetInstanceHealth checks whether an instance is connected and working.

func (*EnterpriseService) ListInstances

func (e *EnterpriseService) ListInstances(ctx context.Context, opts *ListInstancesOptions) ([]Result, error)

ListInstances lists your WhatsApp instances.

func (*EnterpriseService) RequestNewQRCode

func (e *EnterpriseService) RequestNewQRCode(ctx context.Context, instanceID string) (Result, error)

RequestNewQRCode returns a fresh QR code to connect the phone.

func (*EnterpriseService) RestartInstance

func (e *EnterpriseService) RestartInstance(ctx context.Context, instanceID string) (Result, error)

RestartInstance restarts an instance.

type Error

type Error struct {
	StatusCode int    // HTTP status code
	Message    string // the API's "message", or the HTTP status text
	Body       []byte // the raw response body
}

Error is returned when the API responds with an HTTP 4xx or 5xx status.

Example
package main

import (
	"context"
	"errors"
	"fmt"

	"github.com/hypersender/hypersender-go"
)

func main() {
	client := hypersender.NewClient()

	_, err := client.WhatsApp.SendText(context.Background(), "201234567890@c.us", "Hi", nil)
	var apiErr *hypersender.Error
	if errors.As(err, &apiErr) {
		fmt.Println(apiErr.StatusCode, apiErr.Message)
	}
}

func (*Error) Error

func (e *Error) Error() string

type GenerateLinkOptions

type GenerateLinkOptions struct {
	Expires  int              `json:"expires,omitempty"` // seconds, 60-3600
	Name     string           `json:"name,omitempty"`
	Message  *OTPLinkMessage  `json:"message,omitempty"`
	Callback *OTPLinkCallback `json:"callback,omitempty"`
}

GenerateLinkOptions are the optional fields for GenerateLink.

type GetAllContactsOptions

type GetAllContactsOptions struct {
	Limit     int    `json:"limit,omitempty"`      // 1-1000, default 100
	Offset    int    `json:"offset,omitempty"`     // default 0
	SortBy    string `json:"sort_by,omitempty"`    // "id" or "name"
	SortOrder string `json:"sort_order,omitempty"` // "asc" or "desc"
}

GetAllContactsOptions are the optional fields for GetAllContacts.

type GetAllKnownLIDsOptions

type GetAllKnownLIDsOptions struct {
	Limit  int `json:"limit,omitempty"`  // default 100
	Offset int `json:"offset,omitempty"` // default 0
}

GetAllKnownLIDsOptions are the optional fields for GetAllKnownLIDs.

type LinkPreview

type LinkPreview struct {
	Title       string
	Description string
	URL         string
	Image       Media // optional: MediaURL or MediaFile
}

LinkPreview is the custom preview for SendLinkCustomPreview.

type ListInstancesOptions

type ListInstancesOptions struct {
	UUID   string `json:"filter[uuid],omitempty"`
	Name   string `json:"filter[name],omitempty"` // partial match
	Phone  string `json:"filter[phone],omitempty"`
	Status string `json:"filter[status],omitempty"` // STOPPED, STARTING, WORKING, SCAN_QR_CODE, FAILED, PENDING
}

ListInstancesOptions filter ListInstances.

type ListOptions

type ListOptions struct {
	Filters map[string]string // e.g. {"status": "delivered"} becomes filter[status]=delivered
	Sort    string            // e.g. "-created_at"
	Include string
	Page    int
	PerPage int
}

ListOptions filter, sort, and page SMS lists.

type Media

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

Media is a file to send: a public URL (MediaURL) or an upload (MediaFile).

func MediaFile

func MediaFile(filename string, r io.Reader) Media

MediaFile returns media uploaded from r, for example an *os.File.

func MediaURL

func MediaURL(url string) Media

MediaURL returns media that Hypersender downloads from a public URL.

type MediaOptions

type MediaOptions struct {
	Filename string `json:"filename,omitempty"` // file name shown to the recipient
	MimeType string `json:"mimetype,omitempty"`
	Caption  string `json:"caption,omitempty"`
	ReplyTo  string `json:"reply_to,omitempty"`
}

MediaOptions are the optional fields for SendFile, SendImage, and SendVideo.

type OTPLinkCallback

type OTPLinkCallback struct {
	Success string `json:"success,omitempty"`
	Failed  string `json:"failed,omitempty"`
}

OTPLinkCallback sets where the user is sent after verification.

type OTPLinkMessage

type OTPLinkMessage struct {
	Prompt  string `json:"prompt,omitempty"`
	Success string `json:"success,omitempty"`
	Failed  string `json:"failed,omitempty"`
	Expired string `json:"expired,omitempty"`
}

OTPLinkMessage overrides the messages shown during OTP link verification.

type OTPService

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

OTPService sends and checks one-time passwords over WhatsApp or SMS. Use it as client.OTP.

func (o *OTPService) GenerateLink(ctx context.Context, chatID string, opts *GenerateLinkOptions) (Result, error)

GenerateLink creates a WhatsApp OTP link the user opens to verify. The link is in data.whatsapp_link.

func (*OTPService) RequestCode

func (o *OTPService) RequestCode(ctx context.Context, chatID string, opts *RequestCodeOptions) (Result, error)

RequestCode sends a one-time code to chatID.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/hypersender/hypersender-go"
)

func main() {
	client := hypersender.NewClient()
	ctx := context.Background()

	client.OTP.RequestCode(ctx, "201234567890@c.us", &hypersender.RequestCodeOptions{Length: 6, Name: "My Shop"})

	res, err := client.OTP.ValidateCode(ctx, "201234567890@c.us", "123456")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res["success"])
}

func (*OTPService) ValidateCode

func (o *OTPService) ValidateCode(ctx context.Context, chatID, code string) (Result, error)

ValidateCode checks a code the user entered.

type Option

type Option func(*options)

Option configures a Client.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL overrides the API base URL, for example to point at a test server.

func WithEnterprise

func WithEnterprise(apiKey string) Option

WithEnterprise sets the Enterprise API key. Default: HYPERSENDER_ENTERPRISE_API_KEY.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client used for requests. The default has a 30 second timeout.

func WithOTP

func WithOTP(apiKey, instanceID string) Option

WithOTP sets the OTP API key and instance ID. Defaults: HYPERSENDER_OTP_API_KEY and HYPERSENDER_OTP_INSTANCE_ID.

func WithSMS

func WithSMS(apiKey, instanceID string) Option

WithSMS sets the SMS API key and instance ID. Defaults: HYPERSENDER_SMS_API_KEY and HYPERSENDER_SMS_INSTANCE_ID.

func WithWhatsApp

func WithWhatsApp(apiKey, instanceID string) Option

WithWhatsApp sets the WhatsApp API key and instance ID. Defaults: HYPERSENDER_WHATSAPP_API_KEY and HYPERSENDER_WHATSAPP_INSTANCE_ID.

type ReadChatOptions

type ReadChatOptions struct {
	Messages int // how many recent messages to mark as read
	Days     int // mark messages from the last N days as read
}

ReadChatOptions are the optional fields for ReadChat.

type RequestCodeOptions

type RequestCodeOptions struct {
	Length     int    `json:"length,omitempty"`     // 4-10
	UseNumber  *bool  `json:"useNumber,omitempty"`  // use hypersender.Bool(true)
	UseLetter  *bool  `json:"useLetter,omitempty"`  // use hypersender.Bool(true)
	AllCapital *bool  `json:"allCapital,omitempty"` // use hypersender.Bool(true)
	Name       string `json:"name,omitempty"`       // your app or company name, shown in the message
	Expires    int    `json:"expires,omitempty"`    // seconds, 60-1800
}

RequestCodeOptions are the optional fields for RequestCode.

type Result

type Result = map[string]any

Result is a JSON object returned by the API.

type SMSService

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

SMSService sends SMS through your Android phone. Use it as client.SMS.

func (*SMSService) DeleteMessage

func (s *SMSService) DeleteMessage(ctx context.Context, messageID string) (Result, error)

DeleteMessage deletes a message.

func (*SMSService) DeleteMessageThread

func (s *SMSService) DeleteMessageThread(ctx context.Context, messageThreadID string) (Result, error)

DeleteMessageThread deletes a conversation.

func (*SMSService) EditMessageThread

func (s *SMSService) EditMessageThread(ctx context.Context, messageThreadID string, isArchived bool) (Result, error)

EditMessageThread archives or unarchives a conversation.

func (*SMSService) GetHeartbeats

func (s *SMSService) GetHeartbeats(ctx context.Context, opts *ListOptions) (Result, error)

GetHeartbeats lists the phone's heartbeats (app version, battery, charging) to check it is online.

func (*SMSService) ListMessageThreads

func (s *SMSService) ListMessageThreads(ctx context.Context, opts *ListOptions) (Result, error)

ListMessageThreads lists conversations.

func (*SMSService) ListMessages

func (s *SMSService) ListMessages(ctx context.Context, opts *ListOptions) (Result, error)

ListMessages lists messages.

func (*SMSService) SendMessage

func (s *SMSService) SendMessage(ctx context.Context, to, content string, opts *SendSMSOptions) (Result, error)

SendMessage sends an SMS to a phone number such as "+201234567890".

Example
package main

import (
	"context"

	"github.com/hypersender/hypersender-go"
)

func main() {
	client := hypersender.NewClient()

	client.SMS.SendMessage(context.Background(), "+201234567890", "Your order has shipped!",
		&hypersender.SendSMSOptions{RequestID: "order-1042"})
}

type SendLinkCustomPreviewOptions

type SendLinkCustomPreviewOptions struct {
	ReplyTo     string `json:"reply_to,omitempty"`
	HighQuality bool   `json:"high_quality,omitempty"`
}

SendLinkCustomPreviewOptions are the optional fields for SendLinkCustomPreview.

type SendLocationOptions

type SendLocationOptions struct {
	Title   string `json:"title,omitempty"`
	ReplyTo string `json:"reply_to,omitempty"`
}

SendLocationOptions are the optional fields for SendLocation.

type SendPollOptions

type SendPollOptions struct {
	MultipleAnswers bool   // let people pick more than one option
	ReplyTo         string // ID of the message to reply to
}

SendPollOptions are the optional fields for SendPoll.

type SendSMSOptions

type SendSMSOptions struct {
	RequestID                string `json:"request_id,omitempty"`                 // your own ID, echoed back in webhooks
	ScheduleSendAt           string `json:"schedule_send_at,omitempty"`           // send later, e.g. "2026-12-01 09:00:00"
	MaxSendAttempts          int    `json:"max_send_attempts,omitempty"`          // retries on failure
	MessageExpirationSeconds int    `json:"message_expiration_seconds,omitempty"` // give up after this many seconds
}

SendSMSOptions are the optional fields for SendMessage.

type SendSeenOptions

type SendSeenOptions struct {
	Participant string `json:"participant,omitempty"` // in groups, the sender of the message
}

SendSeenOptions are the optional fields for SendSeen.

type SendTextOptions

type SendTextOptions struct {
	ReplyTo                string `json:"reply_to,omitempty"`                  // ID of the message to reply to
	LinkPreview            bool   `json:"link_preview,omitempty"`              // show a preview for links
	LinkPreviewHighQuality bool   `json:"link_preview_high_quality,omitempty"` // use a high quality preview image
}

SendTextOptions are the optional fields for SendText and SendTextSafe.

type UpsertContactOptions

type UpsertContactOptions struct {
	LastName string `json:"last_name,omitempty"`
}

UpsertContactOptions are the optional fields for UpsertContact.

type VoiceOptions

type VoiceOptions struct {
	Caption string `json:"caption,omitempty"`
	ReplyTo string `json:"reply_to,omitempty"`
}

VoiceOptions are the optional fields for SendVoice.

type WhatsAppService

type WhatsAppService struct {

	// Contacts looks up and saves WhatsApp contacts and LIDs.
	Contacts *ContactsService
	// contains filtered or unexported fields
}

WhatsAppService sends WhatsApp messages. Use it as client.WhatsApp.

func (*WhatsAppService) DeleteMessage

func (w *WhatsAppService) DeleteMessage(ctx context.Context, chatID, messageID string) (Result, error)

DeleteMessage deletes a message for everyone.

func (*WhatsAppService) ForwardMessage

func (w *WhatsAppService) ForwardMessage(ctx context.Context, chatID, messageID string) (Result, error)

ForwardMessage forwards a message to a chat.

func (*WhatsAppService) GetQueuedRequest

func (w *WhatsAppService) GetQueuedRequest(ctx context.Context, uuid string) (Result, error)

GetQueuedRequest returns a request's status by the queued_request_uuid every send method returns.

func (*WhatsAppService) ReactToMessage

func (w *WhatsAppService) ReactToMessage(ctx context.Context, chatID, messageID, reaction string) (Result, error)

ReactToMessage reacts to a message with an emoji.

func (*WhatsAppService) ReadChat

func (w *WhatsAppService) ReadChat(ctx context.Context, chatID string, opts *ReadChatOptions) (Result, error)

ReadChat marks a chat's recent messages as read.

func (*WhatsAppService) SendContactCard

func (w *WhatsAppService) SendContactCard(ctx context.Context, chatID string, contacts []ContactCard) (Result, error)

SendContactCard sends one or more contact cards.

func (*WhatsAppService) SendFile

func (w *WhatsAppService) SendFile(ctx context.Context, chatID string, file Media, opts *MediaOptions) (Result, error)

SendFile sends a document from a URL or an upload.

func (*WhatsAppService) SendImage

func (w *WhatsAppService) SendImage(ctx context.Context, chatID string, image Media, opts *MediaOptions) (Result, error)

SendImage sends an image from a URL or an upload.

Example
package main

import (
	"context"
	"log"
	"os"

	"github.com/hypersender/hypersender-go"
)

func main() {
	client := hypersender.NewClient()
	ctx := context.Background()

	// From a URL
	client.WhatsApp.SendImage(ctx, "201234567890@c.us", hypersender.MediaURL("https://example.com/menu.png"),
		&hypersender.MediaOptions{Caption: "Today's menu"})

	// From a local file
	f, err := os.Open("invoice.pdf")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	client.WhatsApp.SendFile(ctx, "201234567890@c.us", hypersender.MediaFile("invoice.pdf", f), nil)
}

func (*WhatsAppService) SendLinkCustomPreview

func (w *WhatsAppService) SendLinkCustomPreview(ctx context.Context, chatID, text string, preview LinkPreview, opts *SendLinkCustomPreviewOptions) (Result, error)

SendLinkCustomPreview sends a link with your own preview title, description, and image.

func (*WhatsAppService) SendLocation

func (w *WhatsAppService) SendLocation(ctx context.Context, chatID string, latitude, longitude float64, opts *SendLocationOptions) (Result, error)

SendLocation sends a location pin.

func (*WhatsAppService) SendPoll

func (w *WhatsAppService) SendPoll(ctx context.Context, chatID, name string, options []string, opts *SendPollOptions) (Result, error)

SendPoll sends a poll.

func (*WhatsAppService) SendSeen

func (w *WhatsAppService) SendSeen(ctx context.Context, chatID, messageID string, opts *SendSeenOptions) (Result, error)

SendSeen marks a message as seen (blue ticks).

func (*WhatsAppService) SendText

func (w *WhatsAppService) SendText(ctx context.Context, chatID, text string, opts *SendTextOptions) (Result, error)

SendText sends a text message. chatID looks like "201234567890@c.us".

func (*WhatsAppService) SendTextSafe

func (w *WhatsAppService) SendTextSafe(ctx context.Context, chatID, text string, opts *SendTextOptions) (Result, error)

SendTextSafe sends a text message with human-like pacing and typing to lower the risk of a block.

func (*WhatsAppService) SendVideo

func (w *WhatsAppService) SendVideo(ctx context.Context, chatID string, video Media, opts *MediaOptions) (Result, error)

SendVideo sends a video from a URL or an upload.

func (*WhatsAppService) SendVoice

func (w *WhatsAppService) SendVoice(ctx context.Context, chatID string, voice Media, opts *VoiceOptions) (Result, error)

SendVoice sends a voice note from a URL or an upload.

func (*WhatsAppService) StarMessage

func (w *WhatsAppService) StarMessage(ctx context.Context, chatID, messageID string, star bool) (Result, error)

StarMessage stars (star=true) or unstars a message.

func (*WhatsAppService) StartTyping

func (w *WhatsAppService) StartTyping(ctx context.Context, chatID string) (Result, error)

StartTyping shows "typing..." in a chat.

func (*WhatsAppService) StopTyping

func (w *WhatsAppService) StopTyping(ctx context.Context, chatID string) (Result, error)

StopTyping stops showing "typing..." in a chat.

Jump to

Keyboard shortcuts

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