npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ablera-assistant-webchat

v0.0.14

Published

Ablera Assistant Webchat is a customizable and easy-to-integrate virtual assistant for your web applications.

Downloads

17

Readme

Ablera's Beth Chatbot

Ablera's Beth Chatbot Component is a customizable web component enabling developers to integrate Beth Virtual Assistant into their web applications.

Installation

To get started with using the Ablera's Chatbot, first you need to install the package from the npm repository.

Run the following command to install the chatbot component:

npm install ablera-assistant-webchat --save

Alternatively you can use CDN.

<script type="text/javascript" src="https://unpkg.com/ablera-assistant-webchat"></script>

Configuration Options

The ChatConfig class allows you to configure the chatbot according to your needs. Below are the configuration properties you can set:

  • userId: A unique identifier for the user chatting with the bot.
  • defaultLang: The default language for the chat interface. ('EN' | 'BG')
  • showDefaultBtn: Display the default button.
  • showPoweredBy: Display 'Powered By' information.
  • theme: The color theme for the chatbot ('blue' or 'default').
  • mode: The display mode for the chatbot ('popup' or 'sidebar').
  • synthesizerConfig: Configuration for the chatbot cognitive services of voice and avatar.
  • backgroundConfig: Configuration for the chat window background image.

Each of these properties can be defined within the configuration JSON object that you pass as the config attribute on the chatbot element.

Simple Usage

To use the chatbot in your HTML file, follow these steps:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Beth Virtual Assistant WebChat</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script type="text/javascript" src="index.js"></script>
  </head>
  <body class="mat-typography" style="margin: 0;">
    <script>
      const initializeChat = () => {
        const chat_el = document.createElement('ablera-assistant-webchat');
        const ws_url = 'URL_HERE';
        const chat_opened_by_default = true;
        const chat_config = JSON.stringify({
          userId: 'test-user-id', // required for user session & unique
          theme: 'blue', // default
          mode: 'sidebar', // sidebar
          showPoweredBy: true
        });

        chat_el.setAttribute('id', 'beth-webchat-el');
        chat_el.setAttribute('ws-url', ws_url);
        chat_el.setAttribute('config', chat_config);
        chat_el.setAttribute('chat-opened', chat_opened_by_default);
        document.body.appendChild(chat_el);
      };
      window.addEventListener('load', initializeChat);
      // window.addEventListener('DOMContentLoaded', initializeChat);
    </script>
  </body>
</html>

With lazy loading of the web component

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Beth Virtual Assistant WebChat</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body class="mat-typography" style="margin: 0;">
    <script>
      const loadScript = src => {
        return new Promise((resolve, reject) => {
          const script = document.createElement('script');
          script.type = 'text/javascript';
          script.src = src;
          script.onload = () => resolve(script);
          script.onerror = () => reject(new Error(`Script load error: ${src}`));
          document.head.appendChild(script);
        });
      };
      const initializeChat = async () => {
        await loadScript("index.js");
        const chat_el = document.createElement('ablera-assistant-webchat');
        const ws_url = 'URL_HERE';
        const chat_opened_by_default = true;
        const chat_config = JSON.stringify({
          userId: 'test-user-id', // required for user session & unique
          theme: 'blue', // default
          mode: 'sidebar', // sidebar
          showPoweredBy: true
        });

        chat_el.setAttribute('id', 'beth-webchat-el');
        chat_el.setAttribute('ws-url', ws_url);
        chat_el.setAttribute('config', chat_config);
        chat_el.setAttribute('chat-opened', chat_opened_by_default);
        document.body.appendChild(chat_el);
      };

      window.addEventListener('load', initializeChat);
      // window.addEventListener('DOMContentLoaded', initializeChat);
    </script>
  </body>
</html>

Advanced Usage

Custom Button

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Beth Virtual Assistant WebChat</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body class="mat-typography" style="margin: 0;">
    <button id="btn">
      Custom button to open avatar
    </button>

    <script>
      const loadScript = src => {
        return new Promise((resolve, reject) => {
          const script = document.createElement('script');
          script.type = 'text/javascript';
          script.src = src;
          script.onload = () => resolve(script);
          script.onerror = () => reject(new Error(`Script load error: ${src}`));
          document.head.appendChild(script);
        });
      };
      const initializeChat = async () => {
        await loadScript('index.js');
        const chat_el = document.createElement('ablera-assistant-webchat');
        const ws_url = 'URL_HERE';
        const chat_opened_by_default = true;
        const chat_config = JSON.stringify({
          userId: 'test-user-id', // required for user session & unique
          theme: 'blue', // default
          mode: 'sidebar', // sidebar
          showPoweredBy: true,
          showDefaultBtn: false
        });

        chat_el.setAttribute('id', 'beth-webchat-el');
        chat_el.setAttribute('ws-url', ws_url);
        chat_el.setAttribute('config', chat_config);
        chat_el.setAttribute('chat-opened', chat_opened_by_default);
        document.body.appendChild(chat_el);
      };

      window.addEventListener('load', async () => {
        await initializeChat();

        const btn = document.getElementById('btn');
        const chat_el = document.getElementById('beth-webchat-el');

        const toggleChat = () => {
          const isOpened = chat_el.getAttribute('chat-opened') === 'true';
          chat_el.setAttribute('chat-opened', `${!isOpened}`);
        };
        btn.addEventListener('click', toggleChat);
      });
      // window.addEventListener('DOMContentLoaded', initializeChat);
    </script>
  </body>
</html>