-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Sleitnick/feature/notifications
Notifications
- Loading branch information
Showing
13 changed files
with
313 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Notification API | ||
|
||
## Send Notification | ||
Send a notification to a user. | ||
``` | ||
Usage: rbxcloud notification send [OPTIONS] --universe-id <UNIVERSE_ID> --user-id <USER_ID> --payload <PAYLOAD> --api-key <API_KEY> | ||
Options: | ||
-u, --universe-id <UNIVERSE_ID> Universe ID | ||
-U, --user-id <USER_ID> User ID | ||
-P, --payload <PAYLOAD> Payload | ||
-p, --pretty Pretty-print the JSON response | ||
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=] | ||
-h, --help Print help | ||
``` | ||
|
||
### Example | ||
For an example payload, see the [Roblox documentation](https://create.roblox.com/docs/cloud/reference/UserNotification#Create-User-Notification). | ||
``` | ||
$ rbxcloud notification send -p -u 12345 -U 6789 -P PAYLOAD_JSON -a MY_KEY | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::collections::HashMap; | ||
|
||
use rbxcloud::rbx::{ | ||
error::Error, | ||
types::{RobloxUserId, UniverseId}, | ||
v2::{ | ||
notification::{ | ||
JoinExperience, Notification, NotificationPayload, NotificationResponse, | ||
NotificationSource, NotificationType, Parameter, | ||
}, | ||
Client, | ||
}, | ||
}; | ||
|
||
async fn send_notification() -> Result<NotificationResponse, Error> { | ||
// Inputs: | ||
let api_key = "MY_API_KEY"; | ||
let message_id = "MY_MESSAGE_ID"; | ||
let universe_id = 9876543210; | ||
let user_id = 308165; | ||
|
||
let client = Client::new(api_key); | ||
let notification_client = client.notification(UniverseId(universe_id)); | ||
|
||
let notification = Notification { | ||
source: NotificationSource { | ||
universe: format!("universe/{}", universe_id), | ||
}, | ||
payload: NotificationPayload { | ||
message_id: message_id.to_string(), | ||
notification_type: NotificationType::TypeUnspecified, | ||
join_experience: Some(JoinExperience { | ||
launch_data: "Some launch data here".to_string(), | ||
}), | ||
analytics_data: Some(HashMap::from([( | ||
"category".to_string(), | ||
"Bronze egg hatched".to_string(), | ||
)])), | ||
parameters: Some(HashMap::from([( | ||
"key".to_string(), | ||
Parameter { | ||
string_value: Some("bronze egg".to_string()), | ||
int64_value: None, | ||
}, | ||
)])), | ||
}, | ||
}; | ||
|
||
notification_client | ||
.send(RobloxUserId(user_id), notification) | ||
.await | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let send_result = send_notification().await; | ||
|
||
match send_result { | ||
Ok(result) => { | ||
println!("Notification sent: {:?}", result); | ||
} | ||
Err(e) => { | ||
eprintln!("{e:?}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use clap::{Args, Subcommand}; | ||
use rbxcloud::rbx::{ | ||
types::{RobloxUserId, UniverseId}, | ||
v2::Client, | ||
}; | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum NotificationCommands { | ||
/// Send a notification to a user | ||
Send { | ||
/// Universe ID | ||
#[clap(short, long, value_parser)] | ||
universe_id: u64, | ||
|
||
/// User ID | ||
#[clap(short = 'U', long, value_parser)] | ||
user_id: u64, | ||
|
||
/// Payload | ||
#[clap(short = 'P', long, value_parser)] | ||
payload: String, | ||
|
||
/// Pretty-print the JSON response | ||
#[clap(short, long, value_parser, default_value_t = false)] | ||
pretty: bool, | ||
|
||
/// Roblox Open Cloud API Key | ||
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")] | ||
api_key: String, | ||
}, | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
pub struct Notification { | ||
#[clap(subcommand)] | ||
command: NotificationCommands, | ||
} | ||
|
||
impl Notification { | ||
pub async fn run(self) -> anyhow::Result<Option<String>> { | ||
match self.command { | ||
NotificationCommands::Send { | ||
universe_id, | ||
user_id, | ||
payload, | ||
pretty, | ||
api_key, | ||
} => { | ||
let client = Client::new(&api_key); | ||
let notification_client = client.notification(UniverseId(universe_id)); | ||
|
||
let notification = serde_json::from_str::< | ||
rbxcloud::rbx::v2::notification::Notification, | ||
>(&payload)?; | ||
|
||
let res = notification_client | ||
.send(RobloxUserId(user_id), notification) | ||
.await; | ||
|
||
match res { | ||
Ok(subscription_info) => { | ||
let r = if pretty { | ||
serde_json::to_string_pretty(&subscription_info)? | ||
} else { | ||
serde_json::to_string(&subscription_info)? | ||
}; | ||
Ok(Some(r)) | ||
} | ||
Err(err) => Err(anyhow::anyhow!(err)), | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.