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

@tanglemesh/chatbot

v2.0.0

Published

A small chatbot widget for websites

Downloads

1

Readme

Chatbot

This is a simple chat-widget webcomponent. You can define initial messages and receive messages from a user.

Installation

Simply install this webcomponent via npm:

npm install --save @tanglemesh/chatbot

Usage

In order to use this chatbot after npm package installation you only have to import the bundled file:

<tanglemesh-chatbot 
    title="Example chatbot"
></tanglemesh-chatbot>

<script src="node_modules/@tanglmesh/chatbot/build/bundle.js"></script>
<!-- Only for browser-compatibility -->
<script src="node_modules/@tanglmesh/chatbot/build/webcomponents-loader.js"></script> 

Configuration

The chatbot-component (<tanglemesh-chatbot />) is configurable with the following attributes:

  • disabled: disabled the user's input-field so the client is not able to write any new messages
  • title: the title of the chatbot. If skipped, there is simply no header for the chatbot
  • avatar: a link to the avatar to be shown. title is required, otherwise the avatar will not be shown!
  • messages: an array of initial messages to be shown to the user (more below)
  • inputPlaceholder: a string that will be shown in the input-field if no text entered by the user
  • maxHeight: the maximum height of the messages container. Defaults to 80vh

Messages

To add messages to the chatbot simply update the messages array of the tanglemesh-chatbot element:

<tanglemesh-chatbot 
    title="Example chatbot"
    id="firstChatbot"
></tanglemesh-chatbot>

<script>
    document.addEventListener ("DOMContentLoaded", () => {
        const $chatbot = document.getElementById ("firstChatbot");
        $chatbot.addEventListener ("message-changed", (e) => {
            console.log ("message-changed", e.detail);
        });
        $chatbot.addEventListener ("message-clicked", (e) => {
            console.log ("message-clicked", e.detail);
        });
        setTimeout (() => {
            $chatbot.messages = [
                {
                    isOwnMessage: true,
                    content: "Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message Some own message",
                },
                {
                    isOwnMessage: false,
                    content: "Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message Some other message",
                },
            ];
        }, 5000);
    });
</script>

There are different formats of messages: text-messages, selection-messages and link-messages.

Text messages

The simplest form of messages are the text-messages. To define a new text-message you can simply pass an object with the following attribtues:

{
    key: "optional identifier",
    isOwnMessage: true, // is this a client or server message
    content: "The actual message to be shown",
}

Selection messages

A selection message is a text messages that can be selected even multiple times, depending on your configuration:

{
    key: "optional identifier",
    isOwnMessage: true, // is this a client or server message
    content: "The actual message to be shown",
    isSelectable: true, // configures this message as a selection-message
    min: 0, // the minimum of selections for this message
    max: 5, // the maximum of selections for this message
    value: 1, // the actual selections
}

The selection messages will have a slightly different styling with an indicator how often this message has been selected.

Link messages

A link messages provides you the functionality to link to an internal or external page:

{
    key: "optional identifier",
    isOwnMessage: true, // is this a client or server message
    content: "The actual message to be shown",
    link: "https://google.com/", // the link the user get's redirected to
    openNewTab: true, // if the user should open this page in a new tab (external) or not (internal)
    isEventLink: true, // if this is a native link (`isEventLink=false`) or if only a event should be fired once the button has clicked (event-name: click)
}

Events

There exists two events that informs you about any interaction the user has made with your chatbot:

<tanglemesh-chatbot 
    title="Example chatbot"
    id="firstChatbot"
></tanglemesh-chatbot>

<script>
    document.addEventListener ("DOMContentLoaded", () => {
        document.getElementById ("firstChatbot").addEventListener ("change", (e) => {
            console.log ("CHANGE", e.detail);
        });
        document.getElementById ("firstChatbot").addEventListener ("click", (e) => {
            console.log ("CHANGE", e.detail);
        });
    });
</script>

The message-changed event will inform you about new user messages or interactions with your selection messages. The message-clicked event informs you about a link-button (isEventLink: true) beeing clicked. The event.detail property will provide you with the available information about the user interaction:

Selection message (message-changed)

{
    isOwnMessage: true
    isSelectable: true
    isUserMessage: false
    key: "some identifier"
    max: 2
    min: 0
    value: 1
}

New user message (message-changed)

{
    isOwnMessage: true
    isSelectable: false
    isUserMessage: true
    key: undefined
    max: 5
    min: 0
    value: "test"
}

Link message (message-clicked)

{
    isOwnMessage: true,
    key: "identifier-for-link,
    value: "test"
}