alexandercerutti/node-telegram-keyboard-wrapper

After closing reply keyboard can't to open it again

Opened this issue ยท 18 comments

toJSON: [Function: responseToJSON], caseless: Caseless { dict: [Object] }, body: { ok: false, error_code: 400, description: 'Bad Request: field "keyboard" of the ReplyKeyboardMarkup should be an Array' } } }
That's the last lines from long console outputting

Hi @furmanServices, I don't know how to help you sincerely. If I don't see the code that caused that error, I cannot help you. Could you provide it please?

If you call rk.reset() you wipe out the whole keyboard content.
You don't have to call it if you want to reuse it.

Sincerely, I don't even know the reason I inserted .reset() as a method.

I suggest you to create and populate the keyboards globally, or at least in you module, to have a static reference to them.

let rk1 = new ReplyKeyboard();
rk1.addRow(keyboards.initial);

bot.onText(/\/start/, async msg => { ... });
bot.onText(/\/cancel/, async msg => { ... });

Anyway in the first chunk of code you showed me, you are not adding new rows.

Yeah okay, so initialize the keyboard once for all globally and just use it in your "bot.sendMessage".

I even tried to act in a such way: http://joxi.ru/12Ml67YiMzOEQm the same issue.
โ€ฆ
On Fri, 11 Jan 2019 at 16:12, Alexander Cerutti @.***> wrote: Yeah okay, so initialize the keyboard once for all globally and just use it in your "bot.sendMessage" โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/Ar44oiQhZtcFsk8lj6PRO3iUpW01vipzks5vCJuvgaJpZM4Z7dBj .

Have you tried, as I said, to initialize it globally?

No, I meant to use .addRow() right below let rk = new ReplyKeyboard();

let rk = new ReplyKeyboard();
rk.addRow(keyboards.initial);

const bot = new TelegramBot(process.env.ACCELERATOR_TOKEN, {
  webHook: {
    port: process.env.ACCELERATOR_PORT
  }
})

bot.setWebHook(`${process.env.ACCELERATOR_HOST}/bot${process.env.ACCELERATOR_TOKEN}`)
bot.on(`error`, err => logger.log(`error`, err))
bot.on(`webhook_error`, err => logger.log(`error`, err))

// ๐Ÿ Start
bot.onText(/\/start/, async msg => {
  const {
    chat: { id, first_name, last_name, username }
  } = msg

...

You can create multiple keyboards, one for case. You don't have to use only one necessarily.

You're welcome! Thank you for using my library! ๐Ÿ˜Š