Generate Post
Once the required setup is done an object can be created from window.Predis
to enable all the functionality.
const predis = new window.Predis();
predis.initialize({ appId: "YOUR_APP_ID" });
predis.on("ready", () => {
predis.createPost({
onPostPublish: function (err, data) {
console.log(err, data);
},
});
});
predis.on("error", (e) => {
console.log(e);
});
caution
Call the initialize
method before calling any other method.
The createPost
is the primary method to trigger the post creation and editing flow.
Example
A complete example is given below.
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<!-- Predis.ai SDK -->
<script
type="text/javascript"
src="https://predis.ai/sdk/embed.js"
async
defer
crossorigin="anonymous"
></script>
<body>
<!-- A button to open the post creator/editor -->
<button id="button">Generate Post</button>
<script type="text/javascript">
document.getElementById("button").addEventListener("click", function () {
// Create an object from the SDK
const predis = new window.Predis();
predis.initialize({ appId: "YOUR_APP_ID" });
// console.log("loading...");
predis.on("ready", () => {
// console.log("opening...");
predis.createPost({
onPostPublish: function (err, data) {
// published posts' data
console.log(err, data);
},
});
});
predis.on("error", (e) => {
console.log(e);
});
});
</script>
</body>
</html>