From 7175756d890e8110ff2ef3a03d57a713a82fc9ba Mon Sep 17 00:00:00 2001 From: crazybolillo Date: Wed, 4 Feb 2026 22:07:45 -0600 Subject: [PATCH] feat: support location messages Both inbound (webhook) and outbound location messages are supported. --- message/location.go | 34 ++++++++++++++++++++++++++++++++++ message/message.go | 1 + webhook/webhook.go | 8 ++++++++ 3 files changed, 43 insertions(+) create mode 100644 message/location.go diff --git a/message/location.go b/message/location.go new file mode 100644 index 0000000..b6477c1 --- /dev/null +++ b/message/location.go @@ -0,0 +1,34 @@ +package message + +// Location represents a WhatsApp location message. +// See: https://developers.facebook.com/documentation/business-messaging/whatsapp/messages/location-messages/ +type Location struct { + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Name *string `json:"name,omitempty"` + Address *string `json:"address,omitempty"` +} + +// NewLocationOpts for creating a new location message. +type NewLocationOpts struct { + Latitude float64 + Longitude float64 + Name *string + Address *string +} + +// NewLocation creates a new WhatsApp location message. +func NewLocation(to string, opts NewLocationOpts) Envelope { + return Envelope{ + MessagingProduct: "whatsapp", + RecipientType: "individual", + To: to, + Type: "location", + Location: &Location{ + Latitude: opts.Latitude, + Longitude: opts.Longitude, + Name: opts.Name, + Address: opts.Address, + }, + } +} diff --git a/message/message.go b/message/message.go index c368cf3..9e90695 100644 --- a/message/message.go +++ b/message/message.go @@ -10,6 +10,7 @@ type Envelope struct { Interactive *Interactive `json:"interactive,omitempty"` Document *Document `json:"document,omitempty"` Sticker *Sticker `json:"sticker,omitempty"` + Location *Location `json:"location,omitempty"` Status string `json:"status,omitempty"` TypingIndicator *TypingIndicator `json:"typing_indicator,omitempty"` MessageID string `json:"message_id,omitempty"` diff --git a/webhook/webhook.go b/webhook/webhook.go index 98c64d6..48e881b 100644 --- a/webhook/webhook.go +++ b/webhook/webhook.go @@ -44,6 +44,7 @@ type Message struct { Context *Context `json:"context"` Text Text `json:"text"` Interactive Interactive `json:"interactive"` + Location Location `json:"location"` } type Text struct { @@ -56,6 +57,13 @@ type Interactive struct { ButtonReply *ButtonReply `json:"button_reply,omitempty"` } +type Location struct { + Address string `json:"address"` + Latitude string `json:"latitude"` + Longitude string `json:"longitude"` + Name string `json:"name"` +} + type NfmReply struct { Name string `json:"name"` ResponseJson string `json:"response_json"`