Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -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/updateEmail.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename it to updateEmail

@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
@mkdir -p ./$(TESTS_DIR)
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;
}
12 changes: 11 additions & 1 deletion include/classes/Messaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,17 @@ 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);
/**
* @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 updateEmail(const std::string& messageId,
const std::string& subject,
const std::string& content);

private:
std::string projectId; ///< Project ID
Expand Down
34 changes: 34 additions & 0 deletions src/services/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,37 @@ std::string Messaging::createPush(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);

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