Skip to content
Merged
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: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ createEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createEmail.cpp
@mkdir -p ./$(TESTS_DIR)
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createEmail.cpp $(LDFLAGS)

updateSms: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateSms.cpp
@mkdir -p ./$(TESTS_DIR)
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateSms $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateSms.cpp $(LDFLAGS)

# Messaging - Topics
getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp
@mkdir -p ./$(TESTS_DIR)
Expand Down
6 changes: 2 additions & 4 deletions examples/messaging/messages/createSms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ int main() {

Appwrite appwrite(projectId, apiKey);

std::string messageId = "6b309k4016e14b8";
std::string subject = "Hello from C++ Appwrite SDK!";
std::string content =
"Testing SMS message creation with topics, users, and targets.";
std::string messageId = "msg001";
std::string content = "Testing SMS message creation.";

std::vector<std::string> topics = {};
std::vector<std::string> users = {};
Expand Down
39 changes: 39 additions & 0 deletions examples/messaging/messages/updateSms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "Appwrite.hpp"
#include <chrono>
#include <iostream>

int main() {
std::string projectId = "";
std::string apiKey = "";

Appwrite appwrite(projectId, apiKey);

std::string messageId = "msg001";
std::string content = "Testing SMS message updation.";

std::vector<std::string> topics = {};
std::vector<std::string> users = {};
std::vector<std::string> targets = {};

auto now = std::chrono::system_clock::now();
auto future_time = now + std::chrono::minutes(5);
auto time_t = std::chrono::system_clock::to_time_t(future_time);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
future_time.time_since_epoch()) %
1000;

std::string scheduled_at = "";

bool draft = true;

try {
std::string response = appwrite.getMessaging().updateSms(
messageId, topics, users, targets, content, draft, scheduled_at);
std::cout << "SMS Message updated!\nResponse: " << response
<< std::endl;
} catch (const AppwriteException &ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
}

return 0;
}
24 changes: 21 additions & 3 deletions include/classes/Messaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ class Messaging {
const std::vector<std::string> &attachments = {},
bool draft = false, bool html = false,
const std::string &scheduled_at = "");
/**
* @brief Update an existing sms message.
*
* @param messageId Unique ID for the message.
* @param topics List of topic IDs (optional).
* @param users List of User IDs (optional).
* @param targets List of target IDs (optional).
* @param content SMS Content.
* @param draft If true, saves the message as a draft.
* @param scheduled_at Scheduled delivery time for message.
* @return JSON response.
*/
std::string updateSms(const std::string &messageId,
const std::vector<std::string> &topics = {},
const std::vector<std::string> &users = {},
const std::vector<std::string> &targets = {},
const std::string &content = "", bool draft = false,
const std::string &scheduled_at = "");

/**
* @brief Updates an existing push notification
Expand Down Expand Up @@ -323,15 +341,15 @@ class Messaging {
std::string listTargets(const std::string &messageId,
const std::vector<std::string> &queries = {});

/**
/**
* @brief List all logs for a given topic.
* @param topicID ID of the message.
* @param queries Optional query filters.
* @return JSON response.
*/
*/
std::string listTopicLogs(const std::string &topicId,
const std::vector<std::string> &queries = {});

private:
std::string projectId; ///< Project ID
std::string apiKey; ///< API Key
Expand Down
71 changes: 71 additions & 0 deletions src/services/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,77 @@ std::string Messaging::createSms(const std::string &messageId,
}
}

// Added method to update an existing SMS message
std::string Messaging::updateSms(const std::string &messageId,
const std::vector<std::string> &topics,
const std::vector<std::string> &users,
const std::vector<std::string> &targets,
const std::string &content, bool draft,
const std::string &scheduled_at) {
if (messageId.empty()) {
throw AppwriteException("Missing required parameter: 'messageId'");
}

if (content.empty()) {
throw AppwriteException("Missing required parameter: 'content'");
}

std::string payload = "{";

payload += R"("topics":[)";
for (size_t i = 0; i < topics.size(); ++i) {
payload += "\"" + Utils::escapeJsonString(topics[i]) + "\"";
if (i != topics.size() - 1)
payload += ",";
}
payload += "]";

payload += R"(,"users":[)";
for (size_t i = 0; i < users.size(); ++i) {
payload += "\"" + Utils::escapeJsonString(users[i]) + "\"";
if (i != users.size() - 1)
payload += ",";
}
payload += "]";

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 += R"(,"content":")" + Utils::escapeJsonString(content) + R"(")";

payload += std::string(R"(,"draft":)") + (draft ? "true" : "false");

if (!scheduled_at.empty()) {
payload += R"(,"scheduledAt":")" +
Utils::escapeJsonString(scheduled_at) + "\"";
}

payload += "}";

std::string url = Config::API_BASE_URL + "/messaging/messages/sms/" +
Utils::urlEncode(messageId);

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) {
return response;
} else {
throw AppwriteException("Error updating sms message. Status code: " +
std::to_string(statusCode) +
"\n\nResponse: " + response);
}
}

// Added method to create a new email message.
std::string Messaging::createEmail(
const std::string &messageId, const std::string &subject,
Expand Down
Loading