Components
import "github.com/sarthakjdev/wapi.go/pkg/components"
type AddressType
type AddressType string
const (
HomeAddress AddressType = "HOME"
WorkAddress AddressType = "WORK"
)
const (
HomeUrl AddressType = "HOME"
WorkUrl AddressType = "WORK"
)
type ApiCompatibleJsonConverterConfigs
ApiCompatibleJsonConverterConfigs represents the configuration for converting to JSON.
type ApiCompatibleJsonConverterConfigs struct {
ReplyToMessageId string
SendToPhoneNumber string
}
type AudioMessage
AudioMessage represents an audio message.
type AudioMessage struct {
Id string `json:"id,omitempty"`
Link string `json:"link,omitempty"`
}
func NewAudioMessage
func NewAudioMessage(params AudioMessageConfigs) (*AudioMessage, error)
NewAudioMessage creates a new AudioMessage object.
func (*AudioMessage) ToJson
func (audio *AudioMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the AudioMessage object to JSON.
type AudioMessageApiPayload
AudioMessageApiPayload represents the payload for an audio message API request.
type AudioMessageApiPayload struct {
BaseMessagePayload
Audio AudioMessage `json:"audio" validate:"required"`
}
type AudioMessageConfigs
AudioMessageConfigs is an alias for AudioMessage.
type AudioMessageConfigs = AudioMessage
type BaseMessage
BaseMessage is an interface for sending messages.
type BaseMessage interface {
ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
}
type BaseMessagePayload
BaseMessagePayload represents the base payload to send messages.
type BaseMessagePayload struct {
Context *Context `json:"context,omitempty"`
To string `json:"to"`
Type MessageType `json:"type"`
MessagingProduct string `json:"messaging_product"`
RecipientType string `json:"recipient_type"`
}
func NewBaseMessagePayload
func NewBaseMessagePayload(to string, messageType MessageType) BaseMessagePayload
NewBaseMessagePayload creates a new instance of BaseMessagePayload.
type Contact
type Contact struct {
Name ContactName `json:"name" validate:"required"`
Org ContactOrg `json:"org,omitempty"`
Addresses []ContactAddress `json:"addresses,omitempty"`
Urls []ContactUrl `json:"urls,omitempty"`
Emails []ContactEmail `json:"emails,omitempty"`
Phones []ContactPhone `json:"phones,omitempty"`
Birthday string `json:"birthday,omitempty"`
}
func NewContact
func NewContact(name ContactName) *Contact
func (*Contact) AddEmail
func (contact *Contact) AddEmail(params ContactEmail)
func (*Contact) AddPhone
func (contact *Contact) AddPhone(params ContactPhone)
func (*Contact) AddUrl
func (contact *Contact) AddUrl(params ContactUrl)
func (*Contact) SetBirthday
func (contact *Contact) SetBirthday(params string)
! TODO: add regex check here in the params
func (*Contact) SetFirstName
func (contact *Contact) SetFirstName(firstName string)
func (*Contact) SetLastName
func (contact *Contact) SetLastName(lastName string)
func (*Contact) SetMiddleName
func (contact *Contact) SetMiddleName(middleName string)
func (*Contact) SetOrg
func (contact *Contact) SetOrg(params ContactOrg)
type ContactAddress
type ContactAddress struct {
Street string `json:"street,omitempty"`
City string `json:"city,omitempty"`
State string `json:"state,omitempty"`
Zip string `json:"zip,omitempty"`
Country string `json:"country,omitempty"`
CountryCode string `json:"countryCode,omitempty"`
Type AddressType `json:"type" validate:"required"`
}
type ContactEmail
type ContactEmail struct {
Email string `json:"email,omitempty"`
Type EmailType `json:"type,omitempty"`
}
type ContactMessage
type ContactMessage struct {
Contacts []Contact `json:"contacts" validate:"required"`
}
func NewContactMessage
func NewContactMessage(configs []Contact) (*ContactMessage, error)
func (*ContactMessage) AddContact
func (contact *ContactMessage) AddContact(params Contact)
func (*ContactMessage) ToJson
func (m *ContactMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
type ContactMessageApiPayload
type ContactMessageApiPayload struct {
BaseMessagePayload
Contacts []Contact `json:"contacts" validate:"required"`
}
type ContactMessageConfigs
type ContactMessageConfigs struct {
Name string `json:"name" validate:"required"`
}
type ContactName
type ContactName struct {
FormattedName string `json:"formatted_name" validate:"required"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
MiddleName string `json:"middle_name,omitempty"`
Suffix string `json:"suffix,omitempty"`
Prefix string `json:"prefix,omitempty"`
}
type ContactOrg
type ContactOrg struct {
Company string `json:"company,omitempty"`
Title string `json:"title,omitempty"`
Department string `json:"department,omitempty"`
}
type ContactPhone
type ContactPhone struct {
Phone string `json:"phone,omitempty"`
WaId string `json:"wa_id,omitempty"`
Type PhoneType `json:"type" validate:"required"`
}
type ContactUrl
type ContactUrl struct {
Url string `json:"url" validate:"required"`
Type UrlType `json:"type" validate:"required"`
}
type Context
Context represents the context of the message.
type Context struct {
MessageId string `json:"message_id,omitempty"`
}
type DocumentMessage
DocumentMessage represents a document message.
type DocumentMessage struct {
}
func NewDocumentMessage
func NewDocumentMessage(params DocumentMessageConfigs) (*DocumentMessage, error)
NewDocumentMessage creates a new DocumentMessage instance.
func (*DocumentMessage) ToJson
func (dm *DocumentMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the DocumentMessage instance to JSON.
type DocumentMessageApiPayload
DocumentMessageApiPayload represents the API payload for a document message.
type DocumentMessageApiPayload struct {
BaseMessagePayload
Document DocumentMessage `json:"document" validate:"required"`
}
type DocumentMessageConfigs
DocumentMessageConfigs represents the configurations for a document message.
type DocumentMessageConfigs struct {
}
type EmailType
type EmailType string
const (
HomeEmail EmailType = "HOME"
WorkEmail EmailType = "WORK"
)
type ImageMessage
ImageMessage represents a message with an image.
type ImageMessage struct {
Id string `json:"id,omitempty"`
Link string `json:"link,omitempty"`
Caption string `json:"caption,omitempty"`
}
func NewImageMessage
func NewImageMessage(params ImageMessageConfigs) (*ImageMessage, error)
NewImageMessage creates a new ImageMessage instance.
func (*ImageMessage) SetCaption
func (image *ImageMessage) SetCaption(params string)
SetCaption sets the caption for the image message.
func (*ImageMessage) ToJson
func (image *ImageMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the ImageMessage to JSON.
type ImageMessageApiPayload
ImageMessageApiPayload represents the API payload for an image message.
type ImageMessageApiPayload struct {
BaseMessagePayload
Image ImageMessage `json:"image" validate:"required"`
}
type ImageMessageConfigs
ImageMessageConfigs is an alias for ImageMessage.
type ImageMessageConfigs = ImageMessage
type InteractiveMessageType
type InteractiveMessageType string
const (
InteractiveMessageTypeButton InteractiveMessageType = "button"
InteractiveMessageTypeProduct InteractiveMessageType = "product"
InteractiveMessageTypeProductList InteractiveMessageType = "product_list"
InteractiveMessageTypeList InteractiveMessageType = "list"
)
type ListMessageApiPayload
ListMessageApiPayload represents the API payload for the list message.
type ListMessageApiPayload struct {
BaseMessagePayload
Interactive listMessage `json:"interactive" validate:"required"` // Interactive message.
}
type ListMessageBody
ListMessageBody represents the body of the list message.
type ListMessageBody struct {
Text string `json:"text" validate:"required"` // Text of the body.
}
type ListMessageParams
ListMessageParams represents the parameters for creating a list message.
type ListMessageParams struct {
ButtonText string `json:"-" validate:"required"` // Text of the button.
BodyText string `json:"-" validate:"required"` // Text of the body.
}
type LocationMessage
LocationMessage represents a location message with latitude, longitude, address, and name.
type LocationMessage struct {
Latitude float64 `json:"latitude" validate:"required"` // Latitude of the location
Longitude float64 `json:"longitude" validate:"required"` // Longitude of the location
Address string `json:"address,omitempty"` // Address of the location (optional)
Name string `json:"name,omitempty"` // Name of the location (optional)
}
func NewLocationMessage
func NewLocationMessage(latitude float64, longitude float64) (*LocationMessage, error)
NewLocationMessage creates a new LocationMessage with the given latitude and longitude.
func (*LocationMessage) SetAddress
func (location *LocationMessage) SetAddress(params string)
SetAddress sets the address of the location.
func (*LocationMessage) SetName
func (location *LocationMessage) SetName(params string)
SetName sets the name of the location.
func (*LocationMessage) ToJson
func (location *LocationMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the LocationMessage to JSON with the given configurations.
type LocationMessageApiPayload
LocationMessageApiPayload represents the API payload for a location message.
type LocationMessageApiPayload struct {
BaseMessagePayload
Location LocationMessage `json:"location" validate:"required"` // Location message
}
type MessageType
MessageType represents the type of message.
type MessageType string
Constants for different message types.
const (
MessageTypeLocation MessageType = "location"
MessageTypeAudio MessageType = "audio"
MessageTypeVideo MessageType = "video"
MessageTypeDocument MessageType = "document"
MessageTypeText MessageType = "text"
MessageTypeContact MessageType = "contacts"
MessageTypeInteractive MessageType = "interactive"
MessageTypeTemplate MessageType = "template"
MessageTypeReaction MessageType = "reaction"
MessageTypeSticker MessageType = "sticker"
MessageTypeImage MessageType = "image"
)
type Order
Order represents an order in the system.
type Order struct {
CatalogID string `json:"catalog_id"` // CatalogID is the ID of the catalog associated with the order.
ProductItems []ProductItem `json:"product_items"` // ProductItems is a list of product items in the order.
Text string `json:"text"` // Text is an additional text associated with the order.
}
type PhoneType
type PhoneType string
const (
CellPhone PhoneType = "CELL"
MainPhone PhoneType = "MAIN"
IphonePhone PhoneType = "IPHONE"
HomePhone PhoneType = "HOME"
WorkPhone PhoneType = "WORK"
)
type ProductItem
ProductItem represents a product item in an order.
type ProductItem struct {
Currency string `json:"currency"` // Currency is the currency of the product item.
ItemPrice string `json:"item_price"` // ItemPrice is the price of the product item.
ProductRetailerID string `json:"product_retailer_id"` // ProductRetailerID is the ID of the retailer associated with the product item.
Quantity string `json:"quantity"` // Quantity is the quantity of the product item.
}
type ProductListMessage
ProductListMessage represents a product list message.
type ProductListMessage struct {
}
func NewProductListMessage
func NewProductListMessage(params ProductListMessageParams) (*ProductListMessage, error)
NewProductListMessage creates a new product list message.
func (*ProductListMessage) ToJson
func (m *ProductListMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the product list message to JSON.
type ProductListMessageApiPayload
ProductListMessageApiPayload represents the API payload for a product list message.
type ProductListMessageApiPayload struct {
BaseMessagePayload
Interactive ProductListMessage `json:"interactive" validate:"required"`
}
type ProductListMessageParams
ProductListMessageParams represents the parameters for creating a product list message.
type ProductListMessageParams struct {
}
type ProductMessage
ProductMessage represents a product message.
type ProductMessage struct {
}
func NewProductMessage
func NewProductMessage(params ProductMessageParams) (*ProductMessage, error)
NewProductMessage creates a new product message with the given parameters.
func (*ProductMessage) ToJson
func (m *ProductMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the product message to JSON with the given configurations.
type ProductMessageApiPayload
ProductMessageApiPayload represents the API payload for a product message.
type ProductMessageApiPayload struct {
BaseMessagePayload
Interactive ProductMessage `json:"interactive" validate:"required"`
}
type ProductMessageParams
ProductMessageParams represents the parameters for creating a product message.
type ProductMessageParams struct {
}
type QuickReplyButtonMessage
QuickReplyButtonMessage represents a quick reply button message.
type QuickReplyButtonMessage struct {
Type InteractiveMessageType `json:"type" validate:"required"` // Type of the quick reply button message.
Body QuickReplyButtonMessageBody `json:"body" validate:"required"` // Body of the quick reply button message.
Action QuickReplyButtonMessageAction `json:"action" validate:"required"` // Action of the quick reply button message.
}
func NewQuickReplyButtonMessage
func NewQuickReplyButtonMessage(bodyText string) (*QuickReplyButtonMessage, error)
NewQuickReplyButtonMessage creates a new quick reply button message with the given body text.
func (*QuickReplyButtonMessage) AddButton
func (m *QuickReplyButtonMessage) AddButton(id, title string) error
func (*QuickReplyButtonMessage) ToJson
func (m *QuickReplyButtonMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the quick reply button message to JSON.
type QuickReplyButtonMessageAction
QuickReplyButtonMessageAction represents the action of a quick reply button message.
type QuickReplyButtonMessageAction struct {
Buttons []quickReplyButtonMessageButton `json:"buttons" validate:"required"` // List of quick reply buttons.
}
type QuickReplyButtonMessageApiPayload
QuickReplyButtonMessageApiPayload represents the API payload for a quick reply button message.
type QuickReplyButtonMessageApiPayload struct {
BaseMessagePayload
Interactive QuickReplyButtonMessage `json:"interactive" validate:"required"` // Interactive part of the API payload.
}
type QuickReplyButtonMessageBody
QuickReplyButtonMessageBody represents the body of a quick reply button message.
type QuickReplyButtonMessageBody struct {
Text string `json:"text" validate:"required"` // Text of the quick reply button message.
}
type ReactionMessage
ReactionMessage represents a reaction to a message.
type ReactionMessage struct {
MessageId string `json:"message_id" validate:"required"` // The ID of the message to react to.
Emoji string `json:"emoji" validate:"required"` // The emoji representing the reaction.
}
func NewReactionMessage
func NewReactionMessage(params ReactionMessageParams) (*ReactionMessage, error)
NewReactionMessage creates a new ReactionMessage instance.
func (*ReactionMessage) ToJson
func (reaction *ReactionMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the ReactionMessage to JSON.
type ReactionMessageApiPayload
ReactionMessageApiPayload represents the API payload for a reaction message.
type ReactionMessageApiPayload struct {
BaseMessagePayload
Reaction ReactionMessage `json:"reaction" validate:"required"` // The reaction message.
}
type ReactionMessageParams
ReactionMessageParams is an alias for ReactionMessage.
type ReactionMessageParams = ReactionMessage
type StickerMessage
StickerMessage represents a sticker message.
type StickerMessage struct {
Id string `json:"id,omitempty"`
Link string `json:"link,omitempty"`
}
func NewStickerMessage
func NewStickerMessage(params *StickerMessageConfigs) (*StickerMessage, error)
NewStickerMessage creates a new sticker message based on the provided configurations.
func (*StickerMessage) ToJson
func (sticker *StickerMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the sticker message to JSON based on the provided configurations.
type StickerMessageApiPayload
StickerMessageApiPayload represents the API payload for a sticker message.
type StickerMessageApiPayload struct {
BaseMessagePayload
Sticker StickerMessage `json:"sticker" validate:"required"`
}
type StickerMessageConfigs
StickerMessageConfigs represents the configurations for a sticker message.
type StickerMessageConfigs struct {
Id string `json:"id,omitempty"`
Link string `json:"link,omitempty"`
}
type TemplateMessage
TemplateMessage represents a template message.
type TemplateMessage struct {
}
func NewTemplateMessage
func NewTemplateMessage() (*TemplateMessage, error)
NewTemplateMessage creates a new instance of TemplateMessage.
type TemplateMessageApiPayload
TemplateMessageApiPayload represents the API payload for a template message.
type TemplateMessageApiPayload struct {
BaseMessagePayload
Template TemplateMessage `json:"template" validate:"required"`
}
type TextMessageApiPayload
TextMessageApiPayload represents the payload for the WhatsApp API.
type TextMessageApiPayload struct {
BaseMessagePayload `json:",inline"`
Text TextMessageApiPayloadText `json:"text" validate:"required"` // The text content of the message.
}
type TextMessageApiPayloadText
TextMessageApiPayloadText represents the text payload for the WhatsApp API.
type TextMessageApiPayloadText struct {
Body string `json:"body" validate:"required"` // The text content of the message.
AllowPreview bool `json:"preview_url,omitempty"` // Whether to allow preview of the message.
}
type TextMessageConfigs
TextMessageConfigs represents the configuration options for a text message.
type TextMessageConfigs struct {
Text string `json:"text" validate:"required"` // The text content of the message.
AllowPreview bool `json:"allowPreview,omitempty"` // Whether to allow preview of the message.
}
type UrlType
type UrlType string
type VideoMessage
VideoMessage represents a video message.
type VideoMessage struct {
Id string `json:"id,omitempty"`
Link string `json:"link,omitempty"`
Caption string `json:"caption,omitempty"`
}
func NewVideoMessage
func NewVideoMessage(params VideoMessageConfigs) (*VideoMessage, error)
NewVideoMessage creates a new VideoMessage instance.
func (*VideoMessage) SetCaption
func (video *VideoMessage) SetCaption(params string)
SetCaption sets the caption for the video message.
func (*VideoMessage) ToJson
func (video *VideoMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the video message to JSON.
type VideoMessageApiPayload
VideoMessageApiPayload represents the API payload for a video message.
type VideoMessageApiPayload struct {
BaseMessagePayload
Video VideoMessage `json:"video" validate:"required"`
}
type VideoMessageConfigs
VideoMessageConfigs is an alias for VideoMessage.
type VideoMessageConfigs = VideoMessage
type listMessage
listMessage represents an interactive list message.
type listMessage struct {
Type InteractiveMessageType `json:"type" validate:"required"` // Type of the message.
Action listMessageAction `json:"action" validate:"required"` // Action of the message.
Body ListMessageBody `json:"body,omitempty"` // Body of the message.
}
func NewListMessage
func NewListMessage(params ListMessageParams) (*listMessage, error)
NewListMessage creates a new list message with the given parameters.
func (*listMessage) AddSection
func (m *listMessage) AddSection(section *listSection)
AddSection adds a new section to the list message.
func (*listMessage) SetBodyText
func (m *listMessage) SetBodyText(section *listSection)
SetBodyText sets the body text of the list message.
func (*listMessage) ToJson
func (m *listMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the list message to JSON.
type listMessageAction
listMessageAction represents the action of the list message.
type listMessageAction struct {
ButtonText string `json:"button" validate:"required"` // Text of the button.
Sections []listSection `json:"sections" validate:"required"` // Sections in the list message.
}
type listSection
listSection represents a section in the list message.
type listSection struct {
Title string `json:"title" validate:"required"` // Title of the section.
Rows []listSectionRow `json:"rows" validate:"required"` // Rows in the section.
}
func NewListSection
func NewListSection(title string) (*listSection, error)
NewListSection creates a new list section with the given title.
func (*listSection) AddRow
func (section *listSection) AddRow(row *listSectionRow)
AddRow adds a new row to the list section.
func (*listSection) SetTitle
func (section *listSection) SetTitle(title string)
SetTitle sets the title of the list section.
type listSectionRow
listSectionRow represents a row in the list section.
type listSectionRow struct {
Id string `json:"id" validate:"required"` // ID of the row.
Description string `json:"description" validate:"required"` // Description of the row.
Title string `json:"title" validate:"required"` // Title of the row.
}
func NewListSectionRow
func NewListSectionRow(id, title, description string) (*listSectionRow, error)
NewListSectionRow creates a new list section row with the given ID, title, and description.
func (*listSectionRow) SetDescription
func (row *listSectionRow) SetDescription(description string)
SetDescription sets the description of the list section row.
func (*listSectionRow) SetId
func (row *listSectionRow) SetId(id string)
SetId sets the ID of the list section row.
func (*listSectionRow) SetTitle
func (row *listSectionRow) SetTitle(title string)
SetTitle sets the title of the list section row.
type quickReplyButtonMessageButton
quickReplyButtonMessageButton represents a quick reply button.
type quickReplyButtonMessageButton struct {
Type string `json:"type" validate:"required"` // Type of the quick reply button.
Reply quickReplyButtonMessageButtonReply `json:"reply" validate:"required"` // Reply structure of the quick reply button.
}
func NewQuickReplyButton
func NewQuickReplyButton(id, title string) (*quickReplyButtonMessageButton, error)
NewQuickReplyButton creates a new quick reply button with the given ID and title.
type quickReplyButtonMessageButtonReply
quickReplyButtonMessageButtonReply represents the reply structure of a quick reply button.
type quickReplyButtonMessageButtonReply struct {
Title string `json:"title" validate:"required"` // Title of the quick reply button.
Id string `json:"id" validate:"required"` // ID of the quick reply button.
}
type textMessage
textMessage represents a text message.
type textMessage struct {
Text string // The text content of the message.
AllowPreview bool // Whether to allow preview of the message.
}
func NewTextMessage
func NewTextMessage(configs TextMessageConfigs) (*textMessage, error)
NewTextMessage creates a new text message with the given configurations.
func (*textMessage) SetText
func (m *textMessage) SetText(text string)
SetText sets the text content of the message.
func (*textMessage) ToJson
func (m *textMessage) ToJson(configs ApiCompatibleJsonConverterConfigs) ([]byte, error)
ToJson converts the text message struct to WhatsApp API compatible JSON.