telegraf-recast
recast.ai middleware for Telegraf
Last updated 2 years ago by dotcypress .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install telegraf-recast 
SYNC missed versions from official npm registry.

recast.ai middleware for Telegraf

Build Status NPM Version

recast.ai middleware for Telegraf. Easily create Telegram bots with Natural Language Processing.

Installation

$ npm install telegraf-recast

Example

const Telegraf = require('telegraf')
const TelegrafAI = require('telegraf-recast')

const app = new Telegraf(process.env.BOT_TOKEN)
const recast = new TelegrafAI(process.env.RECASTAI_TOKEN)

// Add recast.ai middleware
app.use(recast.middleware())

// Intent handler
recast.on('termostat', (ctx) => {
  // Some logic
})

See working example.

API

TelegrafAI.new(token)

Initialize new TelegrafAI.

Param Type Description
token string Recast request access token

TelegrafAI.on(name, fn, [fn, ...])

Adds intent handlers to app

Param Type Description
name string Intent name
fn function Intent handler middleware

User context

Telegraf user context props and functions:

recast.on('intent name', (ctx) => {
  ctx.state.recast            // Current RecastAI context 
  ctx.state.recast.act        // type of text
  ctx.state.recast.intent     // first intent
  ctx.state.recast.intents    // intents
  ctx.state.recast.source     // original text
  ctx.state.recast.entities   // entities
  ctx.state.recast.raw        // raw recast.ai response
})

Current Tags

  • 3.0.0                                ...           latest (2 years ago)

7 Versions

  • 3.0.0                                ...           2 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (2)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |