types

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const FacebookSupportUrl = "https://developers.facebook.com/docs/whatsapp"

references for documentation url, points to the facebook documentation page

View Source
const (
	// global field for authorization header
	HeaderAuthorization = "Authorization"
)

Variables

View Source
var (
	// MediaTypeMapping provides available extension to mime
	// type mapping which can be uploaded to whatsapp
	MediaTypeMapping = map[string]MediaType{
		".jpeg": MediaTypeImageJpeg,
		".png":  MediaTypeImagePng,
		".webp": MediaTypeImageWebp,
		".acc":  MediaTypeAudioAcc,
		".mp3":  MediaTypeAudioMpeg,
		".amr":  MediaTypeAudioAmr,
		".oga":  MediaTypeAudioOgg,
		".opus": MediaTypeAudioOpus,
		".mp4":  MediaTypeVideoMp4,
		".3gp":  MediaTypeVideo3gpp,
		".doc":  MediaTypeDocumentDoc,
		".docx": MediaTypeDocumentDocx,
		".pdf":  MediaTypeDocumentPdf,
		".ppt":  MediaTypeDocumentPpt,
		".pptx": MediaTypeDocumentPptx,
		".xls":  MediaTypeDocumentXls,
		".xlsx": MediaTypeDocumentXlsx,
		".zip":  MediaTypeDocumentZip,
		".rar":  MediaTypeDocumentRar,
	}
)

MessageTypesMapping provides a mapping to message types which will be use to validate the user specified operation

Functions

This section is empty.

Types

type ContactResponse

type ContactResponse struct {
	Contacts []struct {
		Input  string `json:"input"`
		Status string `json:"status"`
		WaID   string `json:"wa_id"`
	} `json:"contacts"`
	Meta Meta `json:"meta"`
}

func (*ContactResponse) GetStatus

func (c *ContactResponse) GetStatus() (string, error)

type Media

type Media struct {
	Path     string `validate:"required"`
	Size     int64
	MimeType MediaType
	Data     []byte
}

Media object for storing the information about file, which will be uploaded to whatsapp

func NewFileReader

func NewFileReader(path string) (*Media, error)

NewFileReader returns a new object of media type it will also convert the file path to absolute

func (*Media) GetMimeType

func (f *Media) GetMimeType() string

GetMimeType will return the file mime type which is of type MediaType converted to string

func (*Media) Read

func (f *Media) Read() error

Read checks if the file exits by checking it's stats if file is not present it will return an error other wise it will process link to find the mime type and returns a []bytes for the files data

type MediaMessage

type MediaMessage struct {
	Provider Provider `json:"provider"`
	Caption  string   `json:"caption"`
	ID       string   `json:"id,omitempty"`
	Link     string   `json:"link,omitempty"`
}

type MediaResponse

type MediaResponse struct {
	Media []struct {
		ID string `json:"id"`
	} `json:"media"`
	Meta Meta `json:"meta"`
}

func (*MediaResponse) GetId

func (m *MediaResponse) GetId() (string, error)

type MediaType

type MediaType string
const (
	MediaTypeImageJpeg    MediaType = "image/jpeg"
	MediaTypeImagePng     MediaType = "image/png"
	MediaTypeImageWebp    MediaType = "image/webp"
	MediaTypeAudioAcc     MediaType = "audio/aac"
	MediaTypeAudioAmr     MediaType = "audio/amr"
	MediaTypeAudioMpeg    MediaType = "audio/mpeg"
	MediaTypeAudioOgg     MediaType = "audio/ogg"
	MediaTypeAudioOpus    MediaType = "audio/opus"
	MediaTypeVideoMp4     MediaType = "video/mp4"
	MediaTypeVideo3gpp    MediaType = "video/3gpp"
	MediaTypeDocumentDoc  MediaType = "application/msword"
	MediaTypeDocumentDocx MediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
	MediaTypeDocumentPdf  MediaType = "application/pdf"
	MediaTypeDocumentPpt  MediaType = "application/vnd.ms-powerpoint"
	MediaTypeDocumentPptx MediaType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
	MediaTypeDocumentXls  MediaType = "application/vnd.ms-excel"
	MediaTypeDocumentXlsx MediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
	MediaTypeDocumentZip  MediaType = "application/zip"
	MediaTypeDocumentRar  MediaType = "application/vnd.rar"
)

All media types extensions which are supported by facebook whatsapp business, please follow the link https://developers.facebook.com/docs/whatsapp/api/media/ for reference on supported media types

type MessageResponse

type MessageResponse struct {
	Messages []struct {
		ID string `json:"id"`
	} `json:"messages"`
	Meta Meta
}

func (*MessageResponse) GetId

func (m *MessageResponse) GetId() (string, error)

type MessageType

type MessageType string
const (
	MessageTypeText          MessageType = "text"
	MessageTypeImage         MessageType = "image"
	MessageTypeAudio         MessageType = "audio"
	MessageTypeVideo         MessageType = "video"
	MessageTypeDocument      MessageType = "document"
	MessageTypeTemplateText  MessageType = "hsm"
	MessageTypeTemplateMedia MessageType = "template"
	MessageTypeContact       MessageType = "contacts"
	MessageTypeLocation      MessageType = "location"
	MessageTypeSticker       MessageType = "sticker"
)

All the available message type supported by Whatsapp

type Meta

type Meta struct {
	Version   string `json:"version"`
	APIStatus string `json:"api_status"`
}

type Provider

type Provider struct {
	Name string `json:"name"`
}

type Text

type Text struct {
	Body string `json:"body"`
}

type WAMessage

type WAMessage struct {
	To            int          `json:"to" validate:"required"`
	Type          string       `json:"type" validate:"required"`
	RecipientType string       `json:"recipient_type"`
	PreviewURL    bool         `json:"preview_url,omitempty"`
	Caption       string       `json:"caption,omitempty"`
	Text          Text         `json:"text,omitempty"`
	Image         MediaMessage `json:"image,omitempty"`
	Audio         MediaMessage `json:"audio,omitempty"`
	Video         MediaMessage `json:"video,omitempty"`
	Document      MediaMessage `json:"document,omitempty"`
}

WAMessage defines all the message formats and it's values which will further be process by intermediate functions to send the request to whatsapp

type WhatsappError

type WhatsappError struct {
	Meta   Meta `json:"meta"`
	Errors []struct {
		Code    int    `json:"code"`
		Title   string `json:"title"`
		Details string `json:"details"`
	} `json:"errors"`
}

func (*WhatsappError) Error

func (w *WhatsappError) Error() string

Jump to

Keyboard shortcuts

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