Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prague

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prague

rules-based app engine

  • 0.6.1
  • npm
  • Socket score

Version published
Weekly downloads
15
increased by275%
Maintainers
1
Weekly downloads
 
Created
Source

Prague

An experimental rule system handy for intepreting user input, great for adding conversational features to apps, using lessons learned from the message router pattern. I thought of it as I walked around Prague on a sunny Spring day. This is just an experiment and not an official Microsoft project.

Major features of Prague:

  • strongly-typed rules engine for interpreting ambiguous input of all kinds
  • support for different types of applications through fine-grained interfaces rather than high-level abstraction
  • deeply asynchronous via RxJS

Some types of applications you could build with Prague:

  • OS shell
  • Browser app w/chat interface
  • Browser app w/voice interface
  • Slack bot (native interface)
  • Multi-platform Chat bot
  • Server-rendered Website w/pop-up chat

Getting up and Running

Building Prague

  • clone or fork this repo
  • npm install
  • npm run build (or npm run watch to build on file changes)

Using Prague in your app

  • npm install prague -S
  • or, if you're building your own, npm install file:../path/to/your/repo
  • import { the, stuff, you, want } from 'prague' or import * as Prague from 'prague'

Prague 101

Let's write a simple bot:

const rule = reply("Hello!");
const rule = rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!"));
const rule = rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!"));
const rule = first(
    rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
    reply("I don't understand you.")
)
const rule = first(
    rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!"));
    rule(matchRegExp(/I am (.*)/), reply("Nice to meet you!")),
    reply("I don't understand you.")
)
const rule = first(
    rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
    rule(matchRegExp(/I am (.*)/), match => match.reply(`Nice to meet you, ${match.groups[1]}!`)),
    reply("I don't understand you.")
)
const rule = first(
    rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
    rule(matchRegExp(/I am (.*)/), match => match.groups[1] === 'Bill', match => match.reply(`HELLO MY CREATOR`)),
    rule(matchRegExp(/I am (.*)/), match => match.reply(`Nice to meet you, ${match.groups[1]}!`)),
    reply("I don't understand you.")
)
const rule = first(
    rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
    rule(matchRegExp(/I am (.*)/), first(
        rule(match => match.groups[1] === 'Bill', match => match.reply(`HELLO MY CREATOR`)),
        rule(match => match.reply(`Nice to meet you, ${match.groups[1]}!`))
    )),
    reply("I don't understand you.")
)

Asynchronous functions

Any Matcher or Handler may optionally return a Promise or an Observable.

Applications and State

Now that you've been introduced to Rules, Matchers, and Handlers, the key helpers, and the type system, we can look into what it takes to build more complex apps using state.

Prompts

Here I'll talk about Prompts.

FAQs

Package last updated on 25 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc