Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorStatus(e interface{}) int
- type Account
- type ActionType
- type Button
- func (b *Button) BgMediaGIF(gifURL string, loop bool) *Button
- func (b *Button) BgMediaPicture(picURL string) *Button
- func (b *Button) SetBgColor(hex string) *Button
- func (b *Button) SetSilent() *Button
- func (b *Button) SetTextOpacity(o int8) *Button
- func (b *Button) TextHAlignCenter() *Button
- func (b *Button) TextHAlignLeft() *Button
- func (b *Button) TextHAlignRight() *Button
- func (b *Button) TextSizeLarge() *Button
- func (b *Button) TextSizeMedium() *Button
- func (b *Button) TextSizeRegular() *Button
- func (b *Button) TextSizeSmall() *Button
- func (b *Button) TextVAlignBottom() *Button
- func (b *Button) TextVAlignMiddle() *Button
- func (b *Button) TextVAlignTop() *Button
- type Contact
- type ContactMessage
- type Error
- type FailedResponse
- type FileMessage
- type Keyboard
- type Member
- type Message
- type MessageType
- type PictureMessage
- type RichMedia
- type RichMediaMessage
- type Sender
- type TextHAlign
- type TextMessage
- type TextSize
- type TextVAlign
- type Timestamp
- type URLMessage
- type User
- type UserDetails
- type UserOnline
- type Viber
- func (v *Viber) AccountInfo() (Account, error)
- func (v *Viber) NewButton(cols, rows int, typ ActionType, actionBody string, text, image string) *Button
- func (v *Viber) NewFileMessage(media string, size int, fileName string) *FileMessage
- func (v *Viber) NewImageButton(cols, rows int, typ ActionType, actionBody string, image string) *Button
- func (v *Viber) NewKeyboard(bgcolor string, defaultHeight bool) *Keyboard
- func (v *Viber) NewPictureMessage(msg string, url string, thumbURL string) *PictureMessage
- func (v *Viber) NewRichMediaMessage(cols, rows int, bgColor string) *RichMediaMessage
- func (v *Viber) NewTextButton(cols, rows int, t ActionType, actionBody, text string) *Button
- func (v *Viber) NewTextMessage(msg string) *TextMessage
- func (v *Viber) NewURLMessage(msg string, url string) *URLMessage
- func (v *Viber) PostData(url string, i interface{}) ([]byte, error)
- func (v *Viber) SendBroadcastMessage(to []string, m Message) (msgToken uint64, err error)
- func (v *Viber) SendMessage(to string, m Message) (msgToken uint64, err error)
- func (v *Viber) SendPictureMessage(receiver string, msg string, url string, thumbURL string) (token uint64, err error)
- func (v *Viber) SendPublicMessage(from string, m Message) (msgToken uint64, err error)
- func (v *Viber) SendTextMessage(receiver string, msg string) (msgToken uint64, err error)
- func (v *Viber) SendURLMessage(receiver string, msg string, url string) (msgToken uint64, err error)
- func (v *Viber) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (v *Viber) SetRequestTimeout(t time.Duration)
- func (v *Viber) SetWebhook(url string, eventTypes []string) (WebhookResp, error)
- func (v *Viber) UserDetails(id string) (UserDetails, error)
- func (v *Viber) UserOnline(ids []string) ([]UserOnline, error)
- type VideoMessage
- type WebhookReq
- type WebhookResp
- type WebhookVerify
Constants ¶
const ( Small = TextSize("small") Medium = TextSize("medium") Large = TextSize("large") Regular = TextSize("regular") )
TextSize values
const ( Reply = ActionType("reply") OpenURL = ActionType("open-url") None = ActionType("none") )
ActionType values
const ( Top = TextVAlign("top") Middle = TextVAlign("middle") Bottom = TextVAlign("bottom") )
TextVAlign values
const ( Left = TextHAlign("left") Center = TextHAlign("center") Right = TextHAlign("right") )
TextHAlign values
const ( TypeTextMessage = MessageType("text") TypeURLMessage = MessageType("url") TypePictureMessage = MessageType("picture") TypeVideoMessage = MessageType("video") TypeFileMessage = MessageType("file") TypeLocationMessage = MessageType("location") TypeContactMessage = MessageType("contact") TypeStickerMessage = MessageType("sticker") TypeRichMediaMessage = MessageType("rich_media") )
Message types
Variables ¶
var ( // Log errors, set to logger if you want to log package activities and errors Log = log.New(ioutil.Discard, "Viber >>", 0) )
Functions ¶
func ErrorStatus ¶
func ErrorStatus(e interface{}) int
ErrorStatus code of Viber error, returns -1 if e is not Viber error
Types ¶
type Account ¶
type Account struct { Status int `json:"status"` StatusMessage string `json:"status_message"` ID string `json:"id"` Name string `json:"name"` URI string `json:"uri"` Icon string `json:"icon"` Background string `json:"background"` Category string `json:"category"` Subcategory string `json:"subcategory"` Location struct { Lon float64 `json:"lon"` Lat float64 `json:"lat"` } `json:"location"` Country string `json:"country"` Webhook string `json:"webhook"` EventTypes []string `json:"event_types"` SubscribersCount int `json:"subscribers_count"` Members []Member `json:"members"` }
Account details
type Button ¶
type Button struct { Columns int `json:"Columns"` Rows int `json:"Rows"` ActionType ActionType `json:"ActionType"` ActionBody string `json:"ActionBody"` Image string `json:"Image,omitempty"` Text string `json:"Text,omitempty"` TextSize TextSize `json:"TextSize,omitempty"` TextVAlign TextVAlign `json:"TextVAlign,omitempty"` TextHAlign TextHAlign `json:"TextHAlign,omitempty"` TextOpacity int8 `json:"TextOpacity,omitempty"` TextBgGradientColor string `json:"TextBgGradientColor,omitempty"` BgColor string `json:"BgColor,omitempty"` BgMediaType string `json:"BgMediaType,omitempty"` BgMedia string `json:"BgMedia,omitempty"` BgLoop bool `json:"BgLoop,omitempty"` Silent bool `json:"Silent,omitempty"` }
Button for carousel and keyboards
func (*Button) BgMediaGIF ¶
BgMediaGIF set BgMedia to GIF with loop param
func (*Button) BgMediaPicture ¶
BgMediaPicture to set background to PNG or JPG. Use BgMediaGIF for GIF background
func (*Button) SetTextOpacity ¶
SetTextOpacity 0-100
func (*Button) TextHAlignCenter ¶
TextHAlignCenter horizontaly center text
func (*Button) TextHAlignLeft ¶
TextHAlignLeft horizontaly center text left
func (*Button) TextHAlignRight ¶
TextHAlignRight horizontaly align text right
func (*Button) TextSizeLarge ¶
TextSizeLarge for button text
func (*Button) TextSizeMedium ¶
TextSizeMedium for button text, synonym to Regular
func (*Button) TextSizeRegular ¶
TextSizeRegular for button text, synonym to Medium
func (*Button) TextSizeSmall ¶
TextSizeSmall for button text
func (*Button) TextVAlignBottom ¶
TextVAlignBottom vertically align text to the bottom
func (*Button) TextVAlignMiddle ¶
TextVAlignMiddle vertically align text to the middle
func (*Button) TextVAlignTop ¶
TextVAlignTop vertically align text to the top
type ContactMessage ¶
type ContactMessage struct { TextMessage Contact Contact `json:"contact"` }
ContactMessage structure
type Error ¶
type Error struct { Status int StatusMessage string FailedList []FailedResponse }
Error from Viber
type FailedResponse ¶
type FailedResponse struct { Receiver string `json:"receiver"` Status int `json:"status"` StatusMessage string `json:"status_message"` }
FailedList from Viber
func ErrorFailedList ¶
func ErrorFailedList(e interface{}) []FailedResponse
type FileMessage ¶
type FileMessage struct { TextMessage Media string `json:"media"` Size int `json:"size"` FileName string `json:"file_name"` }
FileMessage structure
type Keyboard ¶
type Keyboard struct { Type string `json:"Type"` DefaultHeight bool `json:"DefaultHeight,omitempty"` BgColor string `json:"BgColor,omitempty"` Buttons []Button `json:"Buttons"` }
Keyboard struct
type Member ¶
type Member struct { ID string `json:"id"` Name string `json:"name"` Avatar string `json:"avatar"` Role string `json:"role"` }
Member of account details
type Message ¶
type Message interface { SetReceiver(r string) SetBroadcastList(bl []string) SetFrom(from string) SetKeyboard(k *Keyboard) }
Message interface for all types of viber messages
type PictureMessage ¶
type PictureMessage struct { TextMessage Media string `json:"media"` Thumbnail string `json:"thumbnail,omitempty"` }
PictureMessage structure
type RichMedia ¶
type RichMedia struct { Type MessageType `json:"Type"` ButtonsGroupColumns int `json:"ButtonsGroupColumns"` ButtonsGroupRows int `json:"ButtonsGroupRows"` BgColor string `json:"BgColor"` Buttons []Button `json:"Buttons"` }
RichMedia for carousel
type RichMediaMessage ¶
type RichMediaMessage struct { AuthToken string `json:"auth_token"` Receiver string `json:"receiver,omitempty"` Type MessageType `json:"type"` MinAPIVersion int `json:"min_api_version"` RichMedia RichMedia `json:"rich_media"` AltText string `json:"alt_text,omitempty"` Keyboard *Keyboard `json:"keyboard,omitempty"` TrackingData string `json:"tracking_data,omitempty"` }
RichMediaMessage / Carousel
func (*RichMediaMessage) AddButton ¶
func (rm *RichMediaMessage) AddButton(b *Button)
AddButton to rich media message
func (*RichMediaMessage) SetFrom ¶
func (rm *RichMediaMessage) SetFrom(from string)
SetFrom to satisfy interface although RichMedia messages can't be sent to publich chat and don't have From
func (*RichMediaMessage) SetKeyboard ¶
func (rm *RichMediaMessage) SetKeyboard(k *Keyboard)
SetKeyboard for text message
func (*RichMediaMessage) SetReceiver ¶
func (rm *RichMediaMessage) SetReceiver(r string)
SetReceiver for RichMedia message
type TextHAlign ¶
type TextHAlign string
TextHAlign for carousel buttons viber.Left viber.Center (default) viber.Middle
type TextMessage ¶
type TextMessage struct { Receiver string `json:"receiver,omitempty"` BroadcastList []string `json:"broadcast_list,omitempty"` From string `json:"from,omitempty"` MinAPIVersion uint `json:"min_api_version,omitempty"` Sender Sender `json:"sender"` Type MessageType `json:"type"` TrackingData string `json:"tracking_data,omitempty"` Text string `json:"text"` Keyboars *Keyboard `json:"keyboard,omitempty"` }
TextMessage for Viber
func (*TextMessage) SetBroadcastList ¶
func (m *TextMessage) SetBroadcastList(bl []string)
SetReceiver for text message
func (*TextMessage) SetFrom ¶
func (m *TextMessage) SetFrom(from string)
SetFrom to text message for public account message
func (*TextMessage) SetKeyboard ¶
func (m *TextMessage) SetKeyboard(k *Keyboard)
SetKeyboard for text message
func (*TextMessage) SetReceiver ¶
func (m *TextMessage) SetReceiver(r string)
SetReceiver for text message
type TextSize ¶
type TextSize string
TextSize for carousel buttons viber.Small viber.Medium (synonym to regular) viber.Large viber.Regular (default)
type TextVAlign ¶
type TextVAlign string
TextVAlign for carousel buttons viber.Top viber.Middle (default) viber.Bottom
type Timestamp ¶
Timestamp struct for easily MarshalJSON/UnmarshalJSON unix timestamp to time.Time
func (*Timestamp) MarshalJSON ¶
MarshalJSON converts golang time to unix timestam number
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON converts unix timestamp to golang time
type URLMessage ¶
type URLMessage struct { TextMessage Media string `json:"media"` }
URLMessage structure
type User ¶
type User struct { ID string `json:"id"` Name string `json:"name"` Avatar string `json:"avatar"` Country string `json:"country"` Language string `json:"language"` PrimaryDeviceOs string `json:"primary_device_os"` APIVersion int `json:"api_version"` ViberVersion string `json:"viber_version"` Mcc int `json:"mcc"` Mnc int `json:"mnc"` DeviceType string `json:"device_type"` }
User struct as part of UserDetails
type UserDetails ¶
type UserDetails struct { Status int `json:"status"` StatusMessage string `json:"status_message"` MessageToken int64 `json:"message_token"` User `json:"user"` }
UserDetails for Viber user
type UserOnline ¶
type UserOnline struct { ID string `json:"id"` OnlineStatus int `json:"online_status"` OnlineStatusMessage string `json:"online_status_message"` LastOnline int64 `json:"last_online,omitempty"` }
UserOnline response struct
type Viber ¶
type Viber struct { AppKey string Sender Sender // event methods ConversationStarted func(v *Viber, u User, conversationType, context string, subscribed bool, token uint64, t time.Time) Message Message func(v *Viber, u User, m Message, token uint64, t time.Time) Subscribed func(v *Viber, u User, token uint64, t time.Time) Unsubscribed func(v *Viber, userID string, token uint64, t time.Time) Delivered func(v *Viber, userID string, token uint64, t time.Time) Seen func(v *Viber, userID string, token uint64, t time.Time) Failed func(v *Viber, userID string, token uint64, descr string, t time.Time) // contains filtered or unexported fields }
Viber app
func New ¶
New returns Viber app with specified app key and default sender You can also create *VIber{} struct directly
func (*Viber) AccountInfo ¶
AccountInfo returns Public chat info https://developers.viber.com/docs/api/rest-bot-api/#get-account-info
func (*Viber) NewButton ¶
func (v *Viber) NewButton(cols, rows int, typ ActionType, actionBody string, text, image string) *Button
NewButton helper function for creating button with text and image
func (*Viber) NewFileMessage ¶
func (v *Viber) NewFileMessage(media string, size int, fileName string) *FileMessage
NewFileMessage for viber
func (*Viber) NewImageButton ¶
func (v *Viber) NewImageButton(cols, rows int, typ ActionType, actionBody string, image string) *Button
NewImageButton helper function for creating image button struct with common params
func (*Viber) NewKeyboard ¶
NewKeyboard struct with attribs init
func (*Viber) NewPictureMessage ¶
func (v *Viber) NewPictureMessage(msg string, url string, thumbURL string) *PictureMessage
NewPictureMessage for viber
func (*Viber) NewRichMediaMessage ¶
func (v *Viber) NewRichMediaMessage(cols, rows int, bgColor string) *RichMediaMessage
NewRichMediaMessage creates new empty carousel message
func (*Viber) NewTextButton ¶
func (v *Viber) NewTextButton(cols, rows int, t ActionType, actionBody, text string) *Button
NewTextButton helper function for creating image button struct with common params
func (*Viber) NewTextMessage ¶
func (v *Viber) NewTextMessage(msg string) *TextMessage
NewTextMessage viber
func (*Viber) NewURLMessage ¶
func (v *Viber) NewURLMessage(msg string, url string) *URLMessage
NewURLMessage creates new message with global sender and common params set
func (*Viber) SendBroadcastMessage ¶
SendMessage to receiver
func (*Viber) SendMessage ¶
SendMessage to receiver
func (*Viber) SendPictureMessage ¶
func (v *Viber) SendPictureMessage(receiver string, msg string, url string, thumbURL string) (token uint64, err error)
SendPictureMessage to receiver, returns message token
func (*Viber) SendPublicMessage ¶
SendPublicMessage from public account
func (*Viber) SendTextMessage ¶
SendTextMessage to reciever, returns message token
func (*Viber) SendURLMessage ¶
func (v *Viber) SendURLMessage(receiver string, msg string, url string) (msgToken uint64, err error)
SendURLMessage to easily send url messages as global sender
func (*Viber) ServeHTTP ¶
func (v *Viber) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP https://developers.viber.com/docs/api/rest-bot-api/#callbacks
func (*Viber) SetRequestTimeout ¶
SetRequestTimeout for sending messages to viber server
func (*Viber) SetWebhook ¶
func (v *Viber) SetWebhook(url string, eventTypes []string) (WebhookResp, error)
SetWebhook for Viber callbacks if eventTypes is nil, all callbacks will be set to webhook if eventTypes is empty []string mandatory callbacks will be set Mandatory callbacks: "message", "subscribed", "unsubscribed" All possible callbacks: "message", "subscribed", "unsubscribed", "delivered", "seen", "failed", "conversation_started"
func (*Viber) UserDetails ¶
func (v *Viber) UserDetails(id string) (UserDetails, error)
UserDetails of user id
func (*Viber) UserOnline ¶
func (v *Viber) UserOnline(ids []string) ([]UserOnline, error)
UserOnline status
type VideoMessage ¶
type VideoMessage struct { TextMessage Media string `json:"media"` Thumbnail string `json:"thumbnail,omitempty"` Size uint `json:"size"` Duration uint `json:"duration,omitempty"` }
VideoMessage structure
type WebhookReq ¶
WebhookReq request
type WebhookResp ¶
type WebhookResp struct { Status int `json:"status"` StatusMessage string `json:"status_message"` EventTypes []string `json:"event_types,omitempty"` }
WebhookResp response
type WebhookVerify ¶
type WebhookVerify struct { Event string `json:"event"` Timestamp uint64 `json:"timestamp"` MessageToken uint64 `json:"message_token"` }
WebhookVerify response