-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -62,4 +62,25 @@ if (somethingHasGoneVeryWrong) { | |
} | ||
``` | ||
|
||
This will send an alert to the pre-configured recipient from the sender's account, exactly as if triggered via CLI. If it is unable to deliver the notification due to a missing configuration file or failed login, the call to `notify` will throw, allowing you to fall back on other notification methods. | ||
This will send an alert to the pre-configured recipient from the sender's account, exactly as if triggered via CLI. If it is unable to deliver the notification due to a missing configuration file or failed login, the call to `notify` will throw, allowing you to fall back on other notification methods. | ||
|
||
As with the previous commands, you must initialize mnotify before this will work; if you've already done this via `mnotify --init`, you are good to go, but you can also do it programmatically: | ||
|
||
> ### Note | ||
> The code below is just an example for testing purposes; I don't recommend storing your login credentials in plaintext in any source file. In real world usage, you should store the required values below as environment variables or in some external gitignored file that won't be accidentally committed. When you call `init`, you should read in these values from the file or environment to pass as the first parameter. | ||
```js | ||
mnotify.init({ | ||
"senderEmail": "[email protected]", | ||
"senderPass": "*******", | ||
"receiverEmail": "[email protected]", | ||
"receiverPass": "*******", | ||
"storeSenderCredentials": true | ||
}, err => { | ||
if (!err) { | ||
mnotify.notify("Initialized successfully!"); | ||
} else { | ||
console.error("Failed to initialize; oof"); | ||
} | ||
}); | ||
``` |
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
// Expose a notification function for programmatic use | ||
module.exports = require("./src/mnotify"); | ||
// Public API | ||
|
||
module.exports = { | ||
// Expose a notification function for programmatic use | ||
"notify": require("./src/mnotify").notify, | ||
|
||
// Expose initializastion for programmatic use | ||
"init": require("./src/init").programmaticInit | ||
} |
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