@@ -344,7 +344,9 @@ std::string Messaging::createSubscribers(const std::string &topicId,
344344std::string Messaging::createPush (const std::string &messageId,
345345 const std::string &title,
346346 const std::string &body,
347- const std::string &topicId){
347+ const std::vector<std::string> &topicId,
348+ const std::vector<std::string> &userId,
349+ bool draft){
348350 if (messageId.empty ()) {
349351 throw AppwriteException (" Missing required parameter: 'messageId'" );
350352 }
@@ -361,13 +363,34 @@ std::string Messaging::createPush(const std::string &messageId,
361363 throw AppwriteException (" Missing required parameter: 'topicId'" );
362364 }
363365
366+ if (userId.empty ()) {
367+ throw AppwriteException (" Missing required parameter: 'userId'" );
368+ }
369+
370+ std::string topicIdJson = " [" ;
371+ for (size_t i = 0 ; i < topicId.size (); ++i) {
372+ topicIdJson += " \" " + Utils::escapeJsonString (topicId[i]) + " \" " ;
373+ if (i < topicId.size () - 1 ) topicIdJson += " ," ;
374+ }
375+ topicIdJson += " ]" ;
376+
377+ std::string userIdJson = " [" ;
378+ for (size_t i = 0 ; i < userId.size (); ++i) {
379+ userIdJson += " \" " + Utils::escapeJsonString (userId[i]) + " \" " ;
380+ if (i < userId.size () - 1 ) userIdJson += " ," ;
381+ }
382+ userIdJson += " ]" ;
383+
384+
364385 std::string url = Config::API_BASE_URL + " /messaging/messages/push" ;
365-
366386 std::string payload =
367387 R"( {"messageId":")" + Utils::escapeJsonString (messageId) +
368388 R"( ","title":")" + Utils::escapeJsonString (title) +
369389 R"( ","body":")" + Utils::escapeJsonString (body) +
370- R"( ","topics": [")" + Utils::escapeJsonString (topicId) + R"( "]})" ;
390+ R"( ","topicId":)" + topicIdJson +
391+ R"( ,"userId":)" + userIdJson +
392+ R"( ,"draft":)" + (draft ? " true" : " false" ) +
393+ " }" ;
371394
372395 std::vector<std::string> headers = Config::getHeaders (projectId);
373396 headers.push_back (" X-Appwrite-Key: " + apiKey);
@@ -434,6 +457,7 @@ std::string Messaging::createMessage(const std::string& messageId,
434457 headers.push_back (" Content-Type: application/json" );
435458
436459 std::string response;
460+
437461 int statusCode = Utils::postRequest (url, payload, headers, response);
438462
439463 if (statusCode == HttpStatus::CREATED || statusCode == HttpStatus::OK ) {
@@ -442,4 +466,66 @@ std::string Messaging::createMessage(const std::string& messageId,
442466 throw AppwriteException (" Error creating email message. Status code: " +
443467 std::to_string (statusCode) + " \n\n Response: " + response);
444468 }
469+ }
470+
471+ std::string Messaging::updatePush (const std::string &messageId,
472+ const std::string &title,
473+ const std::string &body,
474+ const std::vector<std::string> &topicId,
475+ const std::vector<std::string> &userId) {
476+ if (messageId.empty ()) {
477+ throw AppwriteException (" Missing required parameter: 'messageId'" );
478+ }
479+
480+ if (title.empty ()) {
481+ throw AppwriteException (" Missing required parameter: 'title'" );
482+ }
483+
484+ if (body.empty ()) {
485+ throw AppwriteException (" Missing required parameter: 'body'" );
486+ }
487+
488+ if (topicId.empty ()) {
489+ throw AppwriteException (" Missing required parameter: 'topicId'" );
490+ }
491+
492+ if (userId.empty ()) {
493+ throw AppwriteException (" Missing required parameter: 'userId'" );
494+ }
495+
496+ std::string topicIdJson = " [" ;
497+ for (size_t i = 0 ; i < topicId.size (); ++i) {
498+ topicIdJson += " \" " + Utils::escapeJsonString (topicId[i]) + " \" " ;
499+ if (i < topicId.size () - 1 ) topicIdJson += " ," ;
500+ }
501+ topicIdJson += " ]" ;
502+
503+ std::string userIdJson = " [" ;
504+ for (size_t i = 0 ; i < userId.size (); ++i) {
505+ userIdJson += " \" " + Utils::escapeJsonString (userId[i]) + " \" " ;
506+ if (i < userId.size () - 1 ) userIdJson += " ," ;
507+ }
508+ userIdJson += " ]" ;
509+
510+ std::string url = Config::API_BASE_URL + " /messaging/messages/push/" + messageId;
511+ std::string payload =
512+ R"( {"title":")" + Utils::escapeJsonString (title) +
513+ R"( ","body":")" + Utils::escapeJsonString (body) +
514+ R"( ","topicId":)" + topicIdJson +
515+ R"( ,"userId":)" + userIdJson +
516+ " }" ;
517+ std::vector<std::string> headers = Config::getHeaders (projectId);
518+ headers.push_back (" X-Appwrite-Key: " + apiKey);
519+ headers.push_back (" Content-Type: application/json" );
520+ std::string response;
521+
522+ int statusCode = Utils::patchRequest (url, payload, headers, response);
523+
524+ if (statusCode == HttpStatus::OK ) {
525+ return response;
526+ } else {
527+ throw AppwriteException (
528+ " Error updating push message. Status code: " + std::to_string (statusCode) +
529+ " \n\n Response: " + response);
530+ }
445531}
0 commit comments