-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
81 lines (70 loc) · 2.22 KB
/
app.js
File metadata and controls
81 lines (70 loc) · 2.22 KB
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
var config = require('./config');
var TelegramBot = require('node-telegram-bot-api');
var bot = new TelegramBot(config.get('telegramToken'), {polling: true});
var Weather = require('./lib/weather');
var View = require('./lib/view');
bot.on('message', function(msg, match){
if (msg.text == '/start') {
bot.sendMessage(msg.from.id, View.startMessage, {
parse_mode: "HTML"
});
} else {
Weather.getByQuery(msg.text, function(err, weatherData, geoData) {
var message = View.makeMessage(err, weatherData, geoData);
if (message) {
bot.sendMessage(msg.from.id, message, {
parse_mode: "HTML"
});
}
});
}
});
bot.on('location', function(msg, match){
Weather.getByCoordinates(msg.location.latitude, msg.location.longitude,
function(err, weatherData, geoData){
var message = View.makeMessage(err, weatherData, geoData);
if (message) {
bot.sendMessage(msg.from.id, message, {
parse_mode: "HTML"
});
}
});
});
bot.on('inline_query', function(msg, match){
if ((msg.query == '') && msg.location) {
Weather.getByCoordinates(msg.location.latitude, msg.location.longitude,
function(err, weatherData, geoData){
var inline = View.makeInline(err, weatherData, geoData);
var message = View.makeMessage(err, weatherData, geoData);
if (inline && message) {
bot.answerInlineQuery(msg.id, [{
id: msg.id,
type: "article",
description: inline[1],
input_message_content: {
message_text: message,
parse_mode: "HTML"
},
title: inline[0]
}]);
}
});
} else {
Weather.getByQuery(msg.query, function(err, weatherData, geoData) {
var message = View.makeMessage(err, weatherData, geoData);
var inline = View.makeInline(err, weatherData, geoData);
if (inline && message) {
bot.answerInlineQuery(msg.id, [{
id: msg.id,
type: "article",
description: inline[1],
input_message_content: {
message_text: message,
parse_mode: "HTML"
},
title: inline[0]
}]);
}
});
}
});