From 6d0aa90aaeef4e74ce3b6a0a89454c67f15129f1 Mon Sep 17 00:00:00 2001 From: Daniel Fischer Date: Mon, 25 Mar 2019 11:48:35 -0700 Subject: [PATCH] Get NLP --- message.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/message.go b/message.go index 0a44ef1..37766e1 100644 --- a/message.go +++ b/message.go @@ -1,6 +1,9 @@ package messenger -import "time" +import ( + "encoding/json" + "time" +) // Message represents a Facebook messenger message. type Message struct { @@ -25,6 +28,9 @@ type Message struct { Attachments []Attachment `json:"attachments"` // Selected quick reply QuickReply *QuickReply `json:"quick_reply,omitempty"` + // Entities for NLP + // https://developers.facebook.com/docs/messenger-platform/built-in-nlp/ + NLP json.RawMessage `json:"nlp"` } // Delivery represents a the event fired when Facebook delivers a message to the @@ -84,3 +90,9 @@ func (d Delivery) Watermark() time.Time { func (r Read) Watermark() time.Time { return time.Unix(r.RawWatermark/int64(time.Microsecond), 0) } + +// GetNLP simply unmarshals the NLP entities to the given struct and returns +// an error if it's not possible +func (m *Message) GetNLP(i interface{}) error { + return json.Unmarshal(m.NLP, &i) +}