@@ -9,9 +9,19 @@ import (
9
9
)
10
10
11
11
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.
14
22
messagesPath = "messages"
23
+
24
+ // webhooksPath is the path for the Webhook resource, relative to apiRoot.
15
25
webhooksPath = "webhooks"
16
26
)
17
27
@@ -71,7 +81,13 @@ type MessagesCount struct {
71
81
type ConversationStatus string
72
82
73
83
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.
75
91
ConversationStatusArchived ConversationStatus = "archived"
76
92
)
77
93
@@ -101,29 +117,47 @@ type Message struct {
101
117
UpdatedDatetime time.Time
102
118
}
103
119
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
117
121
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
+ )
126
158
159
+ // MessageContent holds a message's actual content. Only one field can be set
160
+ // per request.
127
161
type MessageContent struct {
128
162
Audio * Audio `json:"audio,omitempty"`
129
163
HSM * HSM `json:"hsm,omitempty"`
@@ -143,77 +177,87 @@ type File Media
143
177
type Image Media
144
178
type Video Media
145
179
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.
146
185
type HSM struct {
147
186
Namespace string `json:"namespace"`
148
187
TemplateName string `json:"templateName"`
149
188
Language * HSMLanguage `json:"language"`
150
189
LocalizableParameters []* HSMLocalizableParameter `json:"params"`
151
190
}
152
191
192
+ // HSMLanguage is used to set the message's locale.
153
193
type HSMLanguage struct {
154
194
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"`
156
199
}
157
200
201
+ // HSMLanguagePolicy sets how the provided language is enforced.
158
202
type HSMLanguagePolicy string
159
203
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.
160
219
type HSMLocalizableParameter struct {
161
220
Default string `json:"default"`
162
221
Currency * HSMLocalizableParameterCurrency `json:"currency,omitempty"`
163
222
DateTime * time.Time `json:"dateTime,omitempty"`
164
223
}
165
224
166
225
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"`
170
228
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
+ }
175
233
176
234
type Location struct {
177
235
Latitude float32 `json:"latitude"`
178
236
Longitude float32 `json:"longitude"`
179
237
}
180
238
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
+ }
206
252
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
+ }
217
261
218
262
type WebhookEvent string
219
263
@@ -224,7 +268,7 @@ const (
224
268
WebhookEventMessageUpdated WebhookEvent = "message.updated"
225
269
)
226
270
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,
228
272
// prefix the path with the Conversation API's root. This ensures the client
229
273
// doesn't "handle" this for us: by default, it uses the REST API.
230
274
func request (c * messagebird.Client , v interface {}, method , path string , data interface {}) error {
0 commit comments