-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (46 loc) · 1.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require('express');
const Telegraf = require('telegraf');
const Rebrandly = require("rebrandly");
const rebrandlyClient = new Rebrandly({
apikey: process.env.REBRANDLY_TOKEN
});
const app = express();
const bot = new Telegraf(process.env.BOT_TOKEN, {
telegram: {
webhookReply: false
}
});
bot.start((ctx) => ctx.reply('Welcome to Tver.io Team Bot'))
bot.help((ctx) => {
ctx.reply('Create short link: /link <destination> <slashtag>')
});
bot.command('link', (ctx) => {
const {reply, message} = ctx;
const splittedMessage = message.text.split(" ");
const destination = splittedMessage[1];
const slashtag = splittedMessage[2];
rebrandlyClient.links.create({
destination,
slashtag,
domain: {
fullName: "go.tver.io"
}
}).then((result) => {
reply(result.shortUrl);
});
});
app.use(bot.webhookCallback('/callback'));
app.get('/', (req, res) => {
res.send('ok')
});
app.get('/start', async (req, res) => {
const url = `https://tverio-team-bot.now.sh/callback`;
await bot.telegram.setWebhook(url);
res.send(url)
});
if (process.env.NODE_ENV === "development") {
console.log('listening local');
bot.launch()
}
app.listen(3000, () =>
console.log('app running on 3000'));