forked from pooranjoyb/cpp-sdk-appwrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessaging.hpp
More file actions
358 lines (327 loc) · 12.9 KB
/
Messaging.hpp
File metadata and controls
358 lines (327 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/// @file Messaging.hpp
/// @brief Provides messaging-related operations (messages, topics, subscribers)
#ifndef MESSAGING_HPP
#define MESSAGING_HPP
#include "Query.hpp"
#include "Utils.hpp"
#include "enums/HttpStatus.hpp"
#include "exceptions/AppwriteException.hpp"
#include <string>
/**
* @class Messaging
* @brief Provides APIs to manage messaging: messages, topics, subscribers.
*/
class Messaging {
public:
/**
* @brief Constructor for Messaging service.
* @param projectId Appwrite project ID
* @param apiKey Appwrite API key
*/
Messaging(const std::string &projectId, const std::string &apiKey);
/**
* @brief List all messages with optional filters.
* @param queries Query parameters for filtering results
* @return JSON string of message list
*/
std::string listMessages(Queries &queries);
/**
* @brief Get a specific message by ID.
* @param messageId ID of the message
* @return JSON string of the message details
*/
std::string getMessages(const std::string &messageId);
/**
* @brief Get details of a topic by ID.
* @param topicId ID of the topic
* @return JSON string of the topic
*/
std::string getTopic(const std::string &topicId);
/**
* @brief List all topics with optional filters.
* @param queries Query parameters for filtering
* @return JSON string of topic list
*/
std::string listTopics(Queries &queries);
/**
* @brief Delete a topic by its ID.
* @param topicId ID of the topic
* @return JSON response
*/
std::string deleteTopic(const std::string &topicId);
/**
* @brief Create a new topic.
* @param topicId Unique topic ID
* @param name Name of the topic
* @param subscribe List of subscriber IDs
* @return JSON response
*/
std::string createTopic(const std::string &topicId, const std::string &name,
const std::vector<std::string> &subscribe);
/**
* @brief Update an existing topic.
* @param topicId ID of the topic to update
* @param name New name for the topic
* @param subscribe Updated list of subscribers (optional)
* @return JSON response
*/
std::string updateTopic(const std::string &topicId, const std::string &name,
const std::vector<std::string> &subscribe = {});
/**
* @brief Get details of a subscriber to a topic.
* @param topicId ID of the topic
* @param subscriberId ID of the subscriber
* @return JSON string of the subscriber
*/
std::string getSubscriber(const std::string &topicId,
const std::string &subscriberId);
/**
* @brief List all subscribers of a topic.
* @param topicId ID of the topic
* @param queries Optional query filters
* @return JSON string of subscriber list
*/
std::string listSubscribers(const std::string &topicId, Queries &queries);
/**
* @brief Delete a subscriber from a topic.
* @param topicId ID of the topic
* @param subscriberId ID of the subscriber to remove
* @return JSON response
*/
std::string deleteSubscribers(const std::string &topicId,
const std::string &subscriberId);
/**
* @brief Add a subscriber to a topic.
* @param topicId ID of the topic
* @param name Name of the subscriber
* @param targetId Target platform/device
* @param subscriberId Unique ID for the subscriber
* @return JSON response
*/
std::string createSubscribers(const std::string &topicId,
const std::string &name,
const std::string &targetId,
const std::string &subscriberId);
/**
* @brief Creates a new push notification message.
*
* Sends a push notification to specified users, topics, or both.
*
* @param messageId A unique Id for the message.
* @param title Title of the push notification.
* @param body Body content of the push notification.
* @param topicId A list of topic IDs to which the notification should be
* sent.
* @param userId A list of user IDs to which the notification should be
* sent.
* @param draft If true, saves the message as a draft.
*
* @return JSON response.
*/
std::string createPush(const std::string &messageId,
const std::string &title, const std::string &body,
const std::vector<std::string> &topicId = {},
const std::vector<std::string> &userId = {},
bool draft = false);
/**
* @brief Create a new email message.
*
* Sends a new email message to specific topics and/or target recipients.
* At least one of `topics` or `targets` must be provided.
*
* @param messageId Unique ID for the message.
* @param subject Subject line of the email.
* @param content Body content of the email.
* @param topics List of topic IDs to send the message to (optional).
* @param targets List of target recipients (e.g., email:userId) (optional).
* @return JSON response.
*/
std::string createMessage(const std::string &messageId,
const std::string &subject,
const std::string &content,
const std::vector<std::string> &topics = {},
const std::vector<std::string> &targets = {});
/**
* @brief Create a new sms message.
*
* @param messageId Unique ID for the message.
* @param content SMS Content.
* @param topics List of topic IDs (optional).
* @param users List of User IDs (optional).
* @param targets List of target IDs (optional).
* @param draft If true, saves the message as a draft.
* @param scheduled_at Scheduled delivery time for message.
* @return JSON response.
*/
std::string createSms(const std::string &messageId,
const std::string &content,
const std::vector<std::string> &topics = {},
const std::vector<std::string> &users = {},
const std::vector<std::string> &targets = {},
bool draft = false,
const std::string &scheduled_at = "");
/**
* @brief Create a new email message.
*
* @param messageId Unique ID for the message.
* @param subject Subject line of the email.
* @param content Email Content.
* @param topics List of topic IDs (optional).
* @param users List of User IDs (optional).
* @param targets List of target IDs (optional).
* @param cc List of target IDs to be added as CC.
* @param bcc List of target IDs to be added as BCC.
* @param attachments List of compound ID strings of bucket IDs and file IDs
* to be attached to the email.
* @param draft If true, saves the message as a draft.
* @param html Is content of type HTML
* @param scheduled_at Scheduled delivery time for message.
* @return JSON response.
*/
std::string createEmail(const std::string &messageId,
const std::string &subject,
const std::string &content,
const std::vector<std::string> &topics = {},
const std::vector<std::string> &users = {},
const std::vector<std::string> &targets = {},
const std::vector<std::string> &cc = {},
const std::vector<std::string> &bcc = {},
const std::vector<std::string> &attachments = {},
bool draft = false, bool html = false,
const std::string &scheduled_at = "");
/**
* @brief Update an existing sms message.
*
* @param messageId Unique ID for the message.
* @param topics List of topic IDs (optional).
* @param users List of User IDs (optional).
* @param targets List of target IDs (optional).
* @param content SMS Content.
* @param draft If true, saves the message as a draft.
* @param scheduled_at Scheduled delivery time for message.
* @return JSON response.
*/
std::string updateSms(const std::string &messageId,
const std::vector<std::string> &topics = {},
const std::vector<std::string> &users = {},
const std::vector<std::string> &targets = {},
const std::string &content = "", bool draft = false,
const std::string &scheduled_at = "");
/**
* @brief Updates an existing push notification
* message.
*
* Modifies the title and body of an existing push
* message.
*
* @param messageId The ID of the message to
* update.
* @param title New title of the push
* notification.
* @param body New body content of the push
* notification.
* @param topicId List of topic IDs to update the
* message.
* @param userId List of user IDs to update the
* message.
* @return JSON response
*/
std::string updatePush(const std::string &messageId,
const std::string &title, const std::string &body,
const std::vector<std::string> &topicId = {},
const std::vector<std::string> &userId = {});
/**
* @brief List all providers.
* @param queries Optional query filters
* @return JSON string of providers list
*/
std::string listProviders(Queries &queries);
/**
* @brief List all provider logs.
* @param providerId ID of the provider
* @param queries Optional query filters
* @return JSON string of provider logs list
*/
std::string listProviderLogs(const std::string &providerId,
Queries &queries);
/**
* @brief Create a new Firebase Cloud Messaging
* provider.
* @param providerId A unique Id for the provider.
* @param name provider name.
* @param service_account_json FCM service account
* JSON..
* @param enabled Whether the provider should be
* active immediately after creation.
* @return JSON response.
*/
std::string createFcmProvider(std::string &providerId, std::string name,
std::string service_account_json,
bool enabled);
/**
* @brief Delete a provider.
* @param providerId ID of the provider
* @return JSON response
*/
std::string deleteProvider(const std::string &providerId);
/**
* @brief Get a specific provider by ID.
* @param providerId ID of the provider
* @return JSON string of the provider details
*/
std::string getProvider(const std::string &providerId);
/**
* @brief List all message logs with optional
* filters.
* @param messageId ID of the message
* @param queries Query parameters for filtering
* @return JSON string of messageLog list
*/
std::string listMessageLogs(const std::string &messageId, Queries &queries);
/**
* @brief Delete a message by its ID.
* @param messageId ID of the message.
* @return JSON response.
*/
std::string deleteMessages(const std::string &messageId);
/**
* @brief Update an email message by its ID.
* @class updateEmail
*
* This method belongs to the updateEmail class
* and provides the functionality to update the
* subject and content of an existing email
* message via the Appwrite Messaging API.
*
* @param messageId Unique message identifier
* @param subject New subject of the email
* @param content Updated content/body of the
* email
* @return JSON response string from the server
* @throws AppwriteException if parameters are
* invalid or request fails
*/
std::string updateEmail(const std::string &messageId,
const std::string &subject,
const std::string &content);
/**
* @brief List all targets for a given message.
* @param messageId ID of the message.
* @param queries Optional query filters.
* @return JSON response.
*/
std::string listTargets(const std::string &messageId,
const std::vector<std::string> &queries = {});
/**
* @brief List all logs for a given topic.
* @param topicID ID of the message.
* @param queries Optional query filters.
* @return JSON response.
*/
std::string listTopicLogs(const std::string &topicId,
const std::vector<std::string> &queries = {});
private:
std::string projectId; ///< Project ID
std::string apiKey; ///< API Key
};
#endif