viber

package
v0.0.0-...-94dcbd2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is used to work with Viber messages.

func NewClient

func NewClient(apiKey string) *Client

NewClient creates new Viber client instance.

func (*Client) GetMessageStatus

func (client *Client) GetMessageStatus(messageId int64) (*MessageReceipt, error)

GetMessageStatus returns Viber message status.

func (*Client) SendMessage

func (client *Client) SendMessage(message *Message) (int64, error)

SendMessage sends Viber message.

type Error

type Error struct {
	Name    string `json:"name"`    // Error name
	Message string `json:"message"` // Error message
	Code    int    `json:"code"`    // Error code
	Status  int    `json:"status"`  // Error status
}

Error represents error which may occur while working with Viber messages.

func (Error) Error

func (e Error) Error() string

Error implements error interface.

type Message

type Message struct {
	Sender         string            `json:"source_addr"`      // Sender is a message sender (from whom message is sent).
	Receiver       string            `json:"destination_addr"` // Receiver is a message receiver (to whom message is sent).
	MessageType    MessageType       `json:"message_type"`     // Message type is a message type.
	Text           string            `json:"text"`             // Text is a message in the UTF8 format.
	ImageUrl       string            `json:"image"`            // ImageUrl is URL of an image for promotional message with button caption and button action.
	ButtonCaption  string            `json:"button_caption"`   // ButtonCaption is a button caption in the UTF8 format.
	ButtonAction   string            `json:"button_action"`    // ButtonAction is an URL for transition when the button is pressed.
	SourceType     MessageSourceType `json:"source_type"`      // SourceType is a message sending procedure.
	CallbackUrl    string            `json:"callback_url"`     // CallbackUrl is an URL for message status callback.
	ValidityPeriod int               `json:"validity_period"`  // ValidityPeriod is a life time of a message (in seconds).
}

Message represents a Viber message.

func NewMessage

func NewMessage() *Message

NewMessage creates new Message.

func (*Message) SetButtonAction

func (m *Message) SetButtonAction(buttonAction string) *Message

SetButtonAction sets button action (an URL for transition when the button is pressed).

func (*Message) SetButtonCaption

func (m *Message) SetButtonCaption(buttonCaption string) *Message

SetButtonCaption sets button caption.

func (*Message) SetCallbackUrl

func (m *Message) SetCallbackUrl(callbackUrl string) *Message

SetCallbackUrl sets callback URL (an URL for message status callback).

func (*Message) SetImageUrl

func (m *Message) SetImageUrl(imageUrl string) *Message

SetImageUrl sets image url for promotional message with button caption and button action.

func (*Message) SetMessageType

func (m *Message) SetMessageType(messageType MessageType) *Message

SetMessageType sets message type.

func (*Message) SetReceiver

func (m *Message) SetReceiver(receiver string) *Message

SetReceiver sets message receiver.

func (*Message) SetSender

func (m *Message) SetSender(sender string) *Message

SetSender sets message sender.

func (*Message) SetSourceType

func (m *Message) SetSourceType(sourceType MessageSourceType) *Message

SetSourceType sets message source type (sending procedure).

func (*Message) SetText

func (m *Message) SetText(text string) *Message

SetText sets message text.

func (*Message) SetValidityPeriod

func (m *Message) SetValidityPeriod(validityPeriod int) *Message

SetValidityPeriod sets message validity period (life time of a message, in seconds).

type MessageReceipt

type MessageReceipt struct {
	MessageId int64         `json:"message_id"` // Id of the Viber message which status should be got (sent in the last 5 days).
	Status    MessageStatus `json:"status"`     // Viber message status
}

MessageReceipt represents Id and status of the particular Viber message.

type MessageSourceType

type MessageSourceType uint16

MessageSourceType represents message sending procedure.

const (
	Promotional MessageSourceType = iota + 1
	Transactional
)

type MessageStatus

type MessageStatus uint16

MessageStatus represents Viber message status.

const (
	Sent MessageStatus = iota
	Delivered
	ErrorStatus
	Rejected
	Undelivered
	Pending
	Unknown = iota + 20
)

func (MessageStatus) String

func (s MessageStatus) String() string

String returns the message status description.

type MessageType

type MessageType uint16

MessageType represents a Viber message type.

const (
	TextOnly            MessageType = 106
	TextImageButton     MessageType = 108
	TextOnly2Way        MessageType = 206
	TextImageButton2Way MessageType = 208
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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