wabaapi

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 15 Imported by: 0

README

Gupshup Whatsapp API

This is a small go package that implements types for Gupshup's Messaging API for WhatsApp Business.

For more info see https://www.gupshup.io/developer/docs/bot-platform/guide/whatsapp-api-documentation

Not stable until we reach v1.0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultTimeout = 120 * time.Second

DefaultTimeout is the default timeout for the media server

Functions

This section is empty.

Types

type AccountEventPayload

type AccountEventPayload struct {
	Type    string                 `json:"type"`
	Payload map[string]interface{} `json:"payload"`
}

type Contact

type Contact struct {
	Addresses []struct {
		City        string `json:"city"`
		Country     string `json:"country"`
		CountryCode string `json:"countryCode"`
		State       string `json:"state"`
		Street      string `json:"street"`
		Type        string `json:"type"`
		Zip         string `json:"zip"`
	} `json:"addresses"`
	Emails []struct {
		Email string `json:"email"`
		Type  string `json:"type"`
	} `json:"emails"`
	Ims  []interface{} `json:"ims"`
	Name struct {
		FirstName     string `json:"first_name"`
		FormattedName string `json:"formatted_name"`
		LastName      string `json:"last_name"`
	} `json:"name"`
	Org struct {
		Company string `json:"company"`
	} `json:"org"`
	Phones []struct {
		Phone string `json:"phone"`
		Type  string `json:"type"`
	} `json:"phones"`
	URLs []struct {
		URL  string `json:"url"`
		Type string `json:"type"`
	} `json:"urls"`
}

type Context

type Context struct {
	ID   string `json:"id"`
	GsID string `json:"gsId"`
}

type GCSMediaServer

type GCSMediaServer struct {
	Client     *gcs.Client
	Bucket     string
	PathPrefix string
	URLHost    string
}

func (*GCSMediaServer) GetFile

func (ms *GCSMediaServer) GetFile(requri string) (io.ReadCloser, error)

func (*GCSMediaServer) PutFile

func (ms *GCSMediaServer) PutFile(r io.Reader, contentType string) (string, error)

func (*GCSMediaServer) PutFileWithExt

func (ms *GCSMediaServer) PutFileWithExt(r io.Reader, ext string) (string, error)

type InboundButtonReply

type InboundButtonReply struct {
	Title string `json:"title"`
	ID    string `json:"id"`
	Reply string `json:"reply"`
}

type InboundButtonText

type InboundButtonText string

type InboundListReply

type InboundListReply struct {
	Title        string `json:"title"`
	ID           string `json:"id"`
	Reply        string `json:"reply"`
	PostbackText string `json:"postbackText"`
	Description  string `json:"description"`
}

type InboundLocation

type InboundLocation struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type InboundMedia

type InboundMedia struct {
	Caption     string    `json:"caption"`
	Name        string    `json:"name"`
	URL         string    `json:"url"`
	ContentType string    `json:"contentType"`
	URLExpiry   time.Time `json:"urlExpiry"`
	Type        string    `json:"-"`
}

func (*InboundMedia) UnmarshalJSON

func (media *InboundMedia) UnmarshalJSON(data []byte) error

type InboundMessage

type InboundMessage struct {
	App       string      `json:"app"`
	Timestamp time.Time   `json:"timestamp"`
	Type      string      `json:"type"`
	Payload   interface{} `json:"payload"`
}

func (*InboundMessage) UnmarshalJSON

func (m *InboundMessage) UnmarshalJSON(data []byte) error

type InboundMessagePayload

type InboundMessagePayload struct {
	ID      string      `json:"id"`
	Source  string      `json:"source"`
	Type    string      `json:"type"`
	Payload interface{} `json:"payload"`
}

func (*InboundMessagePayload) UnmarshalJSON

func (msg *InboundMessagePayload) UnmarshalJSON(data []byte) error

type InboundText

type InboundText string

type ListItem

type ListItem struct {
	Title   string           `json:"title"`
	Options []ListItemOption `json:"options"`
}

func (*ListItem) Validate added in v0.2.1

func (li *ListItem) Validate() error

type ListItemOption

type ListItemOption struct {
	Title        string `json:"title"`
	Description  string `json:"description"`
	PostbackText string `json:"postbackText"`
}

func (ListItemOption) MarshalJSON

func (li ListItemOption) MarshalJSON() ([]byte, error)

func (*ListItemOption) Validate added in v0.2.1

func (li *ListItemOption) Validate() error

type ListMessage

type ListMessage struct {
	Title        string     `json:"title"`
	Body         string     `json:"body"`
	MsgID        string     `json:"msgid,omitempty"`
	GlobalButton string     `json:"-"`
	Items        []ListItem `json:"items"`
}

func (ListMessage) MarshalJSON

func (lm ListMessage) MarshalJSON() ([]byte, error)

func (*ListMessage) Validate added in v0.2.1

func (lm *ListMessage) Validate() error

type MediaServer

type MediaServer interface {
	//GetFile returns a file from the media server and its content type
	GetFile(requri string) (io.ReadCloser, string, error)
	//PutFile uploads a file to the media server and returns the path to the file
	PutFile(r io.Reader, contentType string) (string, error)
	//PutFileWithExt uploads a file to the media server and returns the path to the file
	PutFileWithExt(r io.Reader, ext string) (string, error)
}

