Skip to content

Commit 69570d3

Browse files
authored
Merge pull request #95 from messagebird/add-shorturls-param-to-message
Add support for the shortenUrls parameter in message
2 parents cc69128 + 16dfc01 commit 69570d3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

sms/message.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// Is only used when a binary or premium message is sent.
1515
type TypeDetails map[string]interface{}
1616

17-
// Message struct represents a message at MessageBird.com
17+
// Message struct represents a message at messagebird.com.
1818
type Message struct {
1919
ID string
2020
HRef string
@@ -54,6 +54,7 @@ type Params struct {
5454
DataCoding string
5555
ReportURL string
5656
ScheduledDatetime time.Time
57+
ShortenURLs bool
5758
}
5859

5960
// ListParams provides additional message list options.
@@ -79,6 +80,7 @@ type messageRequest struct {
7980
MClass int `json:"mclass,omitempty"`
8081
ReportURL string `json:"reportUrl,omitempty"`
8182
ScheduledDatetime string `json:"scheduledDatetime,omitempty"`
83+
ShortenURLs bool `json:"shortenUrls"`
8284
}
8385

8486
// path represents the path to the Message resource.
@@ -94,7 +96,7 @@ func Read(c *messagebird.Client, id string) (*Message, error) {
9496
return message, nil
9597
}
9698

97-
// Cancel sending Scheduled Sms
99+
// Cancel sending Scheduled Sms.
98100
func Delete(c *messagebird.Client, id string) (*Message, error) {
99101
message := &Message{}
100102
if err := c.Request(message, http.MethodDelete, path+"/"+id, nil); err != nil {
@@ -172,6 +174,7 @@ func requestDataForMessage(originator string, recipients []string, body string,
172174
request.TypeDetails = params.TypeDetails
173175
request.DataCoding = params.DataCoding
174176
request.ReportURL = params.ReportURL
177+
request.ShortenURLs = params.ShortenURLs
175178

176179
return request, nil
177180
}

sms/message_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ func TestRequestDataForMessage(t *testing.T) {
350350
TypeDetails: nil,
351351
DataCoding: "unicode",
352352
ScheduledDatetime: currentTime,
353+
ShortenURLs: true,
353354
}
354355

355356
request, err := requestDataForMessage("MSGBIRD", []string{"31612345678"}, "MyBody", messageParams)
@@ -387,5 +388,7 @@ func TestRequestDataForMessage(t *testing.T) {
387388
if request.ScheduledDatetime != messageParams.ScheduledDatetime.Format(time.RFC3339) {
388389
t.Errorf("Unexepcted scheduled date time: %s, expected: %s", request.ScheduledDatetime, messageParams.ScheduledDatetime.Format(time.RFC3339))
389390
}
390-
391+
if !request.ShortenURLs {
392+
t.Errorf("Unexpected shorten URL flag: %v, expected: true", request.ShortenURLs)
393+
}
391394
}

0 commit comments

Comments
 (0)