Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added file message support #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions button.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package viber

// Button for carousel and keyboards
type Button struct {
Columns int `json:"Columns"`
Rows int `json:"Rows"`
Columns int `json:"Columns,omitempty"`
Rows int `json:"Rows,omitempty"`
ActionType ActionType `json:"ActionType"`
ActionBody string `json:"ActionBody"`
Image string `json:"Image,omitempty"`
Expand Down
11 changes: 9 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type TextMessage struct {
Type MessageType `json:"type"`
TrackingData string `json:"tracking_data,omitempty"`
Text string `json:"text"`
Keyboars *Keyboard `json:"keyboard,omitempty"`
Keyboard *Keyboard `json:"keyboard,omitempty"`
// "media": "http://www.images.com/img.jpg",
// "thumbnail": "http://www.images.com/thumb.jpg"
// "size": 10000,
Expand All @@ -51,6 +51,13 @@ type URLMessage struct {
Media string `json:"media"`
}

// FileMessage structure
type FileMessage struct {
URLMessage
Size uint `json:"size"`
FileName string `json:"file_name"`
}

// PictureMessage structure
type PictureMessage struct {
TextMessage
Expand Down Expand Up @@ -180,5 +187,5 @@ func (m *TextMessage) SetFrom(from string) {

// SetKeyboard for text message
func (m *TextMessage) SetKeyboard(k *Keyboard) {
m.Keyboars = k
m.Keyboard = k
}
8 changes: 7 additions & 1 deletion viber.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ func (v *Viber) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
go v.Message(v, u, &m, e.MessageToken, e.Timestamp.Time)

case "file":
var m FileMessage
if err := json.Unmarshal(e.Message, &m); err != nil {
Log.Println(err)
return
}
go v.Message(v, u, &m, e.MessageToken, e.Timestamp.Time)
case "contact":
// TODO
case "location":
Expand Down