0.1.76 • Published 1 year ago

@relaycc/receiver v0.1.76

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Overview

The best way to add Web3 messaging to your site!

Relay Receiver is a React library that makes it easy to add Web3 messaging to your website.

  • 🔥 Out-of-the-box wallet-to-wallet messaging, to a site admin or between users.
  • ✅ Easily customizable, with nice defaults.
  • 🦄 Built on top of XMTP

Quick start

Check out the example using create-react-app and wagmi. You can see it live at https://react.relay.cc, or run it yourself:

git clone https://github.com/relaycc/receiver-example-cra.git
cd receiver-example-cra
npm install
npm start
# Then navigate to http://localhost:3000 in your browser

Installation

# with npm
npm install @relaycc/receiver
# with yarn
yarn add @relaycc/receiver

Basic Usage

First, wrap your application in the <Receiver /> context provider. For example:

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { Receiver } from '@relaycc/receiver';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <Receiver>
      <App />
    </Receiver>
  </React.StrictMode>
);

Next, provide the user's connected wallet to Receiver. The wallet is used to sign in to the XMTP messaging network. How to access the connected wallet depends on how your application implements wallet connection. Here's an example using the popular wagmi library.

This code only accesses and uses the connected wallet, it assumes the steps to connect a wallet are already implemented. If you'd like to learn more, here's a great place to start.

import { useSigner } from 'wagmi';
import { useWallet } from '@relaycc/receiver';

function MyWalletComponent() {
  // Access the user's connected wallet.
  const signer = useSigner();
  const [wallet, setWallet] = useWallet();

  useEffect(() => {
    // When the user's connected wallet updates, use setWallet to provide
    // the updated wallet to Receiver
    setWallet(signer.data || null)
  }, [signer.data])

  ...
}

export default App;

Now you're ready to add the Receiver components. The default configuration adds Receiver as an intercom-style messaging widget. To implement this configuration, add <Intercom />, <Window /> and <Launcher /> to your app.

import { Intercom, Window, Launcher } from '@relaycc/receiver';

function App() {
  return (
    <div className="App">
      ...
      <Launcher />
      <Intercom>
        <Window />
      </Intercom>
    </div>
  );
}

export default App;

Launch Directly to a Conversation

The <Launcher /> component, when clicked, will by default open a Receiver <Window /> with the inbox view active. To instead jump directly into a 1:1 conversation with a specific wallet (the site's support team, for example), you can pass in the peerAddress prop:

import { Intercom, Window, Launcher } from '@relaycc/receiver';

function App() {
  return (
    <div className="App">
      <Intercom>
        <Window />
      </Intercom>
      <Launcher peerAddress={'0x1800TECHSUPPORT'} />
    </div>
  );
}

export default App;

Custom Launch Button

You can also use the useLaunch hook to turn any component into a Receiver launcher:

import { Intercom, Window, useLaunch } from '@relaycc/receiver';

function App() {
  const launch = useLaunch();
  return (
    <div className="App">
      <Intercom>
        <Window />
      </Intercom>
      <button onClick={() => launch()}>
        Open Conversations List
      </button>
      <button onClick={() => launch('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')}>
        Talk to Vitalik
      </button>
    </div>
  );
}

export default App;

Custom Positioning

The <Intercom /> component is just a utility component that positions the Receiver window and applies nice default transitions to opening and closing the window. This means that the <Window /> component can be positioned anywhere you like. For example, you could center it:

import { Window, Launcher } from '@relaycc/receiver';
import './App.css';

function App() {
  return (
    <div className="App">
      <div className="overlay">
        <Window />
        <Launcher />
      </div>
    </div>
  );
}

export default App;
/* App.css */
.overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

Custom CSS

The <Window /> component accepts a className prop you can use to apply custom CSS to the window. In the future, we will provide fine-grained access to various components. For now, the className prop will work best for applying basic styling like a border, box-shadow, or custom positioning.

/* App.css */
.bordered {
  border: 3px solid black;
}
<Window className="bordered">

Documentation

For full documentation, visit docs.relay.cc.

License

Licensed under the MIT License, Copyright © 2022-present Relay.

See LICENSE for more information.

0.1.74

1 year ago

0.1.75

1 year ago

0.1.76

1 year ago

0.1.72

1 year ago

0.1.73

1 year ago

0.1.54

2 years ago

0.1.55

2 years ago

0.1.56

2 years ago

0.1.57

2 years ago

0.1.58

2 years ago

0.1.59

2 years ago

0.1.70

2 years ago

0.1.71

1 year ago

0.1.63

2 years ago

0.1.64

2 years ago

0.1.65

2 years ago

0.1.66

2 years ago

0.1.67

2 years ago

0.1.68

2 years ago

0.1.69

2 years ago

0.1.60

2 years ago

0.1.61

2 years ago

0.1.62

2 years ago

0.1.53

2 years ago

0.1.52

2 years ago

0.1.51

2 years ago

0.1.50

2 years ago

0.1.49

2 years ago

0.1.48

2 years ago

0.1.47

2 years ago

0.1.46

2 years ago

0.1.45

2 years ago

0.1.44

2 years ago

0.1.43

2 years ago

0.1.42

2 years ago

0.1.41

2 years ago

0.1.39

2 years ago

0.1.38

2 years ago

0.1.37

2 years ago

0.1.36

2 years ago

0.1.35

2 years ago

0.1.34

2 years ago

0.1.33

2 years ago

0.1.32

2 years ago

0.1.31

2 years ago

0.1.30

2 years ago

0.1.29

2 years ago

0.1.26

2 years ago

0.1.25

2 years ago

0.1.24

2 years ago

0.1.23

2 years ago

0.1.22

2 years ago

0.1.21

2 years ago

0.1.20

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.17

2 years ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.0

2 years ago