forked from jordenc/org.telegram.api.bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
54 lines (38 loc) · 1.48 KB
/
api.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
const Homey = require('homey');
module.exports = [
{
method: 'PUT',
path: '/addbot/',
fn: function(args, callback){
var http = require('http.min');
http('https://api.telegram.org/bot' + args.body.bot_token + '/setWebhook?url=https://webhooks.athom.com/webhook/' + Homey.env.CLIENT_ID).then(function (result) {
if (result.response.statusCode == 200) {
Homey.ManagerSettings.set('bot_token', args.body.bot_token);
callback ('Finished!', true);
} else {
callback ('Error ' + result.response.statusCode + ': ' + result.data, false);
}
});
}
},
{
method: 'PUT',
path: '/deletebot/',
fn: function(args, callback){
var http = require('http.min');
http('https://api.telegram.org/bot' + Homey.ManagerSettings.get('bot_token') + '/setWebhook?url=').then(function (result) {
Homey.ManagerSettings.set('bot_token', '');
callback ('Finished', true);
});
}
},
{
method: 'PUT',
path: '/renew_webhook/',
fn: function(args, callback){
var result = Homey.app.register_webhook();
if( result instanceof Error ) return callback( result );
return callback( null, result );
}
}
]