Skip to content

Commit 4d97b0a

Browse files
Merge branch 'develop' into feat/updateMessage
2 parents 1d3f44f + f0ce2f2 commit 4d97b0a

5 files changed

Lines changed: 105 additions & 1 deletion

File tree

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ getMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp
254254
createMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp
255255
@mkdir -p ./$(TESTS_DIR)
256256
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp $(LDFLAGS)
257+
listProviders: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listProviders.cpp
258+
@mkdir -p ./$(TESTS_DIR)
259+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listProviders $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listProviders.cpp $(LDFLAGS)
257260
listMessageLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessageLogs.cpp
258261
@mkdir -p ./$(TESTS_DIR)
259262
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listMessageLogs $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessageLogs.cpp $(LDFLAGS)
@@ -262,7 +265,10 @@ deleteMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp
262265
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/deleteMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp $(LDFLAGS)
263266
updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp
264267
@mkdir -p ./$(TESTS_DIR)
265-
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS)
268+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS)
269+
listTargets: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp
270+
@mkdir -p ./$(TESTS_DIR)
271+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTargets $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp $(LDFLAGS)
266272
# Messaging - Topics
267273
getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp
268274
@mkdir -p ./$(TESTS_DIR)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
int main() {
4+
std::string projectId = "68853010003a3f4fc106";
5+
std::string apiKey = "";
6+
Appwrite appwrite(projectId, apiKey);
7+
Queries queries;
8+
queries.queryLimit(50);
9+
try {
10+
std::string response = appwrite.getMessaging().listProviders(queries);
11+
std::cout << "providers fetched! \nResponse: " << response << std::endl;
12+
} catch (const AppwriteException &ex) {
13+
std::cerr << "Exception: " << ex.what() << std::endl;
14+
}
15+
return 0;
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

include/classes/Messaging.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ class Messaging {
173173
const std::string &body,
174174
const std::vector<std::string> &topicId = {},
175175
const std::vector<std::string> &userId = {});
176+
177+
/**
178+
* @brief List all providers.
179+
* @param queries Optional query filters
180+
* @return JSON string of providers list
181+
*/
182+
std::string listProviders(Queries &queries);
176183

177184
/**
178185
* @brief List all message logs with optional filters.
@@ -211,6 +218,14 @@ class Messaging {
211218
);
212219

213220

221+
/**
222+
* @brief List all targets for a given message.
223+
* @param messageId ID of the message.
224+
* @param queries Optional query filters.
225+
* @return JSON response.
226+
*/
227+
std::string listTargets(const std::string &messageId,
228+
const std::vector<std::string> &queries = {});
214229
private:
215230
std::string projectId; ///< Project ID
216231
std::string apiKey; ///< API Key

src/services/Messaging.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,20 @@ std::string Messaging::updatePush(const std::string &messageId,
530530
}
531531
}
532532

533+
std::string Messaging::listProviders(Queries &queries) {
534+
std::string url = Config::API_BASE_URL + "/messaging/providers";
535+
std::vector<std::string> headers = Config::getHeaders(projectId);
536+
headers.push_back("X-Appwrite-Key: " + apiKey);
537+
std::string response;
538+
int statusCode = Utils::getRequest(url, headers, response);
539+
if (statusCode == HttpStatus::OK) {
540+
return response;
541+
} else {
542+
throw AppwriteException("Error listing providers . Status code: " +
543+
std::to_string(statusCode) +
544+
"\nResponse: " + response);
545+
}
546+
}
533547

534548
std::string Messaging::listMessageLogs(const std::string &messageId,
535549
Queries &queries) {
@@ -566,6 +580,7 @@ std::string Messaging::deleteMessages(const std::string &messageId) {
566580
"\nResponse: " + response);
567581
}
568582
}
583+
569584
std::string Messaging::updateEmail(
570585
const std::string& messageId,
571586
const std::string& subject,
@@ -593,10 +608,40 @@ std::string Messaging::deleteMessages(const std::string &messageId) {
593608
std::string response;
594609
int statusCode = Utils::patchRequest(url, payload, headers, response);
595610

611+
std::string Messaging::listTargets(const std::string &messageId,
612+
const std::vector<std::string> &queries) {
613+
if (messageId.empty()) {
614+
throw AppwriteException("Missing required parameter: 'messageId'");
615+
}
616+
617+
std::string url = Config::API_BASE_URL + "/messaging/messages/" + messageId + "/targets";
618+
std::string queryParam = "";
619+
if (!queries.empty()) {
620+
queryParam += "?queries[]=" + Utils::urlEncode(queries[0]);
621+
for (size_t i = 1; i < queries.size(); ++i) {
622+
queryParam += "&queries[]=" + Utils::urlEncode(queries[i]);
623+
}
624+
}
625+
626+
url += queryParam;
627+
628+
std::vector<std::string> headers = Config::getHeaders(projectId);
629+
headers.push_back("X-Appwrite-Key: " + apiKey);
630+
631+
std::string response;
632+
int statusCode = Utils::getRequest(url, headers, response);
633+
634+
596635
if (statusCode == HttpStatus::OK) {
597636
return response;
598637
} else {
599638
throw AppwriteException("Error updating message. Status code: " + std::to_string(statusCode) +
600639
"\n\nResponse: " + response);
601640
}
602641
}
642+
throw AppwriteException(
643+
"Error fetching message targets. Status code: " + std::to_string(statusCode) +
644+
"\n\nResponse: " + response);
645+
}
646+
}
647+

0 commit comments

Comments
 (0)