Skip to content
Open
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
30 changes: 30 additions & 0 deletions textMessage.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}