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

@bhtbot/bhtbot

v1.0.20

Published

Chatbot Library for BHT Bot

Downloads

45

Readme

BHT Chat-Bot Library

Purpose

This library is meant to kickstart new BHT-Bot Chat-Client Applications and reduce redundancy

You can setup a new Client in just a few lines of code. All you have to care about is the implementation of your specific Chat-Protocol, while Gateway Communication and Types are offered by the library.

The library contains CommonJS and ES-Modules bundles.

This Library does target NodeJS Bot Applications in first place. Some functions might break for Browser Applications or need some additional Polyfills. Feel free to open pull requests regarding any compatibility improvements.

Get in touch

Usage

Install

Add to your projects dependencies like you typically do

npm i @bhtbot/bhtbot 
 # or
yarn add @bhtbot/bhtbot

Init

On instantiating the Gateway Connection you need to pass url + name of the service. The name of service will be passed to the gateway for uniquely identifying your users. Every Bot Client must use a unique service Id for this purpose.

import BHTBot from '@bhtbot/bhtbot';
const {Gateway, BotRequest} = BHTBot;
const bot = new Gateway('http://localhost:3000', 'nameOfService');

Example Basic Request

Basic Communication with the BHT Bot Gateway is done by calling it with a POST request. You can call the gateway by building a BotRequest instance and passing it to the gateway.

async function queryBot(userId, message){
    const message = new BotRequest({
        text: message,
        serviceUserId: userId,
    });
    return await bot.query(message);
}

const response = await queryBot(333, 'Wie wird das Wetter morgen?');
console.log(response);

Websocket Connection

Some features of BHT-Bot are performed asynchronously, which requires the Chat Bot Service to be callable at any time. This is implemented by having a Websocket connection to the gateway, listening for those events.

Your Chatbot will be registered with the serviceId given at initializing the Gateway - it must be unique, otherwise you will be disconnected.

async function configureSocket(gateway: Gateway) {
    const sock = await gateway.connectWebSocket()

    sock.onMessage(async request => {
        const {userId, message} = request;
        //todo send message to client with user-id == userId
    })

    sock.onFile(async file=>{
        const {binary, userId, fileName} = file;
        //todo send file to client with user-id == userId
    })
}

configureSocket(bot);

Contribution

Since this is a university project which will be passed to new students every semester with their own philosophies and goals, this framework is subject of heavy (breaking) changes.

To keep everybody in sync, any rules and changes made to the project must be visible within this repository.

All rules and pipelines must be implemented as a script withing package.json

Building

For development you can use convenient watchers that will rebuild on file change

$ npm watch:build
$ npm watch:test

Release builds are triggered by

$ npm build:main
$ npm build:module

Lint & beautify

Some code cleanup is done by fix scripts and validated by test scripts

$npm run fix:prettier
$npm run fix:lint
$npm run test:prettier
$npm run test:lint
$npm run test:spelling

Test

There are unit tests as well as coverage checks

$ npm run test: unit
$ npm run cov

Releasing

Deployment

The final release script combines all the steps into a single pipeline which also heightens the build version in package.json and commits the version as a tag for the repository.

This will also generate the docs with npm run doc which will be published to github pages

$ # npm run reset-hard # BEWARE: this will clear your working tree. make sure every changes you want to publish are commited
$ npm run prepare-release

Publishing

After the build pipeline is finished, you will be provided with information about how to publish, which essentially means pushing your code to the git repository and publishing the build to npmjs

$ git push --tags
$ npm publish

Versioning / Changelog

The Patch-Versioning is done automagically by the prepare-release script. Feature and Major releases can be set manually or with help of npm run standard-version You should also consider adding notes to the CHANGELOG.md

Credits

Credits to Bitjson for providing a mature Typescript starter template https://github.com/bitjson/typescript-starter

Initial Work by Dennis Walz