Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ listMessageLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessageLogs.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)

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)
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)
Expand Down
24 changes: 24 additions & 0 deletions examples/messaging/messages/updateEmail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Appwrite.hpp"
#include <iostream>

int main() {
std::string projectId = "<project-id>";
std::string apiKey = "<api-key>";

Appwrite appwrite(projectId, apiKey);

std::string messageId = "<existing-email-message-id>";
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;
}
22 changes: 22 additions & 0 deletions include/classes/Messaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,29 @@ class Messaging {
* @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
);


/**
* @brief List all targets for a given message.
Expand Down
35 changes: 34 additions & 1 deletion src/services/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,33 @@ 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<std::string> 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<std::string> &queries) {
if (messageId.empty()) {
Expand All @@ -604,11 +631,17 @@ std::string Messaging::listTargets(const std::string &messageId,
std::string response;
int statusCode = Utils::getRequest(url, headers, response);


if (statusCode == HttpStatus::OK) {
return response;
} else {
throw AppwriteException("Error updating message. Status code: " + std::to_string(statusCode) +
"\n\nResponse: " + response);
}
}
throw AppwriteException(
"Error fetching message targets. Status code: " + std::to_string(statusCode) +
"\n\nResponse: " + response);
}
}
}