Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
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:
Some types of applications you could build with Prague:
npm install
npm run build
(or npm run watch
to build on file changes)Prague is a low-level framework. If you want to build an app you will want to use (or create) a recipe
, which is a set of functionality that allows you to exchange messages with a given channel, using a given state store, etc. Here is a list of available recipes. Please post your own!
Let's write a simple bot that replies the same way to all inputs:
const rule = reply("Hello!");
Let's be a little more discriminating about when we say Hello, so we introduce a condition that must be satisfied before the action is taken:
const rule = rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!"));
We need a default reply for when the first rule is not satisfied. That means we have two rules, so we need a way to decide how to evaluate them. first
tries a given input on each rule, in order, until one succeeds:
const rule = first(
rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
reply("I don't understand you.")
)
Now let's add a new rule that responds to a different pattern:
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.")
)
matchRegExp
isn't just a predicate. It also extracts out matching groups, which we can use to customize the reply:
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.")
)
Now let's add another rule which looks for specific names. We do this by adding another condition that must be satisfied before the action is taken:
const rule = first(
rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
rule(matchRegExp(/I am (.*)/), match => match.groups[1] === 'Bill', reply(`HELLO MY CREATOR`)),
rule(matchRegExp(/I am (.*)/), match => match.reply(`Nice to meet you, ${match.groups[1]}!`)),
reply("I don't understand you.")
)
This works, but if the name isn't "Bill" we'll end up calling matchRegExp
twice. let's optimize this:
const rule = first(
rule(matchRegExp(/Hello|Hi|Wassup/), reply("Hello!")),
rule(matchRegExp(/I am (.*)/), first(
rule(match => match.groups[1] === 'Bill', reply(`HELLO MY CREATOR`)),
match => match.reply(`Nice to meet you, ${match.groups[1]}!`)
)),
reply("I don't understand you.")
)
This is a simple example to give you a sense of how rules are created and composed in Prague.
Any Matcher or Handler may optionally return a Promise or an Observable.
I know, I know.
FAQs
FP helpers for games and chatbots
The npm package prague receives a total of 104 weekly downloads. As such, prague popularity was classified as not popular.
We found that prague demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.