1 | const { VkBotSdk, Keyboard, TextButton, LinkButton } = require('../index');
|
2 |
|
3 | const keyboard = new Keyboard([
|
4 | [ new TextButton('index', 'primary', ['payload_action', ['arg1']]) ],
|
5 | [ new LinkButton('link', 'https://google.com') ]
|
6 | ]);
|
7 |
|
8 | const main = async () => {
|
9 | const sdk = new VkBotSdk({
|
10 | debug: true,
|
11 | group_id: 0,
|
12 | access_token: ''
|
13 | });
|
14 |
|
15 | const bot = sdk.getCallback();
|
16 |
|
17 | bot.payload('payload_action', (ctx, params, next) => {
|
18 | console.log('payload_action', params[0]);
|
19 | ctx.reply('payload_action');
|
20 | });
|
21 |
|
22 | bot.command(/index/, (ctx, params, next) => {
|
23 | const user_id = ctx.from_id;
|
24 | const peer_id = ctx.peer_id;
|
25 |
|
26 | ctx.replyKeyboard(`reply to ${user_id} in ${peer_id}`, keyboard);
|
27 | });
|
28 |
|
29 | bot.defaultReply((ctx, params) => {
|
30 | ctx.replyKeyboard(`Default reply`, keyboard);
|
31 | });
|
32 |
|
33 | bot.initLongPoll();
|
34 | };
|
35 |
|
36 |
|
37 | main().then(() => {
|
38 | console.log('Initialized');
|
39 | }).catch((e) => {
|
40 | console.error(e);
|
41 | });
|