telebot-apireq/config.js

76 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-09-20 12:17:05 +02:00
const fs = require('fs');
const Markup = require('telegraf/markup');
const Extra = require('telegraf/extra');
const request = require('request');
//=== TOOL FUNCTIONS
//=== MAIN MODULE CONFIG
module.exports = function(url, cmds){
this.url = url;
return {
name : "APIreq",
version : 0.1,
requirements : {
gps: false,
},
text : [
{
trigger : cmds,
requirements : (bot,event,message)=>{
return new Promise((resolve, reject)=>{
return resolve(200);
});
},
action : (bot,event,message)=>{
let options = {
url: this.url,
2019-09-20 13:21:10 +02:00
body:message,
2019-09-20 12:17:05 +02:00
};
2019-09-20 12:35:13 +02:00
return new Promise((resolve,reject)=>{
return request.get(options, function (err, response, body) {
2019-09-20 12:42:17 +02:00
if (err) {
2019-09-20 12:49:10 +02:00
//bot.error(err);
return reject(err);
2019-09-20 12:42:17 +02:00
}
2019-09-20 12:17:05 +02:00
2019-09-20 12:42:17 +02:00
if (response.statusCode != 200 ){
2019-09-20 12:49:10 +02:00
//bot.error(response.statusCode);
2019-09-20 12:35:13 +02:00
return reject(500);//response.statusCode);
2019-09-20 12:42:17 +02:00
}
event.reply(body.reply).catch(err=>bot.error(err));
2019-09-20 12:35:13 +02:00
return resolve(200);
});
});
2019-09-20 12:17:05 +02:00
}
},
],
reply : [],
regex : [],
media : [],
callback : [],
inline : [],
new_member : (bot,event)=>{},
weburl : [{
url : 'self',
post_action : (bot,req,rep)=>{
},
get_action : (bot,req,rep)=>{
2019-09-20 13:21:10 +02:00
console.log(req.body);
rep.send({reply: "Beep Boop"});
2019-09-20 12:52:46 +02:00
//rep.send({msg:req.from.id});
2019-09-20 12:17:05 +02:00
},
}],
cron : []
};
}