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

Add Contact and Location structures #5

Open
wants to merge 3 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
12 changes: 12 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ type VideoMessage struct {
Duration uint `json:"duration,omitempty"`
}

// ContactMessage structure
type ContactMessage struct {
TextMessage
Contact Contact `json:"contact"`
}

// LocationMessage strucutre
type LocationMessage struct {
TextMessage
Location Location `json:"location"`
}

// MessageType for viber messaging
type MessageType string

Expand Down
32 changes: 30 additions & 2 deletions viber.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ type Sender struct {
Avatar string `json:"avatar,omitempty"`
}

// Contact structure
type Contact struct {
Name string `json:"name"`
PhoneNumber string `json:"phone_number"`
}

// Location structure
type Location struct {
Latitude string `json:"lat"`
Longitude string `json:"lon"`
}

type event struct {
Event string `json:"event"`
Timestamp Timestamp `json:"timestamp"`
Expand All @@ -37,6 +49,12 @@ type event struct {
// message event
Sender json.RawMessage `json:"sender,omitempty"`
Message json.RawMessage `json:"message,omitempty"`

// location event
Location json.RawMessage `json:"location,omitempty"`

// contact event
Contact json.RawMessage `json:"contact,omitempty"`
}

// Viber app
Expand Down Expand Up @@ -189,9 +207,19 @@ func (v *Viber) ServeHTTP(w http.ResponseWriter, r *http.Request) {
go v.Message(v, u, &m, e.MessageToken, e.Timestamp.Time)

case "contact":
// TODO
var m ContactMessage
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 "location":
// TODO
var m LocationMessage
if err := json.Unmarshal(e.Message, &m); err != nil {
Log.Println(err)
return
}
go v.Message(v, u, &m, e.MessageToken, e.Timestamp.Time)
default:
return
}
Expand Down