Keyboard
import { Keyboard } from 'degreet-telegram'
import { IContext } from 'degreet-telegram/src/types'
new Keyboard('under_the_message')
.btn('cb', 'Go home', 'home').row() // row with one callback button
.saveLayout('home_btn') // save layout with name "home_btn"
bot.listen(
['Hello, world', 'Hello!'],
async (ctx: IContext): Promise<void> => {
try {
await ctx.answer.send(
ctx.msg.text,
new Keyboard('under_the_message') // under_the_chat or under_the_message
.btn('callback', 'Button text', 'button_action') // base, callback, url and more ...
.btn('callback', 'Btn 2', 'btn_2').row() // create row with 2 btns
.useLayout('home_btn') // use layout with name 'home_btn'
)
} catch (e: any) {
console.error(e)
}
}
)
bot.onClick('button_action', async (ctx: IContext): Promise<void> => {
try {
await ctx.answer.edit(new Keyboard('under_the_message')) // edit keyboard only
} catch (e: any) {
console.error(e)
}
})
bot.onClick('home', async (ctx: IContext): Promise<void> => {
try {
await ctx.answer.send('Home')
} catch (e: any) {
console.error(e)
}
})
const { Markup } = require('degreet-telegram')
new Markup('under_the_message')
.btn('cb', 'Go home', 'home').row() // row with one callback button
.saveLayout('home_btn') // save layout with name "home_btn"
bot.listen(
['Hello, world', 'Hello!'],
async (ctx) => {
try {
await ctx.answer.send(
ctx.msg.text,
new Markup('under_the_message') // reply or inline
.btn('callback', 'Button text', 'button_action') // base, callback, url and more ...
.btn('callback', 'Btn 2', 'btn_2').row() // create row with 2 btns
.useLayout('home_btn') // use layout with name 'home_btn'
.disableWebPagePreview() // disable web page preview for links (extra)
)
} catch (e) {
console.error(e)
}
}
)
bot.onClick('home', async (ctx) => {
try {
await ctx.answer.send('Home')
} catch (e) {
console.error(e)
}
})
You can also pass the 4th parameter to Keyboard.btn how true, and it will be hide
All types of Keyboard.btn: base for under_the_chat, callback and cb, requestContact, requestLocation, webApp, url, switchInlineQuery
Last updated