-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1 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
require("dotenv").config();
const { Telegraf } = require("telegraf");
const axios = require("axios");
const express = require("express");
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
const bot = new Telegraf(process.env.WAGMI_TELEGRAM_BOT_TOKEN);
app.use(bot.webhookCallback("/secret-path"));
bot.telegram.setWebhook("https://wagmi-telegram-bot.onrender.com/secret-path");
app.get("/", (req, res) => {
res.send("Hello World!");
});
bot.command("start", (ctx) => {
bot.telegram.sendMessage(
ctx.chat.id,
"Hello there! Welcome to the Joke telegram bot. \nI respond to /joke. Please try it."
);
});
bot.command("joke", async (ctx) => {
const { data } = await axios.get(
`https://official-joke-api.appspot.com/jokes/random`
);
bot.telegram.sendMessage(
ctx.chat.id,
`<strong>${data.setup}</strong>${data.punchline}`,
{ parse_mode: "HTML" }
);
});
// bot.launch();
app.listen(port, () => {
console.log(`App listening on port ${port}`);
});