Get Started with Weavy in Your Vue App

A step-by-step guide to integrate Weavy components into your Vue application.

Step 1: Weavy API Key

We need the backend URL and an API key to communicate with Weavy.

First, sign up for an account

Before you can work with Weavy, you'll need to sign up for a free account or sign into your existing account.

Then, select your environment and API key to proceed with the tutorial. The API key will be automatically applied to all code snippets below.

Step 2: Configure Custom Elements

To use web components properly in Vue, you need to define which custom elements to allow. This is done in your compilerOptions.

Add this to your vite.config.js:

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag.startsWith("wy-")
        }
      }
    }),
  ],
})

Note: See Vue and Web components for more information and configuration examples.

Step 3: Install UIKit Web

Run this in your terminal:

npm install @weavy/uikit-web

Step 4: Create a Demo User

For this tutorial, we're creating a demo user. We need a display name (what the end user sees) and a unique identifier.

This is what shown for the end user in title bars, search results for users, etc.

A unique identifier for the user - cannot contain whitespace and must contain at least one non-digit.

Now create the user in Weavy through the API using curl:

curl WY_BACKEND_URL/api/users -H "Authorization: Bearer WY_API_*****************" --json "{ 'uid': 'USER_ID', 'name': 'USER_NAME' }"

Notes:

  • Replace WY_BACKEND_URL with the URL to your Weavy backend
  • Replace WY_API_***************** with an API key for your Weavy backend
  • Replace USER_ID with the id of the Weavy user
  • Replace USER_NAME with the name of the Weavy user

You can find this information in your Weavy account.

Note: Creating a user through curl is purely for demo purposes. Users created in Weavy should be done from your backend using the user API endpoints.

Step 5: Issue Access Token

For our chat component to know who we're rendering for, we must issue an access token that we'll pass on to the UIKit.

Copy and paste this into a terminal window and run it:

curl -X POST WY_BACKEND_URL/api/users/USER_ID/tokens -H "Authorization: Bearer WY_API_*****************"

This will return an access token - copy and use it below.

Notes:

  • Replace WY_BACKEND_URL with the URL to your Weavy backend
  • Replace WY_API_***************** with an API key for your Weavy backend
  • Replace USER_ID with the id of the Weavy user

Note: Issuing an access token using curl is for demo purposes only. Access tokens should be created from your backend; read more about authentication and access tokens.

Step 6: Configure Weavy as a Provider

Configure Weavy at app-level to avoid multiple configurations. If you want to access the Weavy instance from your components, you can provide it in the app and inject it in your components.

Add this to main.js:

import { createApp } from "vue";
import App from "./App.vue";
import { Weavy } from "@weavy/uikit-web";

const weavy = new Weavy();
weavy.url = "WY_BACKEND_URL";
weavy.tokenFactory = async (refresh) => "USER_ACCESS_TOKEN";

const app = createApp(App);
app.provide("weavy", weavy);
app.mount("#app");

Notes:

  • Replace WY_BACKEND_URL with the URL to your Weavy backend
  • Replace USER_ACCESS_TOKEN with an access token for the Weavy user

You can find this information in your Weavy account.

Step 7: Create a Vue Component

Create a WeavyChat.vue component:

<script setup>
  import { inject } from 'vue'

  inject('weavy')

  defineProps({
    uid: String
  })
</script>

<style scoped>
  wy-chat {
    --wy-theme-color: green;
  }
</style>

<template>
  <wy-chat :uid="uid"></wy-chat>
</template>

Step 8: Use the Vue Component

To use the component simply import it and use it in a template.

Add this to any .vue file:

<script setup>
  import { WeavyChat } from './WeavyChat.vue'
</script>

<template>
  <WeavyChat uid="vue-chat" />
</template>

Done!

VoilĂ ! Now you have a chat component to integrate anywhere in your Vue app. Start building amazing collaboration features today!