Skip to content

giuseppesalvo/dexter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 = 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 = 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)
})

About

nodejs framework for making bots -> conversational and not

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published