-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushChat.mjs
48 lines (28 loc) · 1.14 KB
/
pushChat.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Import Push SDK & Ethers
import { PushAPI, CONSTANTS } from "@pushprotocol/restapi";
import { ethers } from "ethers";
// server.js
import dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();
const privatekey = process.env.privetkey;
// Now you can use apiKey in your Node.js code
// Creating a random signer from a wallet, ideally this is the wallet you will connect
const signer = new ethers.Wallet(`0x${privatekey}`);
// Initialize wallet user
// 'CONSTANTS.ENV.PROD' -> mainnet apps | 'CONSTANTS.ENV.STAGING' -> testnet apps
const userAlice = await PushAPI.initialize(signer, { env: CONSTANTS.ENV.STAGING });
// This will be the wallet address of the recipient
const signerBobAddress = "0x998F8Fca5845908E83FFe299b98eC3F5c05b3093";
// Send a message to Bob
const aliceMessagesBob = await userAlice.chat.send(signerBobAddress, {
content: "Need help",
});
// Initialize Stream
const stream = await userAlice.initStream([CONSTANTS.STREAM.CHAT]);
// Configure stream listen events and what to do
stream.on(CONSTANTS.STREAM.CHAT, (message) => {
console.log(message);
});
// Connect Stream
stream.connect();