-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenexbot.js
44 lines (30 loc) · 1.1 KB
/
enexbot.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
require('dotenv').config()
const TeleBot = require('telebot');
const bot = new TeleBot(process.env.BOT_TOKEN);
var request = require("request");
bot.on('text', msg => {
let id = msg.from.id;
let text = msg.text;
var options = { method: 'GET',
url: 'http://corpus.vocabulary.com/api/1.0/examples.json',
qs: { query: text,
maxResults: '5',
domain: '' },
json: true};
request(options, function (error, response, body) {
if (body.result.totalHits == 0)
{return bot.sendMessage(id, "No example found. Try a new word.");
}
else{
let Ex00 = body.result.sentences[0].sentence
let Ex01 = body.result.sentences[1].sentence
let Ex02 = body.result.sentences[2].sentence
let Ex03 = body.result.sentences[3].sentence
let Ex04 = body.result.sentences[4].sentence
console.log(Ex01);
let replyToMessage = msg.message_id;
let parseMode = 'html';
return bot.sendMessage(id, `👉 ${ Ex00 } \n 👉 ${ Ex01 } \n 👉 ${ Ex02 } \n 👉 ${ Ex03 } \n 👉 ${ Ex04 }`, {replyToMessage, parseMode});}
});
});
bot.start();