whatsapp_business

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: MIT Imports: 7 Imported by: 0

README

whatsapp-business

This is a SDK did in Go that helps you to handle and send messages of whatsapp business api (v20).

Why?

This task is kinda easy to do, but for a developer, any time saved is precious.

Status

In Development: This SDK is not in ready for use

Pattern

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioMessage

type AudioMessage struct {
	Link string `json:"link"`
	ID   string `json:"id"`
}

type AuthResponse

type AuthResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	*ErrorResponse
}

type BusinessProfile

type BusinessProfile struct {
	About             string   `json:"about"`
	Address           string   `json:"address"`
	Description       string   `json:"description"`
	Email             string   `json:"email"`
	MessagingProduct  string   `json:"messaging_product"`
	ProfilePictureUrl string   `json:"profile_picture_url"`
	Websites          []string `json:"websites"`
	Vertical          string   `json:"vertical"`
}

type BusinessProfileResponse

type BusinessProfileResponse struct {
	Data []BusinessProfile `json:"data"`
	*ErrorResponse
}

type BusinessResponse

type BusinessResponse struct {
	Id                       string `json:"id"`
	Name                     string `json:"name"`
	TimezoneId               string `json:"timezone_id"`
	MessageTemplateNamespace string `json:"message_template_namespace"`
	*ErrorResponse
}

type Client

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

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new client with the provided options

func (*Client) GenerateAccessToken

func (s *Client) GenerateAccessToken(ctx context.Context, code, clientID, clientSecret string) (*AuthResponse, error)

func (*Client) GetBusiness

func (s *Client) GetBusiness(ctx context.Context, businessAccountId string) (*BusinessResponse, error)

func (*Client) GetBusinessProfile

func (s *Client) GetBusinessProfile(ctx context.Context, phoneID string) (*BusinessProfile, error)

func (*Client) GetMedia

func (s *Client) GetMedia(ctx context.Context, mediaID string) (*Media, error)

func (*Client) GetPhoneNumber

func (s *Client) GetPhoneNumber(ctx context.Context, phoneID string) (*PhoneNumberResponse, error)

func (*Client) ReadMessage

func (s *Client) ReadMessage(ctx context.Context, messageID string) (*MessageResponse, error)

func (*Client) RegisterPhoneNumber

func (s *Client) RegisterPhoneNumber(ctx context.Context, phoneID string, pin string) (*RegisterPhoneNumberResponse, error)

func (*Client) SendAudioMessage

func (s *Client) SendAudioMessage(ctx context.Context, to string, d AudioMessage, options ...SendMessageOption) (*MessageResponse, error)

func (*Client) SendDocumentMessage

func (s *Client) SendDocumentMessage(ctx context.Context, to string, d DocumentMessage, options ...SendMessageOption) (*MessageResponse, error)

func (*Client) SendImageMessage

func (s *Client) SendImageMessage(ctx context.Context, to string, d ImageMessage, options ...SendMessageOption) (*MessageResponse, error)

func (*Client) SendInteractiveMessage

func (s *Client) SendInteractiveMessage(ctx context.Context, to string, d InteractiveMessage, options ...SendMessageOption) (*MessageResponse, error)

func (*Client) SendTextMessage

func (s *Client) SendTextMessage(ctx context.Context, to string, d TextMessage, options ...SendMessageOption) (*MessageResponse, error)

func (*Client) SendVideoMessage

func (s *Client) SendVideoMessage(ctx context.Context, to string, d VideoMessage, options ...SendMessageOption) (*MessageResponse, error)

func (*Client) SetBusinessWebhook

func (s *Client) SetBusinessWebhook(ctx context.Context, businessAccountId string, request *SetWebhookConfig) (*SetBusinessWebhookResponse, error)

func (*Client) SetPhoneNumberWebhook

func (s *Client) SetPhoneNumberWebhook(ctx context.Context, phoneID string, request *SetWebhookConfig) (*SetPhoneNumberWebhookResponse, error)

type DocumentMessage

type DocumentMessage struct {
	Link     string `json:"link"`
	ID       string `json:"id"`
	Caption  string `json:"caption"`
	Filename string `json:"filename"`
}

type DocumentMessageRequest

type DocumentMessageRequest struct {
	Document DocumentMessage `json:"document"`
	// contains filtered or unexported fields
}

type ErrorResponse

type ErrorResponse struct {
	Error struct {
		Message   string `json:"message"`
		Type      string `json:"type"`
		Code      int    `json:"code"`
		FbtraceId string `json:"fbtrace_id"`
	} `json:"error"`
}

type ImageMessage

type ImageMessage struct {
	Link    string `json:"link"`
	Caption string `json:"caption"`
	ID      string `json:"id"`
}

type InteractiveMessage

type InteractiveMessage struct {
	Type   InteractiveMessageInternalType `json:"type"`
	Header InteractiveMessageHeader       `json:"header"`
	Body   InteractiveMessageBody         `json:"body"`
	Footer InteractiveMessageFooter       `json:"footer"`
	Action InteractiveMessageAction       `json:"action"`
}

type InteractiveMessageAction

type InteractiveMessageAction struct {
	Button   string                      `json:"button"`
	Sections []InteractiveMessageSection `json:"sections"`
}

type InteractiveMessageBody

type InteractiveMessageBody struct {
	Text string `json:"text"`
}

