Appwrite C++ SDK
Auto-generated API documentation for the Appwrite C++ SDK
Loading...
Searching...
No Matches
Messaging.hpp
Go to the documentation of this file.
1/// @file Messaging.hpp
2/// @brief Provides messaging-related operations (messages, topics, subscribers)
3
4#ifndef MESSAGING_HPP
5#define MESSAGING_HPP
6
7#include "Query.hpp"
8#include "Utils.hpp"
11#include <string>
12
13/**
14 * @class Messaging
15 * @brief Provides APIs to manage messaging: messages, topics, subscribers.
16 */
17class Messaging {
18 public:
19 /**
20 * @brief Constructor for Messaging service.
21 * @param projectId Appwrite project ID
22 * @param apiKey Appwrite API key
23 */
24 Messaging(const std::string &projectId, const std::string &apiKey);
25
26 /**
27 * @brief List all messages with optional filters.
28 * @param queries Query parameters for filtering results
29 * @return JSON string of message list
30 */
31 std::string listMessages(Queries &queries);
32
33 /**
34 * @brief Get a specific message by ID.
35 * @param messageId ID of the message
36 * @return JSON string of the message details
37 */
38 std::string getMessages(const std::string &messageId);
39
40 /**
41 * @brief Get details of a topic by ID.
42 * @param topicId ID of the topic
43 * @return JSON string of the topic
44 */
45 std::string getTopic(const std::string &topicId);
46
47 /**
48 * @brief List all topics with optional filters.
49 * @param queries Query parameters for filtering
50 * @return JSON string of topic list
51 */
52 std::string listTopics(Queries &queries);
53
54 /**
55 * @brief Delete a topic by its ID.
56 * @param topicId ID of the topic
57 * @return JSON response
58 */
59 std::string deleteTopic(const std::string &topicId);
60
61 /**
62 * @brief Create a new topic.
63 * @param topicId Unique topic ID
64 * @param name Name of the topic
65 * @param subscribe List of subscriber IDs
66 * @return JSON response
67 */
68 std::string createTopic(const std::string &topicId, const std::string &name,
69 const std::vector<std::string> &subscribe);
70
71 /**
72 * @brief Update an existing topic.
73 * @param topicId ID of the topic to update
74 * @param name New name for the topic
75 * @param subscribe Updated list of subscribers (optional)
76 * @return JSON response
77 */
78 std::string updateTopic(const std::string &topicId, const std::string &name,
79 const std::vector<std::string> &subscribe = {});
80
81 /**
82 * @brief Get details of a subscriber to a topic.
83 * @param topicId ID of the topic
84 * @param subscriberId ID of the subscriber
85 * @return JSON string of the subscriber
86 */
87 std::string getSubscriber(const std::string &topicId,
88 const std::string &subscriberId);
89
90 /**
91 * @brief List all subscribers of a topic.
92 * @param topicId ID of the topic
93 * @param queries Optional query filters
94 * @return JSON string of subscriber list
95 */
96 std::string listSubscribers(const std::string &topicId, Queries &queries);
97
98 /**
99 * @brief Delete a subscriber from a topic.
100 * @param topicId ID of the topic
101 * @param subscriberId ID of the subscriber to remove
102 * @return JSON response
103 */
104 std::string deleteSubscribers(const std::string &topicId,
105 const std::string &subscriberId);
106
107 /**
108 * @brief Add a subscriber to a topic.
109 * @param topicId ID of the topic
110 * @param name Name of the subscriber
111 * @param targetId Target platform/device
112 * @param subscriberId Unique ID for the subscriber
113 * @return JSON response
114 */
115 std::string createSubscribers(const std::string &topicId,
116 const std::string &name,
117 const std::string &targetId,
118 const std::string &subscriberId);
119 /**
120 * @brief Creates a new push notification message.
121 *
122 * Sends a push notification to specified users, topics, or both.
123 *
124 * @param messageId A unique Id for the message.
125 * @param title Title of the push notification.
126 * @param body Body content of the push notification.
127 * @param topicId A list of topic IDs to which the notification should be
128 * sent.
129 * @param userId A list of user IDs to which the notification should be
130 * sent.
131 * @param draft If true, saves the message as a draft.
132 *
133 * @return JSON response.
134 */
135 std::string createPush(const std::string &messageId,
136 const std::string &title, const std::string &body,
137 const std::vector<std::string> &topicId = {},
138 const std::vector<std::string> &userId = {},
139 bool draft = false);
140
141 /**
142 * @brief Create a new email message.
143 *
144 * Sends a new email message to specific topics and/or target recipients.
145 * At least one of `topics` or `targets` must be provided.
146 *
147 * @param messageId Unique ID for the message.
148 * @param subject Subject line of the email.
149 * @param content Body content of the email.
150 * @param topics List of topic IDs to send the message to (optional).
151 * @param targets List of target recipients (e.g., email:userId) (optional).
152 * @return JSON response.
153 */
154 std::string createMessage(const std::string &messageId,
155 const std::string &subject,
156 const std::string &content,
157 const std::vector<std::string> &topics = {},
158 const std::vector<std::string> &targets = {});
159
160 /**
161 * @brief Create a new sms message.
162 *
163 * @param messageId Unique ID for the message.
164 * @param content SMS Content.
165 * @param topics List of topic IDs (optional).
166 * @param users List of User IDs (optional).
167 * @param targets List of target IDs (optional).
168 * @param draft If true, saves the message as a draft.
169 * @param scheduled_at Scheduled delivery time for message.
170 * @return JSON response.
171 */
172 std::string createSms(const std::string &messageId,
173 const std::string &content,
174 const std::vector<std::string> &topics = {},
175 const std::vector<std::string> &users = {},
176 const std::vector<std::string> &targets = {},
177 bool draft = false,
178 const std::string &scheduled_at = "");
179
180 /**
181 * @brief Updates an existing push notification
182 * message.
183 *
184 * Modifies the title and body of an existing push
185 * message.
186 *
187 * @param messageId The ID of the message to
188 * update.
189 * @param title New title of the push
190 * notification.
191 * @param body New body content of the push
192 * notification.
193 * @param topicId List of topic IDs to update the
194 * message.
195 * @param userId List of user IDs to update the
196 * message.
197 * @return JSON response
198 */
199 std::string updatePush(const std::string &messageId,
200 const std::string &title, const std::string &body,
201 const std::vector<std::string> &topicId = {},
202 const std::vector<std::string> &userId = {});
203
204 /**
205 * @brief List all providers.
206 * @param queries Optional query filters
207 * @return JSON string of providers list
208 */
209 std::string listProviders(Queries &queries);
210
211 /**
212 * @brief List all provider logs.
213 * @param providerId ID of the provider
214 * @param queries Optional query filters
215 * @return JSON string of provider logs list
216 */
217 std::string listProviderLogs(const std::string &providerId,
218 Queries &queries);
219
220 /**
221 * @brief Create a new Firebase Cloud Messaging
222 * provider.
223 * @param providerId A unique Id for the provider.
224 * @param name provider name.
225 * @param service_account_json FCM service account
226 * JSON..
227 * @param enabled Whether the provider should be
228 * active immediately after creation.
229 * @return JSON response.
230 */
231 std::string createFcmProvider(std::string &providerId, std::string name,
232 std::string service_account_json,
233 bool enabled);
234
235 /**
236 * @brief Delete a provider.
237 * @param providerId ID of the provider
238 * @return JSON response
239 */
240 std::string deleteProvider(const std::string &providerId);
241
242 /**
243 * @brief Get a specific provider by ID.
244 * @param providerId ID of the provider
245 * @return JSON string of the provider details
246 */
247 std::string getProvider(const std::string &providerId);
248
249 /**
250 * @brief List all message logs with optional
251 * filters.
252 * @param messageId ID of the message
253 * @param queries Query parameters for filtering
254 * @return JSON string of messageLog list
255 */
256 std::string listMessageLogs(const std::string &messageId, Queries &queries);
257
258 /**
259 * @brief Delete a message by its ID.
260 * @param messageId ID of the message.
261 * @return JSON response.
262 */
263
264 std::string deleteMessages(const std::string &messageId);
265
266 /**
267 * @brief Update an email message by its ID.
268 * @class updateEmail
269 *
270 * This method belongs to the updateEmail class
271 * and provides the functionality to update the
272 * subject and content of an existing email
273 * message via the Appwrite Messaging API.
274 *
275 * @param messageId Unique message identifier
276 * @param subject New subject of the email
277 * @param content Updated content/body of the
278 * email
279 * @return JSON response string from the server
280 * @throws AppwriteException if parameters are
281 * invalid or request fails
282 */
283 std::string updateEmail(const std::string &messageId,
284 const std::string &subject,
285 const std::string &content);
286
287 /**
288 * @brief List all targets for a given message.
289 * @param messageId ID of the message.
290 * @param queries Optional query filters.
291 * @return JSON response.
292 */
293 std::string listTargets(const std::string &messageId,
294 const std::vector<std::string> &queries = {});
295
296 /**
297 * @brief List all logs for a given topic.
298 * @param topicID ID of the message.
299 * @param queries Optional query filters.
300 * @return JSON response.
301 */
302 std::string listTopicLogs(const std::string &topicId,
303 const std::vector<std::string> &queries = {});
304
305 private:
306 std::string projectId; ///< Project ID
307 std::string apiKey; ///< API Key
308};
309
310#endif
Declares the base exception class used to represent Appwrite SDK errors.
Defines HTTP status code enums for consistent error and response handling.
Offers helper methods to construct query parameters for filtering and sorting API responses.
Provides utility functions and helpers used across the SDK.
Provides APIs to manage messaging: messages, topics, subscribers.
Definition Messaging.hpp:17
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={})
Updates an existing push notification message.
std::string createTopic(const std::string &topicId, const std::string &name, const std::vector< std::string > &subscribe)
Create a new topic.
std::string deleteTopic(const std::string &topicId)
Delete a topic by its ID.
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={})
Create a new email message.
std::string deleteMessages(const std::string &messageId)
Delete a message by its ID.
std::string deleteSubscribers(const std::string &topicId, const std::string &subscriberId)
Delete a subscriber from a topic.
std::string deleteProvider(const std::string &providerId)
Delete a provider.
std::string createSubscribers(const std::string &topicId, const std::string &name, const std::string &targetId, const std::string &subscriberId)
Add a subscriber to a topic.
std::string updateEmail(const std::string &messageId, const std::string &subject, const std::string &content)
std::string getProvider(const std::string &providerId)
Get a specific provider by ID.
std::string listTopics(Queries &queries)
List all topics with optional filters.
std::string createFcmProvider(std::string &providerId, std::string name, std::string service_account_json, bool enabled)
Create a new Firebase Cloud Messaging provider.
std::string listProviderLogs(const std::string &providerId, Queries &queries)
List all provider logs.
std::string getMessages(const std::string &messageId)
Get a specific message by ID.
std::string listMessageLogs(const std::string &messageId, Queries &queries)
List all message logs with optional filters.
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)
Creates a new push notification message.
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="")
Create a new sms message.
std::string getTopic(const std::string &topicId)
Get details of a topic by ID.
Messaging(const std::string &projectId, const std::string &apiKey)
Constructor for Messaging service.
std::string getSubscriber(const std::string &topicId, const std::string &subscriberId)
Get details of a subscriber to a topic.
std::string updateTopic(const std::string &topicId, const std::string &name, const std::vector< std::string > &subscribe={})
Update an existing topic.
std::string listProviders(Queries &queries)
List all providers.
std::string listTopicLogs(const std::string &topicId, const std::vector< std::string > &queries={})
List all logs for a given topic.
std::string listTargets(const std::string &messageId, const std::vector< std::string > &queries={})
List all targets for a given message.
std::string listSubscribers(const std::string &topicId, Queries &queries)
List all subscribers of a topic.
std::string listMessages(Queries &queries)
List all messages with optional filters.
Utility class to construct and manage Appwrite-style database query filters.
Definition Query.hpp:24