Skip to content

jcubic/dialogue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dialogue

Chat JavaScript Open Source library

Usage

Terminal and Firebase

import { Dialogue, FirebaseAdapter, Terminal } from "https://esm.sh/dialogue";

const term = $('body').terminal($.noop, {
    exceptionHandler(e) {
        this.error(`Error: ${e.message}`);
    },
    greetings: false
});

const firebase_config = {
    /* your firebase config */
};

const adapter = new FirebaseAdapter(firebase_config);
const renderer = new Terminal(term);

// example of using Joke API with Programming jokes
async function random_joke() {
    const res = await fetch('https://v2.jokeapi.dev/joke/Programming');
    const data = await res.json();
    if (data.type == 'twopart') {
        return [
            `Q: ${data.setup}`,
            `A: ${data.delivery}`
        ].join('\n');
    } else  if (data.type === 'single') {
        return data.joke;
    }
}

const dialogue = new Dialogue({
    adapter,
    renderer,
    commands(command, args) {
        // custom system command
        if (command === '/joke') {
            const joke = await random_joke();
            if (joke) {
                adapter.send(adapter.get_user(), adapter.utc_now(), joke);
            } else {
                renderer.echo('<red>Failed to get joke</red>');
            }
        }
    }
});
await dialogue.start();
term.exec('/join general');

TODO

  • Notifications
  • Push Notifications
  • Sound Notifications
  • Online users per room
  • UI
    • React
    • Vanilla Javascript Minimalistic CodePen
    • Terminal
      • chat command
  • Adapters
  • /help command connected to UI
    • Terminal using less
    • Credits at the bottom of help
    • Maybe written in Markdown
  • Setup CLA
  • Add a way to obtain a commerial License
  • website with React+Firebase Chat above the fold
  • js.org domain

License

Copyright (c) 2024 Jakub T. Jankiewicz
Released under AGPL v3 license