@dapp-sdk/messaging-push
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Push Protocol Chat SDK

The @dapp-sdk/messaging-push allows to integrate Push Chat features into the dapp, including wallet to wallet chat and group chat. By integrating Push Chat SDK, you can setup messaging and support chat between users

Installation

To start using Push Chat SDK, follow this steps :

Install the package :

npm i @dapp-sdk/messaging-push

Import the SDK

Once installed, import the SDK and create an object of the class PushAPIModule with the config, and this object can be used to access various class methods to interact with Push Chat features

Example :

Create a user

const pushAPI = new PushAPIModule({ env: ENV.STAGING });

async function createUser(signer: ethers.Signer) {
  const user = await pushAPI.createUser({
    signer: signer,
  });

  console.log("Push API response for createUser(): ", user);
  return user;
}

Send a message

async function sendMessage(
  publicAddress: string,
  signer: ethers.Signer,
  publicAddress2: string
) {
  // Fetch user
  const user = await getUser(publicAddress);

  // Decrypt PGP Key
  const pgpDecryptedPvtKey = await pushAPI.getPgpPrivateKey({
    encryptedPGPPrivateKey: user.encryptedPrivateKey,
    signer: signer,
  });

  const response = await pushAPI.sendMessages({
    messageContent: "Hi from Push Chat!",
    messageType: "Text", // can be "Text" | "Image" | "File" | "GIF"
    receiverAddress: publicAddress2,
    signer: signer,
    pgpPrivateKey: pgpDecryptedPvtKey,
  });

  console.log("Push API response for sendMessage(): ", response);
  return response;
}

Resources

/@dapp-sdk/messaging-push/

    Package Sidebar

    Install

    npm i @dapp-sdk/messaging-push

    Weekly Downloads

    3

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    31.6 kB

    Total Files

    29

    Last publish

    Collaborators

    • pr4n