You can install using either npm or yarn or use the cdn
# yarn
$ yarn install pully-client
# npm
$ npm install pully-client
// import the pully client library
import Pully from 'pully-client'
// Initiate a new pully connection
const pullyConnection = new Pully({
serverUrl: "<http://localhost:3008/test>", // Pass your server url if you deployed the pully infra to your own account or leave empty to test.
token: "" // generate token by running the pully jwt command.
});
// Send a new message to the test channel.
pullyConnection.sendMessage("test", {
message: "Well Done",
});
// Listen for published messages.
pullyConnection.listen({
callback: (data) => {
// data.data -> contains the received message
// data.channel -> contains the channel name
console.log(data);
},
});