New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

finochat-botkit

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

finochat-botkit

finochat bot framework

  • 1.0.51
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-84.62%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

简单直接好用的机器人框架

  • 基于类型多态的有限状态机进行流程控制
  • 丰富的High-Level-API, 通过清晰的 DSL 描述任何复杂的业务流程状态转移图
  • 支持对 inbound-msg 的多种匹配方式:正文Body匹配,Action匹配,也可以直接用 Low-Level-API 进行完全灵活度的自定义匹配
  • 支持直接使用 Low-Level-API 在某个大状态下完成很多步精细交互操作(配合 async-await)
  • 支持在某一具体状态下,下挂多种匹配的表达式。包括动态长度的自定义匹配
  • 支持丰富简洁的控制流,goto,stay,repeat,stop. 对会话进行精准控制
  • 支持使用 TypeScript 开发,获得类型安全的能力

Development

# 依赖安装
cnpm install

# 开发 typescript 期间的编译 (可以将ts装到全局 cnpm install typescript -g  )
./node_modules/typescript/bin/tsc

# 在 Jetbrains系的IDE下,进入菜单(Preferences | Languages & Frameworks | TypeScript)
# 勾选 `Enable Typescript Compiler` 和 `Track changes` 开启自动编译(file watcher)

构建产物

工程作为 npm module 发布在 finogeeks 的私有 npm-registry 上面

npm install awesome-botkit@latest --registry=https://npm.finogeeks.club/

High-Level-API

状态机定义函数

  • describe 在 describe() 方法体里直接通过 DSL 描述状态机的状态转移图

状态机 DSL

  • startWith 描述状态机的初始状态和初始 data,只需调用一次
  • when 描述某个状态下,发生Event时,Bot业务执行与状态迁移的细节
  • goto 用于生成when()函数的返回值,返回 nextState
  • stay goto(CurrentState)的另一种形式,停留在本状态
  • stop goto(Done)的另一种形式,结束会话

matcher API

  • BodyCase 匹配普通聊天中的string, 支持变长 pattern(String or RegExp type)
  • ActionCase 匹配convoUI消息的action,支持变长 pattern(String or RegExp type)
  • CommandCase 匹配convoUI消息的command类型,支持变长pattern(String or RegExp type)
  • DefaultCase 模式匹配的Default分支

状态机data的共享

状态机describe()的方法体内可以使用如下两种方式共享变量(session scope)

  • 常规方式是在状态迁移时,将修改后的data对象传递给 using(). 这里建议通过 spread-rest 语法构造 immutable object 对象。后续会方便利用到状态跟踪,重演,TimeTravel Debugging 等很多玩法。
  • 还有一种可行的方式是,直接将变量挂在 fsm 上面

Low-Level-API

在回调函数内,可以不借助 matcher API,通过判断 content 或者 data 的具体细节来控制分支走向, 获得最大的灵活度:

when(MyStates.IDLE)(async (sender, content, data) => {
    if(content.body === "step1") {
        return goto(MyStates.STEP1).withConvoMsg({body: "I goto step1!"});
    } else if (content.body === "开始业务2") {
        return goto(MyStates.STEP2)
    }

    return stay().withConvoMsg({body: "Stay!"});
});

FAQs

Package last updated on 04 May 2018

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