From 4948e7335c1c81434032391fa54a4fdae9105f4b Mon Sep 17 00:00:00 2001 From: virgilio-a-cunha-alb Date: Thu, 30 Oct 2025 15:04:05 +0000 Subject: [PATCH] Fixed TextMessage unmarshal JSON --- textMessage.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/textMessage.go b/textMessage.go index 69830020..1c8fee5b 100644 --- a/textMessage.go +++ b/textMessage.go @@ -1,5 +1,9 @@ package ari +import ( + "encoding/json" +) + // TextMessage needs some verbiage here type TextMessage interface { // Send() sends a text message to an endpoint @@ -25,3 +29,29 @@ type TextMessageVariable struct { Key string `json:"key"` Value string `json:"value"` } + +// UnmarshalJSON parses the data into the TextMessageVariable object +func (t *TextMessageData) UnmarshalJSON(data []byte) error { + // Alias to avoid recursive call + type Alias TextMessageData + aux := &struct { + Variables map[string]string `json:"variables"` + *Alias + }{ + Alias: (*Alias)(t), + } + + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + + // Convert map into slice + for k, v := range aux.Variables { + t.Variables = append(t.Variables, TextMessageVariable{ + Key: k, + Value: v, + }) + } + + return nil +}