telebot-apireq/config.js

90 lines
2.1 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",
2019-09-25 08:37:33 +02:00
key : 'apir',
2019-09-20 12:17:05 +02:00
version : 0.1,
requirements : {
gps: false,
},
text : [
{
trigger : cmds,
2019-09-25 12:37:12 +02:00
public : true,
desc : {
0: "Makes an API call and replies with a given message",
1: "Fait un appel API et repond avec le message donné",
4: "Macht ein API aufruff und antwortet mit der gegebenen message",
},
2019-09-20 12:17:05 +02:00
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:44:05 +02:00
qs:{
2019-09-20 13:24:48 +02:00
chat_id:message.chat.id,
user_id: message.from.id,
user_name: message.from.name,
message: message.text,
args: message.text_arg,
}
2019-09-20 12:17:05 +02:00
};
2019-09-20 12:35:13 +02:00
return new Promise((resolve,reject)=>{
2019-09-20 13:44:05 +02:00
return request(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
}
2019-09-20 14:27:03 +02:00
var resp = JSON.parse(body)
if(resp.reply==undefined || resp.reply=='')
resp.reply = "BeepBoop";
event.reply(resp.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:55:24 +02:00
rep.type('application/json').code(200).send({reply: req.query.args });
2019-09-20 12:17:05 +02:00
},
}],
2019-11-18 13:37:06 +01:00
cron : []
2019-09-20 12:17:05 +02:00
};
}