docs: reformat code examples to follow prettier styling
This commit is contained in:
@@ -284,25 +284,34 @@ export interface PushoverRecipient {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* import { Pushover } from '@cis-oss/pushover';
|
* import { Pushover } from "@cis-oss/pushover";
|
||||||
*
|
*
|
||||||
* // Initialize the client
|
* // Initialize the client
|
||||||
* const pushover = new Pushover('YOUR_APP_API_TOKEN');
|
* const pushover = new Pushover("YOUR_APP_API_TOKEN");
|
||||||
*
|
*
|
||||||
* // Define recipients
|
* // Define recipients
|
||||||
* const recipients = [{ id: 'USER_KEY_1' }, {id: 'USER_KEY_2', devices: ['DEVICE_1', 'DEVICE_2']}, { id: 'GROUP_KEY_1' }];
|
* const recipients = [
|
||||||
|
* { id: "USER_KEY_1" },
|
||||||
|
* { id: "USER_KEY_2", devices: ["DEVICE_1", "DEVICE_2"] },
|
||||||
|
* { id: "GROUP_KEY_1" },
|
||||||
|
* ];
|
||||||
*
|
*
|
||||||
* // Send a basic message
|
* // Send a basic message
|
||||||
* const responses = pushover.send({
|
* const responses = pushover.send(
|
||||||
|
* {
|
||||||
* message: "Hello from the library!",
|
* message: "Hello from the library!",
|
||||||
* title: "Test Message"
|
* title: "Test Message",
|
||||||
* }, { recipients });
|
* },
|
||||||
|
* { recipients },
|
||||||
|
* );
|
||||||
*
|
*
|
||||||
* responses.then((responses) => {
|
* responses
|
||||||
* console.log('Messages sent:', responses);
|
* .then((responses) => {
|
||||||
* }).catch( (error) => {
|
* console.log("Messages sent:", responses);
|
||||||
* console.error('Failed to send messages:', error);
|
|
||||||
* })
|
* })
|
||||||
|
* .catch((error) => {
|
||||||
|
* console.error("Failed to send messages:", error);
|
||||||
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export class Pushover {
|
export class Pushover {
|
||||||
@@ -330,19 +339,29 @@ export class Pushover {
|
|||||||
* ```typescript
|
* ```typescript
|
||||||
* // Send a message to a specific user and device
|
* // Send a message to a specific user and device
|
||||||
* const userRecipient: PushoverRecipient = { id: "user-key", devices: ["phone"] };
|
* const userRecipient: PushoverRecipient = { id: "user-key", devices: ["phone"] };
|
||||||
* await pushover.send({ message: "Targeted message" }, { recipients: [userRecipient] });
|
* await pushover.send(
|
||||||
|
* { message: "Targeted message" },
|
||||||
|
* { recipients: [userRecipient] },
|
||||||
|
* );
|
||||||
*
|
*
|
||||||
* // Send an emergency priority message and handle the receipt
|
* // Send an emergency priority message and handle the receipt
|
||||||
* const responses = pushover.send({
|
* const responses = pushover.send(
|
||||||
|
* {
|
||||||
* message: "Emergency alert!",
|
* message: "Emergency alert!",
|
||||||
* priority: 2,
|
* priority: 2,
|
||||||
* emergencyOpts: { retry: 30, expire: 3600 }
|
* emergencyOpts: { retry: 30, expire: 3600 },
|
||||||
* }, { recipients: [userRecipient] });
|
* },
|
||||||
|
* { recipients: [userRecipient] },
|
||||||
|
* );
|
||||||
*
|
*
|
||||||
* responses.then((responses) => {
|
* responses
|
||||||
* console.log(`Emergency message sent. Receipts: ${responses.map((response) => response.receipt).join(", ")}`);
|
* .then((responses) => {
|
||||||
|
* console.log(
|
||||||
|
* `Emergency message sent. Receipts: ${responses.map((response) => response.receipt).join(", ")}`,
|
||||||
|
* );
|
||||||
* // Store the receipt to check status or cancel later
|
* // Store the receipt to check status or cancel later
|
||||||
* }).catch((error) => {
|
* })
|
||||||
|
* .catch((error) => {
|
||||||
* console.error("Failed to send emergency message:", error);
|
* console.error("Failed to send emergency message:", error);
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
@@ -565,13 +584,21 @@ export class Pushover {
|
|||||||
* // Validate a user key
|
* // Validate a user key
|
||||||
* const validation = await pushover.validate({ user: "user-key" });
|
* const validation = await pushover.validate({ user: "user-key" });
|
||||||
* if (validation.status === 1) {
|
* if (validation.status === 1) {
|
||||||
* console.log("User is valid. Devices:", validation.devices, ", Licenses:", validation.licenses);
|
* console.log(
|
||||||
|
* "User is valid. Devices:",
|
||||||
|
* validation.devices,
|
||||||
|
* ", Licenses:",
|
||||||
|
* validation.licenses,
|
||||||
|
* );
|
||||||
* } else {
|
* } else {
|
||||||
* console.error("Validation failed:", validation.errors);
|
* console.error("Validation failed:", validation.errors);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // Validate a user and device
|
* // Validate a user and device
|
||||||
* const deviceValidation = await pushover.validate({ user: "user-key", deviceName: "phone" });
|
* const deviceValidation = await pushover.validate({
|
||||||
|
* user: "user-key",
|
||||||
|
* deviceName: "phone",
|
||||||
|
* });
|
||||||
* console.log("Device validation status:", deviceValidation.status);
|
* console.log("Device validation status:", deviceValidation.status);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@@ -603,7 +630,9 @@ export class Pushover {
|
|||||||
* const receiptId = "RECEIPT_ID_FROM_SEND_RESPONSE";
|
* const receiptId = "RECEIPT_ID_FROM_SEND_RESPONSE";
|
||||||
* const status = await pushover.checkReceipt(receiptId);
|
* const status = await pushover.checkReceipt(receiptId);
|
||||||
* if (status.status === 1) {
|
* if (status.status === 1) {
|
||||||
* console.log(`Acknowledged: ${status.acknowledged} by ${status.acknowledged_by}`);
|
* console.log(
|
||||||
|
* `Acknowledged: ${status.acknowledged} by ${status.acknowledged_by}`,
|
||||||
|
* );
|
||||||
* console.log(`Expired: ${status.expired}`);
|
* console.log(`Expired: ${status.expired}`);
|
||||||
* } else {
|
* } else {
|
||||||
* console.error("Failed to check receipt:", status.errors);
|
* console.error("Failed to check receipt:", status.errors);
|
||||||
@@ -665,7 +694,9 @@ export class Pushover {
|
|||||||
* const tagName = "critical-db-alert";
|
* const tagName = "critical-db-alert";
|
||||||
* const cancelByTagResponse = await pushover.cancelRetriesByTag(tagName);
|
* const cancelByTagResponse = await pushover.cancelRetriesByTag(tagName);
|
||||||
* if (cancelByTagResponse.status === 1) {
|
* if (cancelByTagResponse.status === 1) {
|
||||||
* console.log(`Successfully cancelled ${cancelByTagResponse.canceled} messages with tag: ${tagName}`);
|
* console.log(
|
||||||
|
* `Successfully cancelled ${cancelByTagResponse.canceled} messages with tag: ${tagName}`,
|
||||||
|
* );
|
||||||
* } else {
|
* } else {
|
||||||
* console.error("Failed to cancel by tag:", cancelByTagResponse.errors);
|
* console.error("Failed to cancel by tag:", cancelByTagResponse.errors);
|
||||||
* }
|
* }
|
||||||
|
|||||||
Reference in New Issue
Block a user