type MediaServerMedia

type MediaServerMedia struct {
	Server      MediaServer
	Reader      io.ReadCloser
	ContentType string
}

func (*MediaServerMedia) PutFile

func (media *MediaServerMedia) PutFile() (string, error)

type MessageEventPayload added in v0.2.1

type MessageEventPayload struct {
	ID          string          `json:"id"`
	GSID        string          `json:"gsId"`
	Type        string          `json:"type"`
	Destination string          `json:"destination"`
	Payload     json.RawMessage `json:"payload"`
}

func (*MessageEventPayload) GetError added in v0.2.1

func (msgEvent *MessageEventPayload) GetError() error

type OutboundMessage

type OutboundMessage struct {
	Channel        string
	Destination    string
	Source         string
	SourceName     string
	DisablePreview bool
	DoNotValidate  bool
}

OutboundMessage is the basic structure for creating reply messages. Call this structure with the appropriate method to create a reply message. Limited validation is performed on the structure

Example
om := &OutboundMessage{
	Channel:     "whatsapp",
	Destination: "+1234567890",
	Source:      "+15555555555",
	SourceName:  "Our Company",
}

values, err := om.Text("Hello World")
if err != nil {
	panic(err)
}

//Send the message
_, err = http.PostForm("https://gupshupurl", values)
Output:

func (*OutboundMessage) Audio

func (om *OutboundMessage) Audio(url string) (url.Values, error)

Audio creates an audio message

func (*OutboundMessage) AudioMS

func (om *OutboundMessage) AudioMS(media MediaServerMedia) (url.Values, error)

func (*OutboundMessage) Image

func (om *OutboundMessage) Image(originalURL string, previewURL string) (url.Values, error)

Image creates an image message

func (*OutboundMessage) ImageMS

func (om *OutboundMessage) ImageMS(original MediaServerMedia, preview MediaServerMedia) (url.Values, error)

func (*OutboundMessage) ListMessage

func (om *OutboundMessage) ListMessage(lm ListMessage) (url.Values, error)

Creates an interactive list message

func (*OutboundMessage) QuickReplyDocument

func (om *OutboundMessage) QuickReplyDocument(qrd QuickReplyDocument) (url.Values, error)

func (*OutboundMessage) QuickReplyImage

func (om *OutboundMessage) QuickReplyImage(qri QuickReplyImage) (url.Values, error)

func (*OutboundMessage) QuickReplyText

func (om *OutboundMessage) QuickReplyText(text QuickReplyText) (url.Values, error)

func (*OutboundMessage) Text

func (om *OutboundMessage) Text(text string) (url.Values, error)

Text creates a text message

func (*OutboundMessage) Validate

func (om *OutboundMessage) Validate() error

func (*OutboundMessage) Video

func (om *OutboundMessage) Video(url string, caption string) (url.Values, error)

Video creates a video message

func (*OutboundMessage) VideoMS

func (om *OutboundMessage) VideoMS(media MediaServerMedia, caption string) (url.Values, error)

type QuickReplyDocument

type QuickReplyDocument struct {
	MsgID    string `json:"msgid"`
	URL      string `json:"url"`
	Text     string `json:"text"`
	Caption  string `json:"caption"`
	Filename string `json:"filename"`
	Options  []QuickReplyOption
}

func (*QuickReplyDocument) MarshalJSON

func (qrd *QuickReplyDocument) MarshalJSON() ([]byte, error)

type QuickReplyImage

type QuickReplyImage struct {
	MsgID   string
	URL     string
	Text    string
	Caption string
	Options []QuickReplyOption
}

func (*QuickReplyImage) MarshalJSON

func (qri *QuickReplyImage) MarshalJSON() ([]byte, error)

type QuickReplyOption

type QuickReplyOption string

func (*QuickReplyOption) MarshalJSON

func (qro *QuickReplyOption) MarshalJSON() ([]byte, error)

type QuickReplyText

type QuickReplyText struct {
	MsgID   string `json:"msgid"`
	Header  string `json:"header"`
	Text    string `json:"text"`
	Caption string `json:"caption"`
	Options []QuickReplyOption
}

func (*QuickReplyText) MarshalJSON

func (qrt *QuickReplyText) MarshalJSON() ([]byte, error)

type QuickReplyVideo

type QuickReplyVideo struct {
	MsgID   string `json:"msgid"`
	URL     string `json:"url"`
	Text    string `json:"text"`
	Caption string `json:"caption"`
	Options []QuickReplyOption
}

func (*QuickReplyVideo) MarshalJSON

func (qrv *QuickReplyVideo) MarshalJSON() ([]byte, error)

type Sender

type Sender struct {
	Phone       string `json:"phone"`
	Name        string `json:"name"`
	CountryCode string `json:"country_code"`
	DialCode    string `json:"dial_code"`
}

type SystemEventPayload

type SystemEventPayload struct {
	ID             string `json:"id"`
	Status         string `json:"status"`
	ElementName    string `json:"elementName"`
	LanguageCode   string `json:"languageCode"`
	RejectedReason string `json:"rejectedReason"`
}

type UserEventPayload

type UserEventPayload struct {
	Phone string `json:"phone"`
	Type  string `json:"type"`
}

Jump to

Keyboard shortcuts

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