From 25a3eb900f50c54765c4742f4f1bdf70ac4adef5 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Tue, 29 Jul 2025 20:42:54 +0530 Subject: [PATCH 01/13] Feat/createEmail --- Makefile | 3 + examples/messaging/messages/createMessage.cpp | 27 +++++++++ include/classes/Messaging.hpp | 7 ++- src/services/Messaging.cpp | 58 +++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 examples/messaging/messages/createMessage.cpp diff --git a/Makefile b/Makefile index ccc3214..02e2082 100644 --- a/Makefile +++ b/Makefile @@ -249,6 +249,9 @@ listMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessages.cpp getMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/getMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp $(LDFLAGS) +createMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp + @mkdir -p ./$(TESTS_DIR) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp diff --git a/examples/messaging/messages/createMessage.cpp b/examples/messaging/messages/createMessage.cpp new file mode 100644 index 0000000..1759215 --- /dev/null +++ b/examples/messaging/messages/createMessage.cpp @@ -0,0 +1,27 @@ +#include "Appwrite.hpp" +#include + +int main() { + std::string projectId = ""; + std::string apiKey = ""; + + Appwrite appwrite(projectId, apiKey); + + std::string messageId = ""; + std::string subject = "Hello from C++ Appwrite SDK!"; + std::string content = "Testing email message creation with topics and targets."; + + std::vector topics = {""}; + std::vector targets = {""}; + + try { + std::string response = appwrite.getMessaging().createMessage( + messageId, subject, content, topics, targets + ); + std::cout << "Email Message Created!\nResponse: " << response << std::endl; + } catch (const AppwriteException& ex) { + std::cerr << "Exception: " << ex.what() << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index e92aba9..c84e153 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -119,7 +119,12 @@ class Messaging { std::string createPush(const std::string &messageId, const std::string &title, const std::string &body, - const std::string &topicId); + const std::string &topicId); + std::string createMessage(const std::string& messageId, + const std::string& subject, + const std::string& content, + const std::vector& topics = {}, + const std::vector& targets = {}); private: std::string projectId; ///< Project ID diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index dd324b1..f0414eb 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -385,3 +385,61 @@ std::string Messaging::createPush(const std::string &messageId, } } +std::string Messaging::createMessage(const std::string& messageId, + const std::string& subject, + const std::string& content, + const std::vector& topics, + const std::vector& targets) { + if (messageId.empty()) { + throw AppwriteException("Missing required parameter: 'messageId'"); + } + if (subject.empty()) { + throw AppwriteException("Missing required parameter: 'subject'"); + } + if (content.empty()) { + throw AppwriteException("Missing required parameter: 'content'"); + } + if (topics.empty() && targets.empty()) { + throw AppwriteException("At least one of 'topics' or 'targets' must be provided"); + } + + std::string payload = R"({"messageId":")" + Utils::escapeJsonString(messageId) + + R"(","subject":")" + Utils::escapeJsonString(subject) + + R"(","content":")" + Utils::escapeJsonString(content) + R"(")"; + + if (!topics.empty()) { + payload += R"(,"topics":[)"; + for (size_t i = 0; i < topics.size(); ++i) { + payload += "\"" + Utils::escapeJsonString(topics[i]) + "\""; + if (i != topics.size() - 1) payload += ","; + } + payload += "]"; + } + + if (!targets.empty()) { + payload += R"(,"targets":[)"; + for (size_t i = 0; i < targets.size(); ++i) { + payload += "\"" + Utils::escapeJsonString(targets[i]) + "\""; + if (i != targets.size() - 1) payload += ","; + } + payload += "]"; + } + + payload += "}"; + + std::string url = Config::API_BASE_URL + "/messaging/messages/email"; + + std::vector headers = Config::getHeaders(projectId); + headers.push_back("X-Appwrite-Key: " + apiKey); + headers.push_back("Content-Type: application/json"); + + std::string response; + int statusCode = Utils::postRequest(url, payload, headers, response); + + if (statusCode == HttpStatus::CREATED || statusCode == HttpStatus::OK) { + return response; + } else { + throw AppwriteException("Error creating email message. Status code: " + + std::to_string(statusCode) + "\n\nResponse: " + response); + } +} \ No newline at end of file From c6e0db390f73baa7010bd011bcc8ece5d8ebf229 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Tue, 29 Jul 2025 23:49:33 +0530 Subject: [PATCH 02/13] C++ docs --- include/classes/Messaging.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index c84e153..b2f40c6 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -120,6 +120,19 @@ class Messaging { const std::string &title, const std::string &body, const std::string &topicId); + /** + * @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, From 47497d4d0e70eda88729bf15c95c3af1b7532331 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Wed, 30 Jul 2025 09:19:23 +0530 Subject: [PATCH 03/13] feat/updateMessage --- Makefile | 9 ++-- examples/messaging/messages/updateMessage.cpp | 24 +++++++++ include/classes/Messaging.hpp | 28 ++++------- src/services/Messaging.cpp | 50 +++++-------------- 4 files changed, 52 insertions(+), 59 deletions(-) create mode 100644 examples/messaging/messages/updateMessage.cpp diff --git a/Makefile b/Makefile index 02e2082..867ac8f 100644 --- a/Makefile +++ b/Makefile @@ -249,9 +249,6 @@ listMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessages.cpp getMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/getMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp $(LDFLAGS) -createMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp - @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp @@ -282,4 +279,8 @@ deleteSubscribers: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/deleteSubscribe $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/deleteSubscribers $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/deleteSubscribers.cpp $(LDFLAGS) createSubscribers: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/createSubscribers.cpp @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createSubscribers $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/createSubscribers.cpp $(LDFLAGS) \ No newline at end of file + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createSubscribers $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/createSubscribers.cpp $(LDFLAGS) +updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp + @mkdir -p ./$(TESTS_DIR) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp $(LDFLAGS) + diff --git a/examples/messaging/messages/updateMessage.cpp b/examples/messaging/messages/updateMessage.cpp new file mode 100644 index 0000000..0c297f4 --- /dev/null +++ b/examples/messaging/messages/updateMessage.cpp @@ -0,0 +1,24 @@ +#include "Appwrite.hpp" +#include + +int main() { + std::string projectId = ""; + std::string apiKey = ""; + + Appwrite appwrite(projectId, apiKey); + + std::string messageId = ""; + std::string subject = "Updated Subject from C++"; + std::string content = "Updated content of the email from C++ SDK."; + + try { + std::string response = appwrite.getMessaging().updateMessage( + messageId, subject, content + ); + std::cout << "Email Message Updated!\nResponse: " << response << std::endl; + } catch (const AppwriteException &ex) { + std::cerr << "Exception: " << ex.what() << std::endl; + } + + return 0; +} diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index b2f40c6..d44d515 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -119,25 +119,17 @@ class Messaging { std::string createPush(const std::string &messageId, const std::string &title, const std::string &body, - const std::string &topicId); - /** - * @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. + const std::string &topicId); + /** + * @brief Update an existing message (email). + * @param messageId ID of the message to update + * @param subject Updated subject of the message + * @param content Updated content of the message + * @return JSON response */ - std::string createMessage(const std::string& messageId, - const std::string& subject, - const std::string& content, - const std::vector& topics = {}, - const std::vector& targets = {}); + std::string updateMessage(const std::string& messageId, + const std::string& subject, + const std::string& content); private: std::string projectId; ///< Project ID diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index f0414eb..37755d9 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -385,11 +385,11 @@ std::string Messaging::createPush(const std::string &messageId, } } -std::string Messaging::createMessage(const std::string& messageId, - const std::string& subject, - const std::string& content, - const std::vector& topics, - const std::vector& targets) { +std::string Messaging::updateMessage( + const std::string& messageId, + const std::string& subject, + const std::string& content +) { if (messageId.empty()) { throw AppwriteException("Missing required parameter: 'messageId'"); } @@ -399,47 +399,23 @@ std::string Messaging::createMessage(const std::string& messageId, if (content.empty()) { throw AppwriteException("Missing required parameter: 'content'"); } - if (topics.empty() && targets.empty()) { - throw AppwriteException("At least one of 'topics' or 'targets' must be provided"); - } - - std::string payload = R"({"messageId":")" + Utils::escapeJsonString(messageId) + - R"(","subject":")" + Utils::escapeJsonString(subject) + - R"(","content":")" + Utils::escapeJsonString(content) + R"(")"; - - if (!topics.empty()) { - payload += R"(,"topics":[)"; - for (size_t i = 0; i < topics.size(); ++i) { - payload += "\"" + Utils::escapeJsonString(topics[i]) + "\""; - if (i != topics.size() - 1) payload += ","; - } - payload += "]"; - } - if (!targets.empty()) { - payload += R"(,"targets":[)"; - for (size_t i = 0; i < targets.size(); ++i) { - payload += "\"" + Utils::escapeJsonString(targets[i]) + "\""; - if (i != targets.size() - 1) payload += ","; - } - payload += "]"; - } + std::string url = Config::API_BASE_URL + "/messaging/messages/email/" + Utils::urlEncode(messageId); - payload += "}"; - - std::string url = Config::API_BASE_URL + "/messaging/messages/email"; + std::string payload = R"({"subject":")" + Utils::escapeJsonString(subject) + + R"(","content":")" + Utils::escapeJsonString(content) + R"("})"; std::vector headers = Config::getHeaders(projectId); headers.push_back("X-Appwrite-Key: " + apiKey); headers.push_back("Content-Type: application/json"); std::string response; - int statusCode = Utils::postRequest(url, payload, headers, response); + int statusCode = Utils::patchRequest(url, payload, headers, response); - if (statusCode == HttpStatus::CREATED || statusCode == HttpStatus::OK) { + if (statusCode == HttpStatus::OK || statusCode == HttpStatus::CREATED) { return response; } else { - throw AppwriteException("Error creating email message. Status code: " + - std::to_string(statusCode) + "\n\nResponse: " + response); + throw AppwriteException("Error updating message. Status code: " + std::to_string(statusCode) + + "\n\nResponse: " + response); } -} \ No newline at end of file +} From ad24e95a8c0764525ffbb81728279096579f6400 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Wed, 30 Jul 2025 09:25:33 +0530 Subject: [PATCH 04/13] deleted irrelevant --- examples/messaging/messages/createMessage.cpp | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 examples/messaging/messages/createMessage.cpp diff --git a/examples/messaging/messages/createMessage.cpp b/examples/messaging/messages/createMessage.cpp deleted file mode 100644 index 1759215..0000000 --- a/examples/messaging/messages/createMessage.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Appwrite.hpp" -#include - -int main() { - std::string projectId = ""; - std::string apiKey = ""; - - Appwrite appwrite(projectId, apiKey); - - std::string messageId = ""; - std::string subject = "Hello from C++ Appwrite SDK!"; - std::string content = "Testing email message creation with topics and targets."; - - std::vector topics = {""}; - std::vector targets = {""}; - - try { - std::string response = appwrite.getMessaging().createMessage( - messageId, subject, content, topics, targets - ); - std::cout << "Email Message Created!\nResponse: " << response << std::endl; - } catch (const AppwriteException& ex) { - std::cerr << "Exception: " << ex.what() << std::endl; - } - - return 0; -} \ No newline at end of file From 291860996183cc56700b7c81b1b3b7a0f99d9703 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Wed, 30 Jul 2025 12:39:44 +0530 Subject: [PATCH 05/13] Errors Resolved --- Makefile | 10 ++++------ include/classes/Messaging.hpp | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 867ac8f..e2f499c 100644 --- a/Makefile +++ b/Makefile @@ -249,7 +249,9 @@ listMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessages.cpp getMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/getMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp $(LDFLAGS) - +updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp + @mkdir -p ./$(TESTS_DIR) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp @mkdir -p ./$(TESTS_DIR) @@ -279,8 +281,4 @@ deleteSubscribers: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/deleteSubscribe $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/deleteSubscribers $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/deleteSubscribers.cpp $(LDFLAGS) createSubscribers: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/createSubscribers.cpp @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createSubscribers $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/createSubscribers.cpp $(LDFLAGS) -updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp - @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp $(LDFLAGS) - + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createSubscribers $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/createSubscribers.cpp $(LDFLAGS) \ No newline at end of file diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index d44d515..a8a7edc 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -120,7 +120,7 @@ class Messaging { const std::string &title, const std::string &body, const std::string &topicId); - /** + /** * @brief Update an existing message (email). * @param messageId ID of the message to update * @param subject Updated subject of the message From 40e320722452b83d0f37db3e26935fe0a1784c8f Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Wed, 30 Jul 2025 22:00:36 +0530 Subject: [PATCH 06/13] Minor Changes --- Makefile | 4 ++-- .../messaging/messages/{updateMessage.cpp => updateEmail.cpp} | 2 +- include/classes/Messaging.hpp | 2 +- src/services/Messaging.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename examples/messaging/messages/{updateMessage.cpp => updateEmail.cpp} (90%) diff --git a/Makefile b/Makefile index e2f499c..1b685f7 100644 --- a/Makefile +++ b/Makefile @@ -249,9 +249,9 @@ listMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessages.cpp getMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/getMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp $(LDFLAGS) -updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp +updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp $(LDFLAGS) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp @mkdir -p ./$(TESTS_DIR) diff --git a/examples/messaging/messages/updateMessage.cpp b/examples/messaging/messages/updateEmail.cpp similarity index 90% rename from examples/messaging/messages/updateMessage.cpp rename to examples/messaging/messages/updateEmail.cpp index 0c297f4..65d1bab 100644 --- a/examples/messaging/messages/updateMessage.cpp +++ b/examples/messaging/messages/updateEmail.cpp @@ -12,7 +12,7 @@ int main() { std::string content = "Updated content of the email from C++ SDK."; try { - std::string response = appwrite.getMessaging().updateMessage( + std::string response = appwrite.getMessaging().updateEmail( messageId, subject, content ); std::cout << "Email Message Updated!\nResponse: " << response << std::endl; diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index a8a7edc..09e079a 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -127,7 +127,7 @@ class Messaging { * @param content Updated content of the message * @return JSON response */ - std::string updateMessage(const std::string& messageId, + std::string updateEmail(const std::string& messageId, const std::string& subject, const std::string& content); diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index 37755d9..2b445b1 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -385,7 +385,7 @@ std::string Messaging::createPush(const std::string &messageId, } } -std::string Messaging::updateMessage( +std::string Messaging::updateEmail( const std::string& messageId, const std::string& subject, const std::string& content From d5e6ccb02ffde841beed56aeb3023833df9b1bec Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Mon, 4 Aug 2025 23:47:02 +0530 Subject: [PATCH 07/13] Update --- Makefile | 4 ++-- examples/messaging/messages/updateMessage.cpp | 24 +++++++++++++++++++ include/classes/Messaging.hpp | 24 +++++++++++++++++-- src/services/Messaging.cpp | 3 ++- 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 examples/messaging/messages/updateMessage.cpp diff --git a/Makefile b/Makefile index 16f15f7..656b328 100644 --- a/Makefile +++ b/Makefile @@ -257,9 +257,9 @@ createMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp deleteMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/deleteMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp $(LDFLAGS) - updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp +updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp @mkdir -p ./$(TESTS_DIR) diff --git a/examples/messaging/messages/updateMessage.cpp b/examples/messaging/messages/updateMessage.cpp new file mode 100644 index 0000000..65d1bab --- /dev/null +++ b/examples/messaging/messages/updateMessage.cpp @@ -0,0 +1,24 @@ +#include "Appwrite.hpp" +#include + +int main() { + std::string projectId = ""; + std::string apiKey = ""; + + Appwrite appwrite(projectId, apiKey); + + std::string messageId = ""; + std::string subject = "Updated Subject from C++"; + std::string content = "Updated content of the email from C++ SDK."; + + try { + std::string response = appwrite.getMessaging().updateEmail( + messageId, subject, content + ); + std::cout << "Email Message Updated!\nResponse: " << response << std::endl; + } catch (const AppwriteException &ex) { + std::cerr << "Exception: " << ex.what() << std::endl; + } + + return 0; +} diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index 7d1aaf9..98c5f5c 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -173,13 +173,33 @@ class Messaging { const std::string &body, const std::vector &topicId = {}, const std::vector &userId = {}); - - /** + /** * @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 + ); + private: std::string projectId; ///< Project ID std::string apiKey; ///< API Key diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index bf6d8ff..46e50d2 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -546,7 +546,8 @@ std::string Messaging::deleteMessages(const std::string &messageId) { std::to_string(statusCode) + "\nResponse: " + response); } -}std::string Messaging::updateEmail( +} + std::string Messaging::updateEmail( const std::string& messageId, const std::string& subject, const std::string& content From 9bedc9d95d30eed0aa51c3c1cc8bf2477dbe6951 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Tue, 5 Aug 2025 17:51:52 +0530 Subject: [PATCH 08/13] New Update --- Makefile | 4 ++-- examples/messaging/messages/updateMessage.cpp | 24 ------------------- 2 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 examples/messaging/messages/updateMessage.cpp diff --git a/Makefile b/Makefile index 656b328..cb025da 100644 --- a/Makefile +++ b/Makefile @@ -257,9 +257,9 @@ createMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp deleteMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/deleteMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp $(LDFLAGS) -updateMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp +updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateMessage.cpp $(LDFLAGS) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp @mkdir -p ./$(TESTS_DIR) diff --git a/examples/messaging/messages/updateMessage.cpp b/examples/messaging/messages/updateMessage.cpp deleted file mode 100644 index 65d1bab..0000000 --- a/examples/messaging/messages/updateMessage.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "Appwrite.hpp" -#include - -int main() { - std::string projectId = ""; - std::string apiKey = ""; - - Appwrite appwrite(projectId, apiKey); - - std::string messageId = ""; - std::string subject = "Updated Subject from C++"; - std::string content = "Updated content of the email from C++ SDK."; - - try { - std::string response = appwrite.getMessaging().updateEmail( - messageId, subject, content - ); - std::cout << "Email Message Updated!\nResponse: " << response << std::endl; - } catch (const AppwriteException &ex) { - std::cerr << "Exception: " << ex.what() << std::endl; - } - - return 0; -} From 6b0d517af77247b90310670f102bed0080abc752 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Fri, 8 Aug 2025 10:03:03 +0530 Subject: [PATCH 09/13] 201 removed --- src/services/Messaging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index 46e50d2..f01b75a 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -574,7 +574,7 @@ std::string Messaging::deleteMessages(const std::string &messageId) { std::string response; int statusCode = Utils::patchRequest(url, payload, headers, response); - if (statusCode == HttpStatus::OK || statusCode == HttpStatus::CREATED) { + if (statusCode == HttpStatus::OK) { return response; } else { throw AppwriteException("Error updating message. Status code: " + std::to_string(statusCode) + From e5192072a5b43d2fe11fbdcfa971088fb69b4eac Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Fri, 29 Aug 2025 11:07:51 +0530 Subject: [PATCH 10/13] Update Email --- Makefile | 3 +++ include/classes/Messaging.hpp | 21 ++++++++++++++++++++- src/services/Messaging.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index db5ed1d..d485051 100644 --- a/Makefile +++ b/Makefile @@ -273,6 +273,9 @@ updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp listTargets: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTargets $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp $(LDFLAGS) +updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp + @mkdir -p ./$(TESTS_DIR) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index f914232..62e7d65 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -155,7 +155,26 @@ class Messaging { const std::string& content, const std::vector& topics = {}, const std::vector& targets = {}); - + /** + * @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 Updates an existing push notification message. * diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index 7f1e034..2d85245 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -468,6 +468,41 @@ std::string Messaging::createMessage(const std::string& messageId, } } +std::string Messaging::updateEmail( + const std::string& messageId, + const std::string& subject, + const std::string& content +) { + if (messageId.empty()) { + throw AppwriteException("Missing required parameter: 'messageId'"); + } + if (subject.empty()) { + throw AppwriteException("Missing required parameter: 'subject'"); + } + if (content.empty()) { + throw AppwriteException("Missing required parameter: 'content'"); + } + + std::string url = Config::API_BASE_URL + "/messaging/messages/email/" + Utils::urlEncode(messageId); + + std::string payload = R"({"subject":")" + Utils::escapeJsonString(subject) + + R"(","content":")" + Utils::escapeJsonString(content) + R"("})"; + + std::vector headers = Config::getHeaders(projectId); + headers.push_back("X-Appwrite-Key: " + apiKey); + headers.push_back("Content-Type: application/json"); + + std::string response; + int statusCode = Utils::patchRequest(url, payload, headers, response); + + if (statusCode == HttpStatus::OK) { + return response; + } else { + throw AppwriteException("Error updating message. Status code: " + std::to_string(statusCode) + + "\n\nResponse: " + response); + } +} + std::string Messaging::updatePush(const std::string &messageId, const std::string &title, const std::string &body, From a82d8e94634bfe106ea7d06416c163809f314cbb Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Fri, 29 Aug 2025 22:58:39 +0530 Subject: [PATCH 11/13] Fix --- include/classes/Messaging.hpp | 19 ------------------- src/services/Messaging.cpp | 32 -------------------------------- 2 files changed, 51 deletions(-) diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index 62e7d65..f53d4ea 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -155,25 +155,6 @@ class Messaging { const std::string& content, const std::vector& topics = {}, const std::vector& targets = {}); - /** - * @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 Updates an existing push notification message. diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index 2d85245..d6e9a6d 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -635,33 +635,6 @@ std::string Messaging::deleteMessages(const std::string &messageId) { } } - std::string Messaging::updateEmail( - const std::string& messageId, - const std::string& subject, - const std::string& content -) { - if (messageId.empty()) { - throw AppwriteException("Missing required parameter: 'messageId'"); - } - if (subject.empty()) { - throw AppwriteException("Missing required parameter: 'subject'"); - } - if (content.empty()) { - throw AppwriteException("Missing required parameter: 'content'"); - } - - std::string url = Config::API_BASE_URL + "/messaging/messages/email/" + Utils::urlEncode(messageId); - - std::string payload = R"({"subject":")" + Utils::escapeJsonString(subject) + - R"(","content":")" + Utils::escapeJsonString(content) + R"("})"; - - std::vector headers = Config::getHeaders(projectId); - headers.push_back("X-Appwrite-Key: " + apiKey); - headers.push_back("Content-Type: application/json"); - - std::string response; - int statusCode = Utils::patchRequest(url, payload, headers, response); - std::string Messaging::listTargets(const std::string &messageId, const std::vector &queries) { if (messageId.empty()) { @@ -693,9 +666,4 @@ std::string Messaging::listTargets(const std::string &messageId, "\n\nResponse: " + response); } } - throw AppwriteException( - "Error fetching message targets. Status code: " + std::to_string(statusCode) + - "\n\nResponse: " + response); - } -} From b86e638ae950db6096baf25e10c724e76121ebec Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Fri, 29 Aug 2025 23:13:43 +0530 Subject: [PATCH 12/13] Make Update --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index d485051..db5ed1d 100644 --- a/Makefile +++ b/Makefile @@ -273,9 +273,6 @@ updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp listTargets: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTargets $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp $(LDFLAGS) -updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp - @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS) # Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp From a650ba5da41e6f51176574066823ed55da912f13 Mon Sep 17 00:00:00 2001 From: aritracodes_69 Date: Sun, 7 Sep 2025 22:51:49 +0530 Subject: [PATCH 13/13] Makefile Update --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index db5ed1d..e8ad965 100644 --- a/Makefile +++ b/Makefile @@ -269,7 +269,6 @@ deleteMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/deleteMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/deleteMessages.cpp $(LDFLAGS) listTargets: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTargets $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp $(LDFLAGS)