From ac87668cad9420cc2f5ec0bd56aec0d62a82094b Mon Sep 17 00:00:00 2001 From: Vladislav Polyakov <39828645+polRk@users.noreply.github.com> Date: Thu, 30 Jan 2020 21:03:00 +0300 Subject: [PATCH 1/3] feat: add TODO structures Add Contact and Location structures --- viber.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/viber.go b/viber.go index 71db2a4..1f1160a 100644 --- a/viber.go +++ b/viber.go @@ -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"` @@ -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 From 9097dc4056ab337fb7e9340dd19de7ddaaead46c Mon Sep 17 00:00:00 2001 From: Vladislav Polyakov <39828645+polRk@users.noreply.github.com> Date: Thu, 30 Jan 2020 21:07:12 +0300 Subject: [PATCH 2/3] feat: add contact and location handlers --- viber.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/viber.go b/viber.go index 1f1160a..d4d8573 100644 --- a/viber.go +++ b/viber.go @@ -207,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 } From ca5ab6855517c8bebe1d08e27b68968fac15e04c Mon Sep 17 00:00:00 2001 From: Vladislav Polyakov <39828645+polRk@users.noreply.github.com> Date: Thu, 30 Jan 2020 21:12:22 +0300 Subject: [PATCH 3/3] feat: add message structures --- message.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/message.go b/message.go index 0a7eb33..4677629 100644 --- a/message.go +++ b/message.go @@ -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