3.0.0 • Published 6 years ago

telegraf-recast v3.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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.

ParamTypeDescription
tokenstringRecast request access token

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

Adds intent handlers to app

ParamTypeDescription
namestringIntent name
fnfunctionIntent 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
})