Ephemerals - adamyeager/PushbulletSharp GitHub Wiki

Ephemerals are pushes that can be used for sending SMS text messages, notifications (both sending and dismissing), and universal copy/paste. They also support Pushbullet's end-to-end encryption method, which I highly recommend using.

If you are using encryption you'll want to construct your PushbulletSharp Client using the new constructor which takes an additional argument of the encryption password. The client does not keep the password in plain text as a property. Instead on initialization, the constructor uses the password to generate the hash key. The hash key is accessible via the EncryptionKey property. You can update the encryption key by sending a new plaintext password to it and it will generate a new hash, but this should really ever be necessary unless you're using the same client and switching Access Tokens.

Creating a PushbulletSharp Client that supports End-to-End Encryption

The encryption password is the password the user inputs on their devices.

string ApiKey = "--YOURKEYGOESHERE--";
var Client = new PushbulletClient(ApiKey, "--YOUR-ENCRYPTION-PASSWORD--", TimeZoneInfo.Local);

Sending a SMS Text Message

Sending a SMS text message requires using the SMSEphemeral object provided by PushbulletSharp (PushbulletSharp.Models.Requests.Ephemerals.SMSEphemeral). It's properties are as follows:

  • Type - Pushbullet requires the type of a SMS ephemeral to be set to messaging_extension_reply. PushbulletSharp automatically sets this field to that when initializing the object.
  • PackageName - Pushbullet requires the package_name to be set to com.pushbullet.android. PushbulletSharp automatically sets this field to that when initializing the object.
  • SourceUserIden - The iden will be the current user's iden. With a constructed client you could access this via Client.CurrentUsersInformation().Iden;
  • TargetDeviceIden - The target_device_iden is the device that the current user has listed that has the ability to send SMS text messages.
  • ConversationIden - The conversation_iden is the phone number you are trying to send the SMS to. Pushbullet's API uses the example number of "+1 303 555 1212"
  • Message - The message you are trying to send.

To send the ephemeral, use the client's PushEphemeral method. It's method signature has one required parameter which is an IEphemeral object and one optional boolean parameter called encrypt. By default encrypt will be false. I highly recommend using encryption. When set to true, the PushbulletSharp client will encrypt the ephemeral for you.

Here's an example of sending a SMS Ephemeral:

string ApiKey = "--YOURKEYGOESHERE--";
var Client = new PushbulletClient(ApiKey, "--YOUR-ENCRYPTION-PASSWORD--", TimeZoneInfo.Local);

var currentUser = Client.CurrentUsersInformation();
var userDevices = Client.CurrentUsersDevices(true);
var smsDevice= userDevices.Devices.Where(o => o.HasSMS).FirstOrDefault();

SMSEphemeral smsRequest = new SMSEphemeral()
{
	ConversationIden = "+1 303 555 1212",
	Message = "Hello from PushbulletSharp!",
	SourceUserIden = currentUser.Iden,
	TargetDeviceIden = smsDevice.Iden
};
var result = Client.PushEphemeral(smsRequest, true);

Sending a Notification

Notifications use the NotificationEphemeral object (PushbulletSharp.Models.Requests.Ephemerals.NotificationEphemeral). It's properties are as follows:

  • Type - The API requires this to be set to mirror. PushbulletSharp automatically sets this field to that when initializing the object.
  • PackageName - The package that made the notification, used when updating/dismissing an existing notification. PushbulletSharp automatically sets this field to com.pushbullet.android
  • ApplicationName - The name of the application that created the notification. PushbulletSharp automatically sets this to PushbulletSharp
  • ClientVersion - The client version of the app sending this message. PushbulletSharp automatically sets this to 3
  • NotificationId - The id of the notification, used when updating/dismissing an existing notification.
  • NotificationTag - The tag of the notification, used when updating/dismissing an existing notification.
  • Icon - Base64-encoded JPEG image to use as the icon of the push.
  • SourceUserIden - The user iden of the user sending this message.
  • SourceDeviceIden - The iden of the device sending this message.
  • HasRoot - The phone is rooted.
  • Title - The title of the notification.
  • Body - The body of the notification.
  • Dismissable - True if the notification can be dismissed.

I recommend installing the Pushbullet software onto your desktop and then updating this example to target your desktop's software. As you run it you'll see the notification pop up. If you create a dismissal ephemeral outlined under this section, you can send that too and watch the notification go away without you having to click the "Dismiss" button.

Here's an example of sending a Notification Ephemeral:


string ApiKey = "--YOURKEYGOESHERE--";
var Client = new PushbulletClient(ApiKey, "--YOUR-ENCRYPTION-PASSWORD--", TimeZoneInfo.Local);

var currentUser = Client.CurrentUsersInformation();
var userDevices = Client.CurrentUsersDevices(true);
var firstActiveDevice= userDevices.Devices.FirstOrDefault();

NotificationEphemeral notificationRequest = new NotificationEphemeral()
{
  Title = "Notification Test",
  Body = "This is a notification from PushBulletSharp!",
  Dismissable = true,
  HasRoot = false,
  NotificationId = "123456789",
  NotificationTag = null,
  SourceDeviceIden = firstActiveDevice.Iden,
  SourceUserIden = currentUser.Iden
};
var result = Client.PushEphemeral(notificationRequest, true);

Dismissing a Notification

Dismissing a notification requires the use of the DismissalEphemeral request object (PushbulletSharp.Models.Requests.Ephemerals.DismissalEphemeral). It's properties are as follows:

  • Type - Dismissals are type of dismissal. PushbulletSharp automatically sets this property to dismissal
  • PackageName - Set to the PackageName field from the mirrored notification. _PushbulletSharp automatically sets this property to com.pushbullet.android because it does that for the NotficationEphemeral request object.
  • SourceUserIden - Set to the SourceUserIden field from the mirrored notification.
  • NotificationId - Set to the NotificationId field from the mirrored notification.
  • NotificationTag - Set to the NotificationTag field from the mirrored notification.

Here's an example of sending a DismissalEphemeral (using the same NotificationId & SourceUserIden used in the previous example):

string ApiKey = "--YOURKEYGOESHERE--";
var Client = new PushbulletClient(ApiKey, "--YOUR-ENCRYPTION-PASSWORD--", TimeZoneInfo.Local);

var currentUser = Client.CurrentUsersInformation();

DismissalEphemeral dismissalRequest = new DismissalEphemeral()
{
  NotificationId = "123456789",
  NotificationTag = null,
  SourceUserIden = CurrentUser.Iden
};
var result = Client.PushEphemeral(dismissalRequest, true);

Universal Copy / Paste

Universal Copy/Paste is really cool and easy to utilize. To send this kind of ephemeral, use the UniversalCopyPasteEphemeral request object (PushbulletSharp.Models.Requests.Ephemerals.UniversalCopyPasteEphemeral). It's properties are as follows:

  • Type - The type is clip PushbulletSharp automatically sets this value to clip
  • SourceUserIden - The iden of the user sending this message.
  • SourceDeviceIden - The iden of the device sending this message.
  • Body - The text to copy to the clipboard.

Here's an example of sending a Universal Copy/Paste Ephemeral:

string ApiKey = "--YOURKEYGOESHERE--";
var Client = new PushbulletClient(ApiKey, "--YOUR-ENCRYPTION-PASSWORD--", TimeZoneInfo.Local);

var currentUser = Client.CurrentUsersInformation();
var userDevices = Client.CurrentUsersDevices(true);
var firstActiveDevice= userDevices.Devices.FirstOrDefault();

UniversalCopyPasteEphemeral ucpRequest = new UniversalCopyPasteEphemeral()
{
  Body = "https://www.nuget.org/packages/PushBulletSharp",
  SourceDeviceIden = firstActiveDevice.Iden,
  SourceUserIden = currentUser.Iden
};
var result = Client.PushEphemeral(ucpRequest, true);