A nudge in time saves nine
The nudge.js SDK is a lightweight (ZERO dependencies) wrapper around nudge and its APIs.
The nudge.js SDK clients come in 2 flavors:
- The fully featured nudge.js client that exposes all API capabilities within nudge
- The "Send" client which specifically only supports sending real-time nudges
To use the nudge.js SDK you need either an API key (for sending real-time nudges via the "Send" client) or the user credentials used to log into app.nudge.net (all other functionality).
Tip
If you're not sure how to get an API key, you can read more here: Nudge API Documentation
In either case, getting started is the same:
import { createSendClient, createClient } from "@tilli-pro/nudge.js";
const apiKey = ""; // get this from the nudge dashboard
const sendClient = createSendClient({ apiKey });
// credentials used to login to app.nudge.net
const authCredentials = {
email: "",
password: "",
};
const client = createClient({ apiKey, authCredentials });
The clients can be used immediately for sending real-time nudges:
sendClient.send({
nudgeId: "1234", // you can get this from the nudge dashboard
recipient: {
email: "[email protected]",
name: "Ibrahim Ali", // OPTIONAL
},
options: { // OPTIONAL
cc: ["[email protected]"], // OPTIONAL
bcc: ["[email protected]"], // OPTIONAL
},
mergeTags: { // OPTIONAL
productName: "tilliX",
},
files: [ // OPTIONAL
new File(["test_document_text"], "test_document.txt", { type: "text/plain" }),
],
});
// => Promise<NudgeSendResult>
// { success: true; error: undefined }
// { success: false; error: { HasErrors: boolean; Code: number; Error: string; } }
That's it. Your nudge has been sent.