1 | import TelegramBot from 'node-telegram-bot-api';
|
2 | import superscript from 'superscript';
|
3 |
|
4 | const options = {
|
5 | factSystem: {
|
6 | clean: true,
|
7 | },
|
8 | importFile: './data.json',
|
9 | };
|
10 |
|
11 | superscript.setup(options, (err, bot) => {
|
12 | if (err) {
|
13 | console.error(err);
|
14 | }
|
15 | // Auth Token - You can generate your token from @BotFather
|
16 | // @BotFather is the one bot to rule them all.
|
17 | const token = '...';
|
18 |
|
19 | //= == Polling ===
|
20 | const telegram = new TelegramBot(token, {
|
21 | polling: true,
|
22 | });
|
23 |
|
24 | //= == Webhook ===
|
25 | // Choose a port
|
26 | // var port = 8080;
|
27 |
|
28 | // var telegram = new TelegramBot(token, {
|
29 | // webHook: {
|
30 | // port: port,
|
31 | // host: 'localhost'
|
32 | // }
|
33 | // });
|
34 |
|
35 | // Use `ngrok http 8080` to tunnels localhost to a https endpoint. Get it at https://ngrok.com/
|
36 | // telegram.setWebHook('https://_____.ngrok.io/' + token);
|
37 |
|
38 | telegram.on('message', (msg) => {
|
39 | const fromId = msg.from.id;
|
40 | const text = msg.text.trim();
|
41 |
|
42 | bot.reply(fromId, text, (err, reply) => {
|
43 | if (reply.string) {
|
44 | telegram.sendMessage(fromId, reply.string);
|
45 | // From file
|
46 | // var photo = __dirname+'/../test/bot.gif';
|
47 | // telegram.sendPhoto(fromId, photo, {caption: "I'm a bot!"});
|
48 |
|
49 | // For more examples, check out https://github.com/yagop/node-telegram-bot-api
|
50 | }
|
51 | });
|
52 | });
|
53 | });
|