Skip to content

Commit

Permalink
fix(question): question works again with unexpected deleteMessage errors
Browse files Browse the repository at this point in the history
Promise.catch can not throw stuff.
Print on console instead.
Also test its working with old menu.
  • Loading branch information
EdJoPaTo committed Sep 18, 2018
1 parent 67d06dc commit 233ed92
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inline-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class TelegrafInlineMenu {
// Looks like message is to old to be deleted
return
}
throw error
console.error('deleteMessage on question button failed', error)
})
])
}
Expand Down
27 changes: 27 additions & 0 deletions test/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,30 @@ test('multiple question setFuncs do not interfere', async t => {
text: 'less meat'
}})
})

test('question button works on old menu', async t => {
t.plan(3)
const menu = new TelegrafInlineMenu('yaay')
menu.question('Question', 'c', {
questionText: 'what do you want?',
setFunc: t.fail
})

const bot = new Telegraf()
bot.use(menu.init({actionCode: 'a:b'}))

bot.context.editMessageText = t.fail
bot.context.deleteMessage = () => {
// Method is triggered but fails as the message is to old
t.pass()
return Promise.reject(new Error('Bad Request: message can\'t be deleted'))
}
bot.context.reply = (text, extra) => {
t.is(text, 'what do you want?')
t.deepEqual(extra.reply_markup, {
force_reply: true
})
}

await bot.handleUpdate({callback_query: {data: 'a:b:c'}})
})

0 comments on commit 233ed92

Please sign in to comment.