UNPKG

1.25 kBJavaScriptView Raw
1const { VkBotSdk, redisStorage } = require('../index');
2
3const main = async () => {
4 const sdk = new VkBotSdk({
5 debug: true,
6 group_id: 0,
7 access_token: ''
8 });
9
10 const bot = sdk.getCallback();
11
12 bot.use(redisStorage.middleware({
13 config: {
14 host: 'localhost',
15 port: 6379,
16 prefix: 'namespace:',
17 password: '...'
18 }
19 }));
20
21 bot.command(/index/, async (ctx, params, next) => {
22 await ctx.storage.set('active_poll', true);
23 await ctx.storage.expire('active_poll', 60 * 60);
24
25 ctx.reply('Tell me about you...');
26 });
27
28 bot.defaultReply(async (ctx, params, next) => {
29 const pollState = await ctx.storage.get('active_poll');
30
31 if(pollState) {
32 await ctx.storage.del('poll_state');
33
34 // ctx.orig_message
35 // ...
36
37 ctx.reply('Okay, I will remember this')
38 }
39 else next();
40 });
41
42 bot.defaultReply((ctx, params) => {
43 ctx.replyKeyboard(`Default reply`);
44 });
45
46 bot.initLongPoll();
47};
48
49
50main().then(() => {
51 console.log('Initialized');
52}).catch((e) => {
53 console.error(e);
54});