File tree Expand file tree Collapse file tree 4 files changed +65
-0
lines changed
examples/messaging/messages Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,9 @@ deleteMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp
261261 @mkdir -p ./$(TESTS_DIR )
262262 $(CXX ) $(CXXFLAGS ) -o ./$(TESTS_DIR ) /deleteMessages $(SRCS ) $(EXAMPLES_DIR ) /messaging/messages/deleteMessages.cpp $(LDFLAGS )
263263
264+ listTargets : $(SRCS ) $(EXAMPLES_DIR ) /messaging/messages/listTargets.cpp
265+ @mkdir -p ./$(TESTS_DIR )
266+ $(CXX ) $(CXXFLAGS ) -o ./$(TESTS_DIR ) /listTargets $(SRCS ) $(EXAMPLES_DIR ) /messaging/messages/listTargets.cpp $(LDFLAGS )
264267# Messaging - Topics
265268getTopic : $(SRCS ) $(EXAMPLES_DIR ) /messaging/topics/getTopic.cpp
266269 @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 @@ -189,6 +189,14 @@ class Messaging {
189189 */
190190 std::string deleteMessages (const std::string &messageId);
191191
192+ /* *
193+ * @brief List all targets for a given message.
194+ * @param messageId ID of the message.
195+ * @param queries Optional query filters.
196+ * @return JSON response.
197+ */
198+ std::string listTargets (const std::string &messageId,
199+ const std::vector<std::string> &queries = {});
192200 private:
193201 std::string projectId; // /< Project ID
194202 std::string apiKey; // /< API Key
Original file line number Diff line number Diff line change @@ -565,4 +565,36 @@ std::string Messaging::deleteMessages(const std::string &messageId) {
565565 std::to_string (statusCode) +
566566 " \n Response: " + response);
567567 }
568+ }
569+
570+ std::string Messaging::listTargets (const std::string &messageId,
571+ const std::vector<std::string> &queries) {
572+ if (messageId.empty ()) {
573+ throw AppwriteException (" Missing required parameter: 'messageId'" );
574+ }
575+
576+ std::string url = Config::API_BASE_URL + " /messaging/messages/" + messageId + " /targets" ;
577+ std::string queryParam = " " ;
578+ if (!queries.empty ()) {
579+ queryParam += " ?queries[]=" + Utils::urlEncode (queries[0 ]);
580+ for (size_t i = 1 ; i < queries.size (); ++i) {
581+ queryParam += " &queries[]=" + Utils::urlEncode (queries[i]);
582+ }
583+ }
584+
585+ url += queryParam;
586+
587+ std::vector<std::string> headers = Config::getHeaders (projectId);
588+ headers.push_back (" X-Appwrite-Key: " + apiKey);
589+
590+ std::string response;
591+ int statusCode = Utils::getRequest (url, headers, response);
592+
593+ if (statusCode == HttpStatus::OK) {
594+ return response;
595+ } else {
596+ throw AppwriteException (
597+ " Error fetching message targets. Status code: " + std::to_string (statusCode) +
598+ " \n\n Response: " + response);
599+ }
568600}
You can’t perform that action at this time.
0 commit comments