Skip to content

Commit 91312a9

Browse files
committed
Add more docs and reorder struct definitions
1 parent 0de3c3e commit 91312a9

File tree

1 file changed

+112
-68
lines changed

1 file changed

+112
-68
lines changed

conversation/api.go

Lines changed: 112 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@ import (
99
)
1010

1111
const (
12-
apiRoot = "https://conversations.messagebird.com/v1"
13-
path = "conversations"
12+
// apiRoot is the absolute URL of the Converstations API. All paths are
13+
// relative to apiRoot (e.g.
14+
// https://conversations.messagebird.com/v1/webhooks).
15+
apiRoot = "https://conversations.messagebird.com/v1"
16+
17+
// path is the path for the Conversation resource, relative to apiRoot.
18+
path = "conversations"
19+
20+
// messagesPath is the path for the Message resource, relative to apiRoot
21+
// and path.
1422
messagesPath = "messages"
23+
24+
// webhooksPath is the path for the Webhook resource, relative to apiRoot.
1525
webhooksPath = "webhooks"
1626
)
1727

@@ -71,7 +81,13 @@ type MessagesCount struct {
7181
type ConversationStatus string
7282

7383
const (
74-
ConversationStatusActive ConversationStatus = "active"
84+
// ConversationStatusActive is returned when the Conversation is active.
85+
// Only one active conversation can ever exist for a given contact.
86+
ConversationStatusActive ConversationStatus = "active"
87+
88+
// ConversationStatusArchived is returned when the Conversation is
89+
// archived. When this is the case, a new Conversation is created when a
90+
// message is received from a contact.
7591
ConversationStatusArchived ConversationStatus = "archived"
7692
)
7793

@@ -101,29 +117,47 @@ type Message struct {
101117
UpdatedDatetime time.Time
102118
}
103119

104-
type WebhookList struct {
105-
Offset int
106-
Limit int
107-
Count int
108-
TotalCount int
109-
Links struct {
110-
First string
111-
Previous string
112-
Next string
113-
Last string
114-
}
115-
Items []*Webhook
116-
}
120+
type MessageDirection string
117121

118-
type Webhook struct {
119-
ID string
120-
ChannelID string
121-
Events []WebhookEvent
122-
URL string
123-
CreatedDatetime time.Time
124-
UpdatedDatetime time.Time
125-
}
122+
const (
123+
// MessageDirectionReceived indicates an inbound message received from the customer.
124+
MessageDirectionReceived MessageDirection = "received"
125+
126+
// MessageDirectionSent indicates an outbound message sent from the API.
127+
MessageDirectionSent MessageDirection = "sent"
128+
)
129+
130+
// MessageStatus is a field set by the API. It indicates what the state of the
131+
// message is, e.g. whether it has been successfully delivered or read.
132+
type MessageStatus string
133+
134+
const (
135+
MessageStatusDeleted MessageStatus = "deleted"
136+
MessageStatusDelivered MessageStatus = "delivered"
137+
MessageStatusFailed MessageStatus = "failed"
138+
MessageStatusPending MessageStatus = "pending"
139+
MessageStatusRead MessageStatus = "read"
140+
MessageStatusReceived MessageStatus = "received"
141+
MessageStatusSent MessageStatus = "sent"
142+
MessageStatusUnsupported MessageStatus = "unsupported"
143+
)
144+
145+
// MessageType indicates what kind of content a Message has, e.g. audio or
146+
// text.
147+
type MessageType string
148+
149+
const (
150+
MessageTypeAudio MessageType = "audio"
151+
MessageTypeFile MessageType = "file"
152+
MessageTypeHSM MessageType = "hsm"
153+
MessageTypeImage MessageType = "image"
154+
MessageTypeLocation MessageType = "location"
155+
MessageTypeText MessageType = "text"
156+
MessageTypeVideo MessageType = "video"
157+
)
126158

159+
// MessageContent holds a message's actual content. Only one field can be set
160+
// per request.
127161
type MessageContent struct {
128162
Audio *Audio `json:"audio,omitempty"`
129163
HSM *HSM `json:"hsm,omitempty"`
@@ -143,77 +177,87 @@ type File Media
143177
type Image Media
144178
type Video Media
145179

180+
// HSM is a pre-approved, reusable message template required when messaging
181+
// over WhatsApp. It allows you to just send the required parameter values
182+
// instead of the full message. It also allows for localization of the message
183+
// and decreases the possibility of being blocked on the first contact as the
184+
// message is pre-approved by WhatsApp.
146185
type HSM struct {
147186
Namespace string `json:"namespace"`
148187
TemplateName string `json:"templateName"`
149188
Language *HSMLanguage `json:"language"`
150189
LocalizableParameters []*HSMLocalizableParameter `json:"params"`
151190
}
152191

192+
// HSMLanguage is used to set the message's locale.
153193
type HSMLanguage struct {
154194
Policy HSMLanguagePolicy `json:"policy"`
155-
Code string `json:"code"`
195+
196+
// Code can be both language and language_locale formats (e.g. en and
197+
// en_US).
198+
Code string `json:"code"`
156199
}
157200

201+
// HSMLanguagePolicy sets how the provided language is enforced.
158202
type HSMLanguagePolicy string
159203

204+
const (
205+
// HSMLanguagePolicyFallback will deliver the message template in the
206+
// user's device language. If the settings can't be found on the user's
207+
// device the fallback language is used.
208+
HSMLanguagePolicyFallback HSMLanguagePolicy = "fallback"
209+
210+
// HSMLanguagePolicyDeterministic will deliver the message template
211+
// exactly in the language and locale asked for.
212+
HSMLanguagePolicyDeterministic HSMLanguagePolicy = "deterministic"
213+
)
214+
215+
// HSMLocalizableParameter are used to replace the placeholders in the message
216+
// template. They will be localized by WhatsApp. Default values are used when
217+
// localization fails. Default is required. Additionally, currency OR DateTime
218+
// may be present in a request.
160219
type HSMLocalizableParameter struct {
161220
Default string `json:"default"`
162221
Currency *HSMLocalizableParameterCurrency `json:"currency,omitempty"`
163222
DateTime *time.Time `json:"dateTime,omitempty"`
164223
}
165224

166225
type HSMLocalizableParameterCurrency struct {
167-
Code string `json:"currencyCode"`
168-
Amount int64 `json:"amount"`
169-
}
226+
// Code is the currency code in ISO 4217 format.
227+
Code string `json:"currencyCode"`
170228

171-
const (
172-
HSMLanguagePolicyFallback HSMLanguagePolicy = "fallback"
173-
HSMLanguagePolicyDeterministic HSMLanguagePolicy = "deterministic"
174-
)
229+
// Amount is the total amount, including cents, multiplied by 1000. E.g.
230+
// 12.34 become 12340.
231+
Amount int64 `json:"amount"`
232+
}
175233

176234
type Location struct {
177235
Latitude float32 `json:"latitude"`
178236
Longitude float32 `json:"longitude"`
179237
}
180238

181-
// MessageType indicates what kind of content a Message has, e.g. audio or
182-
// text.
183-
type MessageType string
184-
185-
const (
186-
MessageTypeAudio MessageType = "audio"
187-
MessageTypeFile MessageType = "file"
188-
MessageTypeHSM MessageType = "hsm"
189-
MessageTypeImage MessageType = "image"
190-
MessageTypeLocation MessageType = "location"
191-
MessageTypeText MessageType = "text"
192-
MessageTypeVideo MessageType = "video"
193-
)
194-
195-
type MessageDirection string
196-
197-
const (
198-
// MessageDirectionReceived indicates an inbound message received from the customer.
199-
MessageDirectionReceived MessageDirection = "received"
200-
201-
// MessageDirectionSent indicates an outbound message sent from the API.
202-
MessageDirectionSent MessageDirection = "sent"
203-
)
204-
205-
type MessageStatus string
239+
type WebhookList struct {
240+
Offset int
241+
Limit int
242+
Count int
243+
TotalCount int
244+
Links struct {
245+
First string
246+
Previous string
247+
Next string
248+
Last string
249+
}
250+
Items []*Webhook
251+
}
206252

207-
const (
208-
MessageStatusDeleted MessageStatus = "deleted"
209-
MessageStatusDelivered MessageStatus = "delivered"
210-
MessageStatusFailed MessageStatus = "failed"
211-
MessageStatusPending MessageStatus = "pending"
212-
MessageStatusRead MessageStatus = "read"
213-
MessageStatusReceived MessageStatus = "received"
214-
MessageStatusSent MessageStatus = "sent"
215-
MessageStatusUnsupported MessageStatus = "unsupported"
216-
)
253+
type Webhook struct {
254+
ID string
255+
ChannelID string
256+
Events []WebhookEvent
257+
URL string
258+
CreatedDatetime time.Time
259+
UpdatedDatetime time.Time
260+
}
217261

218262
type WebhookEvent string
219263

@@ -224,7 +268,7 @@ const (
224268
WebhookEventMessageUpdated WebhookEvent = "message.updated"
225269
)
226270

227-
// request does the exact same thign as Client.Request. It does, however,
271+
// request does the exact same thing as Client.Request. It does, however,
228272
// prefix the path with the Conversation API's root. This ensures the client
229273
// doesn't "handle" this for us: by default, it uses the REST API.
230274
func request(c *messagebird.Client, v interface{}, method, path string, data interface{}) error {

0 commit comments

Comments
 (0)