type InteractiveMessageFooter

type InteractiveMessageFooter struct {
	Text string `json:"text"`
}

type InteractiveMessageHeader

type InteractiveMessageHeader struct {
	Type InteractiveMessageHeaderType `json:"type"`
	Text string                       `json:"text"`
}

type InteractiveMessageHeaderType

type InteractiveMessageHeaderType string
const (
	InteractiveMessageHeaderTypeText InteractiveMessageHeaderType = "text"
)

type InteractiveMessageInternalType

type InteractiveMessageInternalType string
const (
	InteractiveMessageTypeList InteractiveMessageInternalType = "LIST"
)

type InteractiveMessageRequest

type InteractiveMessageRequest struct {
	Interactive InteractiveMessage `json:"interactive"`
	// contains filtered or unexported fields
}

type InteractiveMessageRow

type InteractiveMessageRow struct {
	Id          string `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

type InteractiveMessageSection

type InteractiveMessageSection struct {
	Title string                  `json:"title"`
	Rows  []InteractiveMessageRow `json:"rows"`
}

type Media

type Media struct {
	MessagingProduct string `json:"messaging_product"`
	URL              string `json:"url"`
	MimeType         string `json:"mime_type"`
	Sha256           string `json:"sha256"`
	FileSize         uint64 `json:"file_size"`
	ID               string `json:"id"`
	*ErrorResponse
}

type MessageContext

type MessageContext struct {
	MessageId string `json:"message_id,omitempty"`
}

type MessageResponse

type MessageResponse struct {
	MessagingProduct string                   `json:"messaging_product"`
	Contacts         []contactMessageResponse `json:"contacts"`
	Messages         []contentMessageResponse `json:"messages"`
	*ErrorResponse
}

type MessageType

type MessageType string
const (
	TextMessageType        MessageType = "text"
	ImageMessageType       MessageType = "image"
	AudioMessageType       MessageType = "audio"
	VideoMessageType       MessageType = "video"
	DocumentMessageType    MessageType = "document"
	InteractiveMessageType MessageType = "interactive"
)

type Option

type Option func(*Client)

Option is a function that configures a client

func WithBaseUrl

func WithBaseUrl(baseUrl string) Option

WithBaseUrl sets the base URL of the client

func WithHttpClient

func WithHttpClient(httpClient *http.Client) Option

WithHttpClient sets the http client of the client

func WithPhoneNumberId

func WithPhoneNumberId(phoneNumberId string) Option

WithPhoneNumberId sets the phone number id of the client

func WithToken

func WithToken(token string) Option

WithToken sets the token of the client

type PhoneNumberResponse

type PhoneNumberResponse struct {
	VerifiedName           string                                   `json:"verified_name"`
	CodeVerificationStatus string                                   `json:"code_verification_status"`
	DisplayPhoneNumber     string                                   `json:"display_phone_number"`
	QualityRating          string                                   `json:"quality_rating"`
	PlatformType           string                                   `json:"platform_type"`
	Throughput             PhoneNumberResponseThroughput            `json:"throughput"`
	LastOnboardedTime      string                                   `json:"last_onboarded_time"`
	WebhookConfiguration   PhoneNumberResponseWhatsappConfiguration `json:"webhook_configuration"`
	Id                     string                                   `json:"id"`
	*ErrorResponse
}

type PhoneNumberResponseThroughput

type PhoneNumberResponseThroughput struct {
	Level string `json:"level"`
}

type PhoneNumberResponseWhatsappConfiguration

type PhoneNumberResponseWhatsappConfiguration struct {
	WhatsappBusinessAccount string `json:"whatsapp_business_account"`
	Application             string `json:"application"`
}

type RegisterPhoneNumberRequest

type RegisterPhoneNumberRequest struct {
	MessagingProduct messagingProductType `json:"messaging_product"`
	Pin              string               `json:"pin"`
}

type RegisterPhoneNumberResponse

type RegisterPhoneNumberResponse struct {
	Success bool `json:"success"`
	*ErrorResponse
}

type SendMessageOption

type SendMessageOption func(*MessageContext)

func WithReplyMessage

func WithReplyMessage(messageID string) SendMessageOption

type SetBusinessWebhookRequest

type SetBusinessWebhookRequest struct {
	WebhookConfiguration SetWebhookConfig `json:"webhook_configuration"`
}

type SetBusinessWebhookResponse

type SetBusinessWebhookResponse struct {
	Success bool `json:"success"`
	*ErrorResponse
}

type SetPhoneNumberWebhookRequest

type SetPhoneNumberWebhookRequest struct {
	WebhookConfiguration SetWebhookConfig `json:"webhook_configuration"`
}

type SetPhoneNumberWebhookResponse

type SetPhoneNumberWebhookResponse struct {
	Success bool `json:"success"`
	*ErrorResponse
}

type SetWebhookConfig

type SetWebhookConfig struct {
	OverrideCallbackUri string `json:"override_callback_uri"`
	VerifyToken         string `json:"verify_token"`
}

type TextMessage

type TextMessage struct {
	PreviewUrl *bool  `json:"preview_url,omitempty"`
	Body       string `json:"body"`
}

type VideoMessage

type VideoMessage struct {
	Link    string `json:"link"`
	Caption string `json:"caption"`
	ID      string `json:"id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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