-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (53 loc) · 1.92 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
require("dotenv").config();
const express = require("express");
const expressApp = express();
const axios = require("axios");
const path = require("path");
const port = process.env.PORT || 7777;
expressApp.use(express.static("static"));
expressApp.use(express.json());
require("dotenv").config();
const { Telegraf } = require("telegraf");
const bot = new Telegraf(process.env.BOT_TOKEN);
expressApp.get("/", (req, res) => {
console.log("server started at port", port);
res.sendFile("/index.html");
});
bot.launch();
bot.command("start", (ctx) => {
console.log(ctx.from);
bot.telegram.sendMessage(
ctx.chat.id,
"Hello there! Welcome to the Code Capsules telegram bot.\nI respond to /ethereum. Please try it",
{}
);
});
bot.command("user", (ctx) => {
console.log("name >>>>> ", ctx.message.text);
const username = ctx.message.text.split(' ')[1];
const apiKey = "978136bc16msh0a47a7343676f53p17367djsn538ecaa9237a";
var rate;
axios
.get(
`https://twitter154.p.rapidapi.com/user/details?username=${username}`,
{
headers: {
"X-RapidAPI-Key": apiKey,
"X-RapidAPI-Host": "twitter154.p.rapidapi.com",
},
}
)
.then(async (response) => {
// console.log(response.data);
const username = response.data.username;
const FullName = response.data.name;
const Followers = response.data.follower_count;
const Following = response.data.following_count;
const NoofTweets = response.data.number_of_tweets;
const profileImg = response.data.profile_pic_url;
const Description = response.data.description;
if(profileImg) await ctx.replyWithPhoto({ url: profileImg });
const message = `NoofTweets : ${NoofTweets} \n Followers : ${Followers} \n Following : ${Following} \n Username : ${username} \n FullName : ${FullName} \n Description : ${Description} `;
bot.telegram.sendMessage(ctx.chat.id, message, {});
});
});