File tree Expand file tree Collapse file tree
examples/messaging/messages Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -258,6 +258,9 @@ deleteMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp
258258 @mkdir -p ./$(TESTS_DIR )
259259 $(CXX ) $(CXXFLAGS ) -o ./$(TESTS_DIR ) /deleteMessages $(SRCS ) $(EXAMPLES_DIR ) /messaging/messages/deleteMessages.cpp $(LDFLAGS )
260260
261+ listTargets : $(SRCS ) $(EXAMPLES_DIR ) /messaging/messages/listTargets.cpp
262+ @mkdir -p ./$(TESTS_DIR )
263+ $(CXX ) $(CXXFLAGS ) -o ./$(TESTS_DIR ) /listTargets $(SRCS ) $(EXAMPLES_DIR ) /messaging/messages/listTargets.cpp $(LDFLAGS )
261264# Messaging - Topics
262265getTopic : $(SRCS ) $(EXAMPLES_DIR ) /messaging/topics/getTopic.cpp
263266 @mkdir -p ./$(TESTS_DIR )
Original file line number Diff line number Diff line change 1+ #include " Appwrite.hpp"
2+ #include " classes/Messaging.hpp"
3+ #include < iostream>
4+
5+ int main () {
6+ std::string projectId = " " ;
7+ std::string apiKey = " " ;
8+ std::string messageId = " " ;
9+
10+ std::vector<std::string> queries = {};
11+
12+ Appwrite appwrite (projectId, apiKey);
13+
14+ try {
15+ std::string response = appwrite.getMessaging ().listTargets (messageId, queries);
16+ std::cout << " Message targets retrieved successfully:\n " << response << std::endl;
17+ } catch (const AppwriteException &e) {
18+ std::cerr << " Appwrite error: " << e.what () << std::endl;
19+ }
20+
21+ return 0 ;
22+ }
Original file line number Diff line number Diff line change @@ -180,6 +180,15 @@ class Messaging {
180180 * @return JSON response.
181181 */
182182 std::string deleteMessages (const std::string &messageId);
183+
184+ /* *
185+ * @brief List all targets for a given message.
186+ * @param messageId ID of the message.
187+ * @param queries Optional query filters.
188+ * @return JSON response.
189+ */
190+ std::string listTargets (const std::string &messageId,
191+ const std::vector<std::string> &queries = {});
183192 private:
184193 std::string projectId; // /< Project ID
185194 std::string apiKey; // /< API Key
Original file line number Diff line number Diff line change @@ -546,4 +546,36 @@ std::string Messaging::deleteMessages(const std::string &messageId) {
546546 std::to_string (statusCode) +
547547 " \n Response: " + response);
548548 }
549+ }
550+
551+ std::string Messaging::listTargets (const std::string &messageId,
552+ const std::vector<std::string> &queries) {
553+ if (messageId.empty ()) {
554+ throw AppwriteException (" Missing required parameter: 'messageId'" );
555+ }
556+
557+ std::string url = Config::API_BASE_URL + " /messaging/messages/" + messageId + " /targets" ;
558+ std::string queryParam = " " ;
559+ if (!queries.empty ()) {
560+ queryParam += " ?queries[]=" + Utils::urlEncode (queries[0 ]);
561+ for (size_t i = 1 ; i < queries.size (); ++i) {
562+ queryParam += " &queries[]=" + Utils::urlEncode (queries[i]);
563+ }
564+ }
565+
566+ url += queryParam;
567+
568+ std::vector<std::string> headers = Config::getHeaders (projectId);
569+ headers.push_back (" X-Appwrite-Key: " + apiKey);
570+
571+ std::string response;
572+ int statusCode = Utils::getRequest (url, headers, response);
573+
574+ if (statusCode == HttpStatus::OK ) {
575+ return response;
576+ } else {
577+ throw AppwriteException (
578+ " Error fetching message targets. Status code: " + std::to_string (statusCode) +
579+ " \n\n Response: " + response);
580+ }
549581}
You can’t perform that action at this time.
0 commit comments