symon
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

banner

Symon

npm-badge ci-badge license-badge typescript-badge

🇬🇧 🇺🇦 🇩🇪 🇫🇷 🇪🇸 🇵🇹 🇮🇹 🇳🇱 🇳🇴 🇸🇪 🇮🇷 🇯🇵 🇮🇩 🇷🇺

Minimalistic chatbot framework for humans.

Getting Started

Installation

npm install symon

Configuration

import { Bot } from 'symon';
const bot = new Bot({
  languages: ['en'],
});

Natural Language Understanding

bot.addDocument({
  intent: 'chatter/greeting',
  examples: ['hello', 'hi'],
  answers: ['Hello!'],
});

bot.addDocument({
  intent: 'chatter/parting',
  examples: ['goodbye', 'bye'],
  answers: ['Bye!'],
});

Named Entity Recognition

import { EnumEntity } from 'symon';

bot.addEntity(
  new EnumEntity({
    label: 'insult',
    options: ['stupid', 'silly'],
  })
);

bot.addEntity(
  new EnumEntity{
    label: 'praise',
    options: ['smart', 'sweet'],
  })
);

bot.addDocument({
  intent: 'chatter/insult',
  examples: ['you are %insult%', '%insult%'],
  answers: ['You make me sad...'],
});

bot.addDocument({
  intent: 'chatter/praise',
  examples: ['you are %praise%', '%insult%'],
  answers: ['Thanks!'],
});

Handlers

bot.addDocument({
  intent: 'random',
  examples: ['pick a random number', 'say a random number'],
  handler: async (ctx) => {
    const number = Math.floor(Math.random() * 5);
    await ctx.say({ answer: number.toString() });
  },
});

Dialogues

bot.addDocument({
  intent: 'response/yes',
  examples: ['yes', 'yeah'],
});

bot.addDocument({
  intent: 'response/no',
  examples: ['no', 'nope'],
});

bot.addDocument({
  intent: 'suicide',
  examples: ['stop yourself', 'kill yourself'],
  handler: async (ctx) => {
    const { intent } = await ctx.classify(await ctx.ask({ answer: 'Really?' }));
    if (intent === 'response/yes') {
      process.exit(0);
    } else {
      await ctx.say({ answer: 'Hooray!' });
    }
  },
});

Middlewares

bot.addMiddleware(async (req, res) => {
  if (!res.answer) {
    res.answer = `Sorry, I don't understand you.`;
  }
});

Built-in Shell Interface

import { Shell } from 'symon';
const shell = new Shell({ bot });
shell.start();

Running examples

git clone https://github.com/sweetpalma/symon.git && cd symon && npm install
npm run example en
npm run example uk

License

Symon is licensed under the MIT license.

Package Sidebar

Install

npm i symon

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

110 kB

Total Files

32

Last publish

Collaborators

  • sweetpalma