The Grovs SDK is a JavaScript module designed to integrate with the Grovs API, providing functionality for creating and managing links, handling user information, and managing authentication. This documentation covers the main methods and usage of the SDK.
To install the Grovs SDK, use the following command to add it as a dependency to your project:
npm install grovs --saveThis will add the Grovs SDK to your dependencies in package.json.
After installation, you can include the SDK in your project:
import Grovs from "Grovs";constructor(APIKey, linkHandlingCallback);Creates a new instance of the grovs SDK.
- APIKey (string): Your API key provided by grovs for authentication.
- linkHandlingCallback (Function): A callback function that handles the data received from grovs.
const APIKey = "your-api-key-here";
const handleLinkData = (data) => {
console.log("Link data received:", data);
};
const grovs = new Grovs(APIKey, handleLinkData);Initializes and starts the Grovs SDK by authenticating with the provided API key.
- succesfullAuthenticatedCallback (Function, optional): Callback to invoke on successful authentication.
grovs.start();Creates a new link using the Grovs API.
- title (string): The title of the link.
- subtitle (Function): The subtitle of the link.
- imageURL (string): The URL of the image associated with the link.
- data (Object): Additional data to be included with the link.
- success (Function): A callback function to be invoked upon successful creation of the link.
- error (Function): A callback function to be invoked if there is an error in creating the link.
const linkData = {
description: "This is a sample link",
category: "Demo",
};
grovs.createLink(
"Sample Link",
"This is a subtitle",
"https://example.com/image.jpg",
linkData,
(response) => {
console.log("Link created successfully:", response);
},
(err) => {
console.error("Error creating link:", err);
}
);Retrieves the current user identifier.
- Returns (string|null): The user identifier if set, otherwise null.
const userId = grovs.userIdentifier();
console.log("Current user ID:", userId);Retrieves the current user attributes.
- Returns (Object|null): A dictionary of user attributes if set, otherwise null.
const userAttributes = grovs.userAttributes();
console.log("User attributes:", userAttributes);Sets the user identifier.
- identifier (string): The user identifier to set.
grovs.setUserIdentifier("user-12345");Sets the user attributes.
- attributes (Object): A dictionary of user attributes to set.
const attributes = {
name: "John Doe",
email: "john.doe@example.com",
};
grovs.setUserAttributes(attributes);Checks if the SDK is currently authenticated.
- Returns (boolean): true if authenticated, false otherwise.
const isAuthenticated = grovs.authenticated();
console.log("Is authenticated:", isAuthenticated);Displays the messages list using the manager.
grovs.showMessagesList();Retrieves messages for a specific page using the manager.
- page (number): The page number to retrieve messages from.
- response (Function): Callback to handle the retrieved messages.
- error (Function): Callback to handle any errors during retrieval.
grovs.getMessages(
1,
(messages) => {
console.log("Retrieved messages:", messages);
},
(err) => {
console.error("Error retrieving messages:", err);
}
);Retrieves the number of unread messages using the manager.
- response (Function): Callback to handle the count of unread messages.
- error (Function): Callback to handle any errors during retrieval.
grovs.getNumberOfUnreadMessages(
(count) => {
console.log("Number of unread messages:", count);
},
(err) => {
console.error("Error retrieving unread messages count:", err);
}
);import grovs from "grovs";
const APIKey = "your-api-key";
const grovs = new grovs(APIKey, (data) => {
console.log("Link data:", data);
});
grovs.start();
if (grovs.authenticated()) {
grovs.createLink(
"Sample Link",
"Subtitle",
"https://example.com/image.jpg",
{ foo: "bar" },
(response) => console.log("Link created:", response),
(error) => console.error("Error:", error)
);
}
grovs.setUserIdentifier("user-123");
grovs.setUserAttributes({ name: "John Doe", age: 30 });
console.log("User ID:", grovs.userIdentifier());
console.log("User Attributes:", grovs.userAttributes());