Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
721 stars 143 forks source link

error Not Implemented #74

Closed infacq closed 8 years ago

infacq commented 8 years ago

I don't know what is wrong with my code that can produce mentioned above

'use strict'

const Telegram = require('telegram-node-bot')
const TelegramBaseController = Telegram.TelegramBaseController
const tg = new Telegram.Telegram('253636404:AAFpu9GwhWZasXAQ7JvSlSIJuFSuhDH-b58')

class PembukaController extends TelegramBaseController {
    /**
     * @param {Scope} $
     */
    pembukaHandler($) {
        $.runInlineMenu({
            method: 'sendMessage', //here you must pass the method name
            params: ['Silakan pilih kitab:'],
            menu: [
                {
                    text: 'test 1', //text of the button
                    callback: (callbackQuery) => {
                        console.log(1)
                    }
                },
                {
                    text: 'Perjanjian Lama',
                    callback: (callbackQuery) => {
                        console.log(2)
                    }
                },
                {
                    text: 'Perjanjian Baharu',
                    callback: (callbackQuery) => {
                        console.log(callbackQuery)
                    }
                }
            ]
        })
    }

    get routes() {
        return {
            'start': 'pembukaHandler'
        }
    }
}

class testController extends TelegramBaseController {
    /**
     * @param {Scope} $
     */
    cariAyat($) {
        $.sendMessage('Verse ' + parseInt($.query.num2) + ': Chapter ' + parseInt($.query.num1));
    }

    get routes() {
        return {
            'qs': 'cariAyat'
        }
    }
}

class OtherwiseController extends TelegramBaseController {
    handle() {
        console.log('otherwise')
    }
}

tg.router
    .when(['start'], new PembukaController())
    .when(['/qs :num1 :num2'], new testController())
    .otherwise(new OtherwiseController())

it only happen when I run /qs 2 4

kamikazechaser commented 8 years ago
get routes() {
        return {
            '/qs :num1 :num2': 'cariAyat'
        }
}
infacq commented 8 years ago

thanks. how about

get routes() {
        return {
            ':num1 :num2': 'cariAyat'
        }
}

how to make this work?

kamikazechaser commented 8 years ago

Just use a command before the numbers. Use commands or In-line rather than just plain text.

infacq commented 8 years ago

use Inline? what do you mean? is that inlineQueries?

kamikazechaser commented 8 years ago

yes, but stick to commands at the moment

infacq commented 8 years ago

do you have example or article about inlineQueries