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

@daniel-ordonez/vue-chatui

v0.3.0

Published

A Vuejs component for creating conversational UIs based on simple 2-way chat.

Downloads

16

Readme

Vue ChatUI

A Vuejs component for creating conversational UIs based on simple 2-way chat.

npm version

vue-chatui screenshot

Table of contents

Installation

Client side

<!-- add scripts and style -->
<script src="https://unpkg.com/vue"></script>
<script src="./VueChatui.umd.js"></script>
<link rel="stylesheet" href="./VueChatui.css">
<!-- add the component tag -->
<div id="app">
  <vue-chatui></vue-chatui>
</div>
<!-- instantiate your Vue app and add component -->
<script>
// VueChatui is globally accessible
new Vue({
  components: {
    VueChatui: VueChatui
  }
}).$mount('#app')
</script>

NPM

Import the package

npm i @daniel-ordonez/vue-chatui

Register the component in Vue

import { VueChatui } from '@daniel-ordonez/vue-chatui';
export default{
	components:{
    	VueChatui
    }
}

Use the component tag

<template>
	<vue-chatui></vue-chatui>
</template>

Usage

To access your component easily use the ref attribute

<vue-chatui ref="chat"></vue-chatui>

Then assign it to a variable

// 'this' is your Vue instance
let {chat} = this.$refs;

Adding text programatically

//Passing a plain string will add a new text bubble at the left
chat.addEntry("Bot says hello!");
//You can pass an object with the property 'user:true' to add the bubble at the right
chat.addEntry( { text : "User says hi!", user : true } );

The function addEntry accepts either a string or an object with the following structure:

| Property | Type | Description | |----------|----------|-------------| |text |String |the text to show in the chat bubble| |user |Boolean |if true the chat bubble will appear at the right| |loading |Boolean |if true shows a three dots animation in the chat bubble instead of text until the loadingTimeout expires | |loadingTimeout |Number |time in milliseconds to show the animation when loading, after that loading is set to false, and text becomes readable|

If it's given a string, the rest attributes will set to defult { user: false, loading: true, loadingTimeout: 500 }

The addEntry function returns a new object with the same attributes plus a new one

| Property | Type | Description | |----------|----------|-------------| |readable |Promise |if loading, resolves after loadingTimeout when the text becomes visible, else, resolves immediately|

User input text

//This enables a textarea for the user
chat.userInput("text");

When the user submits (by pressing the send button), the text is put into an object (data) and addEntry is called

/*
data = {
 text: <whatever the user typed>,
 user: true,
 loading: false
}
*/
addEntry(data);

All that is made under the hood, userInput returns a Promise that resolves after the new chat bubble with the user text is readable.

Using with async/await

async talk = (chat) => {
  //Use the readable promise
  await chat.addEntry("What's your name?").readable;
  let name = await chat.userInput("text");
  //userInput returns an object after the user submits a response
  await chat.addEntry(`Nice to meet you ${name.text}`).readable;
  console.log("done");
}

If you want to only capture the user's input without adding a new entry, use getUserInput

async talk = (chat) => {
  await chat.addEntry("Tell me a secret").readable;
  let secret = await chat.getUserInput();
  //storeSecure( secret.text );
  await chat.addEntry("Your secret is safe with me").readable;
  console.log("done");
}

It works the same as userInput but the Promise resolves right after the user submits returning the object

{
 text: <whatever the user typed>,
 user: true,
 loading: false
}

Support

Please open an issue for support.

Be aware that some features may be under development

Contributing

  1. Please check whether another person has raised a pull request for same issue before creating one.
  2. Please check issues created before requesting for a feature.
  3. Open a pull request explaining what changes it brings.
  4. Add references where applicable.

License

GNU General Public License

Buy me a coffee

Yay! 🎉 You reached the end.