-
Notifications
You must be signed in to change notification settings - Fork 0
/
app2.js
322 lines (287 loc) · 10.6 KB
/
app2.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
//Major project --> Tilte - Smart Bot <--
var express = require('express');
const {Router, Extra, memorySession} = require('telegraf')
const Markup = require('markup')
const Telegraf = require('telegraf')
const app = new Telegraf("371107155:AAFxgTSa0QDHwYNFywr43MpKEl6dpWqY7ck")
const imdb = require('imdb-api');
var Q = require('q');
var request = Q.denodeify(require("request"));
app.command('start', (ctx) => {
ctx.reply("Welcome "+ctx.chat.first_name+"!")
console.log(ctx.chat.location)
console.log("li")
return ctx.reply('Options',mainMenu)
})
const mainMenu = Telegraf.Extra
//.markdown()
.markup((m) => m.keyboard([
['Weather','News'],
['Movie Rating',' Get to know us']
]))
app.hears('Get to know us', (ctx) => {
return ctx.reply('Options',ourMenu)
})
const ourMenu = Telegraf.Extra
.HTML()
.markdown()
.markup((m) => m.keyboard([
['Team Members','Roll Nos'],
['Project Guide','My Details'],
['Back']
]))
app.hears('Team Members',(ctx) => {
return ctx.reply('Sumayyiah & Zahra')
} )
app.hears('Roll Nos',(ctx) => {
return ctx.reply('160413737008 & 160413737071')
} )
app.hears('Project Guide',(ctx) => {
return ctx.reply('Mr Pasha')
} )
app.hears('My Details',(ctx) => {
return ctx.reply('...', Extra.markup((markup) => {
return markup.resize()
.keyboard([
markup.contactRequestButton('My contact'),
markup.locationRequestButton('My location')
])
}))
})
app.hears('Back',(ctx) => {
return ctx.reply('Back',mainMenu)
} )
app.hears('Weather',(ctx) =>{
var message1 = "Welcome to your WeatherBot\n"
message1 += "Get weather update by entering the name of a city."
var fromId = ctx.from.id;// get the id, of who is sending the message
ctx.reply(message1);
console.log(message1)
app.on('text',ctx=>{
var city = ctx.message.text
console.log(city)
getWeatherData(city)
.then(function(data){
var message1 = "Weather today in "+city+"\n";
//message +=data.weather[2].main+"\n"
message1+= "temp: "+(data.main.temp-273.15)+" Celsius"
message1+= "\nhumidity: "+(data.main.humidity)+"%"
message1+= "\nwind: "+(data.wind.speed)+" miles/hr"
ctx.reply(message1);
console.log(message1)
});
})
});
app.hears('Movie Rating',(ctx) =>{
var message = "Welcome\n"
message += "Get movie rating by entering the name of a movie."
var fromId = ctx.from.id;// get the id, of who is sending the message
ctx.reply(message);
console.log(message)
app.on('text',ctx=>{
var movie = ctx.message.text
console.log(movie)
getMovie(movie)
.then(function(data){
var message = "Rating of "+movie+"\n";
//message +=data.weather[2].main+"\n"
message+= "Title: "+(data.Title)
message+= "\nYear: "+(data.Year)//+"%"
message+= "\nGenre: "+(data.Genre)
message+= "\n"+(data.Poster)
message+= "\nRating: "+(data.Rating[1].Source)
message+= "\t "+(data.Rating[1].Value)
ctx.reply(message);
console.log(message)
});
})
});
app.hears('News',(ctx) =>{
var message = "Welcome to your NewsBot\n"
message += "Get news update by selecting a news channel/paper."
var fromId = ctx.from.id;// get the id, of who is sending the message
ctx.reply('Get news update by selecting a news channel/paper',newsMenu);
console.log(message)
// app.on('text',ctx=>{
// var channel = ctx.message.text
// console.log(channel)
// getNews(channel)
// .then(function(data){
// var i=1
// // while(i<=10){
// var message = "News in "+channel+"\n";
// //message +=data.weather[2].main+"\n"
// message+= "Headlines: "+(data.articles[1].title)
// message+= "Link: "+(data.articles[1].urlToImage)
// // message+= "Headlines: "+(data.articles[2].title)
// // message+= "Link: "+(data.articles[2].urlToImage)//+"%"
// ctx.reply(message);
// console.log(message)
// // }
// });
// })
})
const newsMenu = Telegraf.Extra
.HTML()
.markdown()
.markup((m) => m.keyboard([
['The Times of India','CNN'],
['BBC news','BBC Sport'],
['Tech Crunch','National Geographic']
]))
// const defaultMarkup = Extra
// .HTML()
// .markup((m) => m.keyboard([
// m.callbackButton('Next article', 'clothes')
// ], {columns: 2}))
app.hears('The Times of India',ctx=>{
var channel = "The Times of India"
console.log(channel)
getNews(channel)
.then(function(data){
var i=1
// while(i<=10){
var message = "News in "+channel+"\n";
//message +=data.weather[2].main+"\n"
message+= "Headlines: "+(data.articles[1].title)
message+= "Link: "+(data.articles[1].urlToImage)
// message+= "Headlines: "+(data.articles[2].title)
// message+= "Link: "+(data.articles[2].urlToImage)//+"%"
ctx.reply(message);
console.log(message)
// }
});
})
app.hears('BBC news',ctx=>{
var channel = "BBC news"
console.log(channel)
getNews(channel)
.then(function(data){
var i=1
// while(i<=10){
var message = "News in "+channel+"\n";
//message +=data.weather[2].main+"\n"
message+= "Headlines: "+(data.articles[1].title)
message+= "Link: "+(data.articles[1].urlToImage)//+"%"
ctx.reply(message);
console.log(message)
// }
});
})
app.hears('CNN',ctx=>{
var channel = "CNN"
console.log(channel)
getNews(channel)
.then(function(data){
var i=1
// while(i<=10){
var message = "News in "+channel+"\n";
//message +=data.weather[2].main+"\n"
message+= "Headlines: "+(data.articles[1].title)
message+= "Link: "+(data.articles[1].urlToImage)//+"%"
ctx.reply(message);
console.log(message)
// }
});
})
app.hears('BBC Sport',ctx=>{
var channel = "BBC Sport"
console.log(channel)
getNews(channel)
.then(function(data){
var i=1
// while(i<=10){
var message = "News in "+channel+"\n";
//message +=data.weather[2].main+"\n"
message+= "Headlines: "+(data.articles[1].title)
message+= "Link: "+(data.articles[1].urlToImage)//+"%"
ctx.reply(message);
console.log(message)
// }
});
})
app.hears('Tech Crunch',ctx=>{
var channel = "Tech Crunch"
console.log(channel)
getNews(channel)
.then(function(data){
var i=1
// while(i<=10){
var message = "News in "+channel+"\n";
//message +=data.weather[2].main+"\n"
message+= "Headlines: "+(data.articles[1].title)
message+= "Link: "+(data.articles[1].urlToImage)//+"%"
ctx.reply(message);
console.log(message)
// }
});
})
app.hears('National Geographic',ctx=>{
var channel = "National Geographic"
console.log(channel)
getNews(channel)
.then(function(data){
var i=1
// while(i<=10){
var message = "News in "+channel+"\n";
//message +=data.weather[2].main+"\n"
message+= "Headlines: "+(data.articles[1].title)
message+= "Link: "+(data.articles[1].urlToImage)//+"%"
ctx.reply(message);
console.log(message)
// }
});
})
//This function gets the data for the requested city from api.openweathermap.org
function getWeatherData(city){
var url = "http://api.openweathermap.org/data/2.5/weather?q="+city+"&APPID=6656a4dbba28453e82898e39e3b3e6e8"
//var url = "http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1"
var options ={
url: url,
method: "GET",
json:true,
}
var response = request(options);
return response.then(function (r){
return r[0].body
});
}
function getNews(channel){
var newsOp;
if(channel=='BBC news')
{ newsOp="bbc-news"
}
if(channel=='The Times of India')
{ newsOp="the-times-of-india"}
if(channel=='CNN')
{ newsOp="cnn"}
if(channel=='BBC Sport')
{ newsOp="bbc-sport"}
if(channel=='Tech Crunch')
{ newsOp="techcrunch"}
if(channel=='National Geographic')
{ newsOp="national-geographic"}
var url = "https://newsapi.org/v1/articles?source="+newsOp+"&apiKey=59d1acae7d94454194dfd31ab070a98a"
var options ={
url: url,
method: "GET",
json:true,
}
var response = request(options);
return response.then(function (r){
return r[0].body
});
}
function getMovie(movie){
var url ="http://www.omdbapi.com/?t="+movie
var options ={
url: url,
method: "GET",
json:true,
}
var response = request(options);
return response.then(function (r){
return r[0].body
});
}
app.startPolling()