Struct fcm::MessageBuilder
source · pub struct MessageBuilder<'a> { /* private fields */ }
Expand description
A builder to get a Message
instance.
Examples
use fcm::MessageBuilder;
let mut builder = MessageBuilder::new("<FCM API Key>", "<registration id>");
builder.dry_run(true);
let message = builder.finalize();
Implementations
sourceimpl<'a> MessageBuilder<'a>
impl<'a> MessageBuilder<'a>
sourcepub fn new(api_key: &'a str, to: &'a str) -> Self
pub fn new(api_key: &'a str, to: &'a str) -> Self
Get a new instance of Message. You need to supply either a registration id, or a topic (/topics/…).
sourcepub fn registration_ids<S>(&mut self, ids: &'a [S]) -> &mut Selfwhere
S: Into<Cow<'a, str>> + AsRef<str>,
pub fn registration_ids<S>(&mut self, ids: &'a [S]) -> &mut Selfwhere
S: Into<Cow<'a, str>> + AsRef<str>,
String value to replace format specifiers in the body string.
sourcepub fn collapse_key(&mut self, collapse_key: &'a str) -> &mut Self
pub fn collapse_key(&mut self, collapse_key: &'a str) -> &mut Self
Set this parameter to identify groups of messages that can be collapsed.
sourcepub fn priority(&mut self, priority: Priority) -> &mut Self
pub fn priority(&mut self, priority: Priority) -> &mut Self
Set the priority of the message. You can set Normal or High priorities.
Examples:
use fcm::{MessageBuilder, Priority};
let mut builder = MessageBuilder::new("<FCM API Key>", "<registration id>");
builder.priority(Priority::High);
let message = builder.finalize();
sourcepub fn content_available(&mut self, content_available: bool) -> &mut Self
pub fn content_available(&mut self, content_available: bool) -> &mut Self
To set the content-available
field on iOS
sourcepub fn delay_while_idle(&mut self, delay_while_idle: bool) -> &mut Self
pub fn delay_while_idle(&mut self, delay_while_idle: bool) -> &mut Self
When set to true
, sends the message only when the device is active.
sourcepub fn time_to_live(&mut self, time_to_live: i32) -> &mut Self
pub fn time_to_live(&mut self, time_to_live: i32) -> &mut Self
How long (in seconds) to keep the message on FCM servers in case the device is offline. The maximum and default is 4 weeks.
sourcepub fn restricted_package_name(
&mut self,
restricted_package_name: &'a str
) -> &mut Self
pub fn restricted_package_name(
&mut self,
restricted_package_name: &'a str
) -> &mut Self
Package name of the application where the registration tokens must match.
sourcepub fn dry_run(&mut self, dry_run: bool) -> &mut Self
pub fn dry_run(&mut self, dry_run: bool) -> &mut Self
When set to true
, allows you to test FCM without actually sending the message.
sourcepub fn data(&mut self, data: &dyn Serialize) -> Result<&mut Self, Error>
pub fn data(&mut self, data: &dyn Serialize) -> Result<&mut Self, Error>
Use this to add custom key-value pairs to the message. This data must be handled appropriately on the client end. The data can be anything that Serde can serialize to JSON.
Examples:
use fcm::MessageBuilder;
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert("message", "Howdy!");
let mut builder = MessageBuilder::new("<FCM API Key>", "<registration id>");
builder.data(&map);
let message = builder.finalize();
sourcepub fn notification(&mut self, notification: Notification<'a>) -> &mut Self
pub fn notification(&mut self, notification: Notification<'a>) -> &mut Self
Use this to set a Notification
for the message.
Examples:
use fcm::{MessageBuilder, NotificationBuilder};
let mut builder = NotificationBuilder::new();
builder.title("Hey!");
builder.body("Do you want to catch up later?");
let notification = builder.finalize();
let mut builder = MessageBuilder::new("<FCM API Key>", "<registration id>");
builder.notification(notification);
let message = builder.finalize();