0.0.251 • Published 6 years ago

dexter.js v0.0.251

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

WORK IN PROGRESS

HOW TO

Dependencies

  • Typescript: $ npm i -g typescript
  • NodeJS 8.6.0

Commands

  • $ yarn watch
  • $ yarn start

Bot init

import {
    Bot, Mode
} from 'dexter.js'

const bot = new Bot({
    token: Config.telegramToken,
    mode: Mode.Debug, // Or Mode.Telegram
    plugins: [ MyPlugin, AnotherPlugin ]
})

bot.start()

Reactor

import {
    ReactorPlugin,
    ReactorCtx,
    ReactorEvent,
} from 'dexter.js'

export const Hello: any = new ReactorPlugin({
    name: "hello",
    trigger: "hello",
})

Hello.on( ReactorEvent.Text, (ctx: ReactorCtx) => {
    ctx.bot.sendMessage("hello man!", ctx.sender)
})

Hello.on( ReactorEvent.Init, (ctx: ReactorCtx) => {
    console.log("Init in hello")
})

Dialog

import {
    DialogPlugin,
    DialogEvent,
    DialogCtx
} from 'dexter.js'

const States = [
    
    function (ctx: DialogCtx) {
        ctx.bot.sendMessage('What color do you like?', ctx.sender)
        ctx.session.waitForAnswer(ctx)
    },

    function (ctx: DialogCtx) {
        ctx.bot.sendMessage('Are you sure? (yes, no)', ctx.sender)
        ctx.session.waitForAnswer(ctx)
    },

    function (ctx: DialogCtx) {

        if ( ctx.message.text === "yes" ) {
            ctx.bot.sendMessage('Ok!', ctx.sender)
            ctx.session.end(ctx)
            return
        }

        if ( ctx.message.text === "no" ) {
            ctx.session.goToStart(ctx)
            return
        }   

        ctx.bot.sendMessage('Permitted answers: (yes, no)', ctx.sender)
        ctx.session.error(ctx)
    },

]

export const Color: any = new DialogPlugin({
    name: "color",
    trigger: "/color",
    states: States,
    remindEvery: 3 * 1000,
    expireAfter: 20 * 1000,
})

Color.on( DialogEvent.SessionRemind, (ctx:DialogCtx) => {
    ctx.plugin.repeatSessionFromCtx(ctx)
})

Color.on( DialogEvent.SessionExpired, (ctx:DialogCtx) => {
    ctx.bot.sendMessage("bye man", ctx.sender)
})
0.0.251

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.235

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.2

6 years ago

0.0.15

6 years ago

0.0.1

6 years ago