🇬🇧 🇺🇦 🇩🇪 🇫🇷 🇪🇸 🇵🇹 🇮🇹 🇳🇱 🇳🇴 🇸🇪 🇮🇷 🇯🇵 🇮🇩 🇷🇺
Minimalistic chatbot framework for humans.
npm install symon
import { Bot } from 'symon';
const bot = new Bot({
languages: ['en'],
});
bot.addDocument({
intent: 'chatter/greeting',
examples: ['hello', 'hi'],
answers: ['Hello!'],
});
bot.addDocument({
intent: 'chatter/parting',
examples: ['goodbye', 'bye'],
answers: ['Bye!'],
});
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!'],
});
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() });
},
});
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!' });
}
},
});
bot.addMiddleware(async (req, res) => {
if (!res.answer) {
res.answer = `Sorry, I don't understand you.`;
}
});
import { Shell } from 'symon';
const shell = new Shell({ bot });
shell.start();
git clone https://github.com/sweetpalma/symon.git && cd symon && npm install
npm run example en
npm run example uk
Symon is licensed under the MIT license.