-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (68 loc) · 2.05 KB
/
index.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
//const telegraf =require('telegraf');
const { Composer } = require('micro-bot');
const bot = new Composer;
const axios = require('axios').default;
//const bot= new telegraf("1489562418:AAETCP44MyUOmPIsWcPZdTvinu7iT1ww9Fo");
const date=new Date();
const year=date.getFullYear().toString();
//const express=require('express');
//const app=express();
const month=(date.getMonth()).toString();
const d=date.getDate().toString();
const current=year+"-"+month+"-"+d
bot.start((ctx)=>{
console.log(current);
ctx.reply("ready to serve");
});
bot.on("sticker", (ctx) => {
ctx.reply("nice sticker");
});
bot.hears("idiot", (ctx) => {
ctx.reply("Hey who are you calling idiot wanna get kicked out 😠");
});
bot.command("hey", (ctx) => {
ctx.reply("hey you called me?");
});
bot.on("inline_query",async (ctx)=>{
//console.log();
let q=ctx.inlineQuery.query;
//console.log(await quer(q));
let a=[];
console.log(q);
if (q!==" " && q!==""){
a=await quer(q);
}
if (a!==[]){let result=await a.map((ele,index)=>{
return ({
type:"article",
title:ele.title,
id:index,
input_message_content:{
message_text:ele.title+"\n"+ele.url+"\n"+ele.description
},
url:ele.url
});
});
ctx.answerInlineQuery(result);
}
});
async function quer(que='apple'){
let res= await axios.get('http://newsapi.org/v2/everything?from='+current+'&sortBy=publishedAt&apiKey=eb5dbd33fa6f40cab72e237c524070df&q='+que)
// .then(function (response) {
// // handle success
// //articles=response.data.articles;
// })
// .catch(function (error) {
// // handle error
// //console.log(error);
// });
// console.log(res.data.articles);
//console.log(res);
return res.data.articles;
}
//bot.launch();
module.exports = bot
//app.get('/',(req,res)=>res.send('newsbot up and running'))
//app.listen(process.env.PORT||3000,(req,res)=>console.log("newsbot running"))
//heroku -----radiant-island-89459
//https://radiant-island-89459.herokuapp.com/