Gathering detailed insights and metrics for telegraf-question-sm
Gathering detailed insights and metrics for telegraf-question-sm
Gathering detailed insights and metrics for telegraf-question-sm
Gathering detailed insights and metrics for telegraf-question-sm
This package allows you to ask users questions and get an answer with Promise.
npm install telegraf-question-sm
Typescript
Module System
Node Version
NPM Version
44.9
Supply Chain
89
Quality
75
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Built with Next.js • Fully responsive • SEO optimized • Open source ready
Total Downloads
319
Last Day
1
Last Week
2
Last Month
7
Last Year
74
7 Stars
8 Commits
2 Forks
2 Watchers
1 Branches
2 Contributors
Updated on Jan 11, 2025
Latest Version
1.1.1
Package Id
telegraf-question-sm@1.1.1
Unpacked Size
4.46 kB
Size
1.48 kB
File Count
2
NPM Version
8.5.0
Node Version
16.14.2
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
75%
7
Compared to previous month
Last Year
8.8%
74
Compared to previous year
1
2
This package allows you to ask users questions and get an answer with Promise.
$ npm i telegraf-question
$ yarn add telegraf-question
1TelegrafQuestion(config?: { 2 cancelTimeout?: number; // Throw null if user doesn't reply; leave blank to wait forever. 3})
1TelegrafContext.ask( 2 question: { text: string; extra?: ExtraReplyMessage } | string, 3 cancel?: ((ctx: TelegrafContext) => Promise<boolean> | boolean) | string | null, 4 type: 'text' | 'number' | 'callback_query' = 'text', 5 errorText: { text: string; extra?: ExtraReplyMessage } | string | null = null, 6 filter?: (ctx: TelegrafContext) => Promise<boolean> | boolean 7): Promise<TelegrafContext | null> // returns null on cancel
1import Telegraf, { Markup } from "telegraf"; 2import TelegrafQuestion from "telegraf-question"; 3 4let username = 'user'; 5 6let bot = new Telegraf(<BOT_TOKEN>); 7bot.use(TelegrafQuestion({ 8 cancelTimeout: 300000 // 5 min 9})); 10 11bot.action('change_username', async (ctx, next) => { 12 ctx.answerCbQuery(); 13 let newUsername = await ctx.ask('Send new username:'); 14 if (newUsername === null) { 15 return next(); 16 } 17 username = newUsername.message.text; 18 next(); 19}); 20 21bot.use((ctx) => { 22 ctx.reply(`Hi ${username}.`, Markup.inlineKeyboard([ 23 [Markup.callbackButton('Change username', 'change_username')], 24 ]).extra()); 25}); 26 27bot.launch(); 28
1import Telegraf, { Markup } from "telegraf"; 2import TelegrafQuestion from "telegraf-question"; 3 4let username = 'user'; 5let age = 0; 6let online = false; 7 8let bot = new Telegraf(<BOT_TOKEN>); 9bot.use(TelegrafQuestion()); 10 11bot.action('change_username', async (ctx, next) => { 12 ctx.answerCbQuery(); 13 let newUsername = await ctx.ask('Send new username:'); 14 username = newUsername.message.text; 15 next(); 16}); 17 18bot.action('change_age', async (ctx, next) => { 19 ctx.answerCbQuery(); 20 let newAge = await ctx.ask( 21 { 22 text: 'Send new age:', 23 extra: { 24 reply_markup: Markup.keyboard(['Cancel']).resize(), 25 } 26 }, 27 'Cancel', 28 'number', 29 'Please send a whole number.', 30 (ctx) => { 31 let num = parseInt(ctx.message?.text); 32 return num >= 0; 33 } 34 ); 35 36 if (newAge !== null) { 37 age = parseInt(newAge.message.text); 38 } 39 next(); 40}); 41 42bot.action('change_online', async (ctx, next) => { 43 ctx.answerCbQuery(); 44 let status = await ctx.ask( 45 { 46 text: '<b>Select status:</b>', 47 extra: { 48 reply_markup: Markup.inlineKeyboard([ 49 [ 50 Markup.callbackButton('Online', 'online'), 51 Markup.callbackButton('Offline', 'offline'), 52 ], 53 [Markup.callbackButton('Cancel', 'cancel_status')] 54 ]), 55 parse_mode: 'HTML' 56 } 57 }, 58 (ctx) => ctx.callbackQuery?.data === 'cancel_status', 59 'callback_query', 60 null, 61 (ctx) => ['online', 'offline'].some(el => ctx.callbackQuery.data === el), 62 ); 63 64 if (status !== null) { 65 status.answerCbQuery(); 66 online = status.callbackQuery.data === 'online'; 67 } 68 next(); 69}); 70 71bot.use((ctx) => { 72 ctx.reply(`Hi ${username}.\nAge: ${age}\nOnline: ${online ? 'Yes' : 'No'}`, Markup.inlineKeyboard([ 73 [Markup.callbackButton('Change username', 'change_username')], 74 [Markup.callbackButton('Change age', 'change_age')], 75 [Markup.callbackButton('Change online', 'change_online')], 76 ]).extra()); 77}); 78 79bot.launch();
No vulnerabilities found.