@jajoosam/

wikibot

Express

Wikibot 🤖📜 💬

fork
loading
Files
  • index.js
  • public
  • views
  • package-lock.json
  • package.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.01112201990852002","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"dmFyIGV4cHJlc3MgPSByZXF1aXJlKCdleHByZXNzJyk7CnZhciBhcHAgPSBleHByZXNzKCk7CnZhciByZXF1ZXN0ID0gcmVxdWlyZSgncmVxdWVzdCcpOwpjb25zdCBib2R5UGFyc2VyID0gcmVxdWlyZSgnYm9keS1wYXJzZXInKTsKCgpjb25zdCBhY2NvdW50U2lkID0gcHJvY2Vzcy5lbnYuU0lEOwpjb25zdCBhdXRoVG9rZW4gPSBwcm9jZXNzLmVudi5LRVk7CgoKY29uc3QgY2xpZW50ID0gcmVxdWlyZSgndHdpbGlvJykocHJvY2Vzcy5lbnYuU0lELCBwcm9jZXNzLmVudi5LRVkpOwpjb25zdCBNZXNzYWdpbmdSZXNwb25zZSA9IHJlcXVpcmUoJ3R3aWxpbycpLnR3aW1sLk1lc3NhZ2luZ1Jlc3BvbnNlOwoKYXBwLnVzZShleHByZXNzLnN0YXRpYygncHVibGljJykpOwphcHAudXNlKGJvZHlQYXJzZXIudXJsZW5jb2RlZCh7IGV4dGVuZGVkOiBmYWxzZSB9KSk7CgoKCmFwcC5wb3N0KCcvaW5jb21pbmcnLCAocmVxLCByZXMpID0+IHsKICBjb25zdCB0d2ltbCA9IG5ldyBNZXNzYWdpbmdSZXNwb25zZSgpOwogIGlmKHJlcS5ib2R5LkJvZHkudG9Mb3dlckNhc2UoKS50cmltKCkhPSJoaSIgJiYgcmVxLmJvZHkuQm9keS50b0xvd2VyQ2FzZSgpLnRyaW0oKSE9ImhlbGxvIiAmJiByZXEuYm9keS5Cb2R5LnRvTG93ZXJDYXNlKCkudHJpbSgpIT0idGVzdCIgJiYgcmVxLmJvZHkuQm9keS50b0xvd2VyQ2FzZSgpLnRyaW0o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CwgcmVzcG9uc2UpIHsKICByZXNwb25zZS5zZW5kRmlsZShfX2Rpcm5hbWUgKyAnL3ZpZXdzL2luZGV4Lmh0bWwnKTsKfSk7CgoKdmFyIGxpc3RlbmVyID0gYXBwLmxpc3Rlbihwcm9jZXNzLmVudi5QT1JULCBmdW5jdGlvbigpIHsKICBjb25zb2xlLmxvZygnWW91ciBhcHAgaXMgbGlzdGVuaW5nIG9uIHBvcnQgJyArIGxpc3RlbmVyLmFkZHJlc3MoKS5wb3J0KTsKfSk7Cgo="},"asBuffer":null},"loaded":true}}
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
var express = require('express');
var app = express();
var request = require('request');
const bodyParser = require('body-parser');


const accountSid = process.env.SID;
const authToken = process.env.KEY;


const client = require('twilio')(process.env.SID, process.env.KEY);
const MessagingResponse = require('twilio').twiml.MessagingResponse;

app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }));



app.post('/incoming', (req, res) => {
  const twiml = new MessagingResponse();
  if(req.body.Body.toLowerCase().trim()!="hi" && req.body.Body.toLowerCase().trim()!="hello" && req.body.Body.toLowerCase().trim()!="test" && req.body.Body.toLowerCase().trim()!="help"){

  request('https://api.duckduckgo.com/?skip_disambig=1&format=json&pretty=1&q='+req.body.Body, function (error, response, body) {
    body = JSON.parse(body)
    console.log('body:', body["Abstract"]);
    
    if(body["Abstract"] == ""){
	    body["Abstract"]= body["RelatedTopics"][0]["Text"]
	  }
    
    var msg = twiml.message(`*`+body["Heading"]+`*

`+body["Abstract"]);
  res.writeHead(200, {'Content-Type': 'text/xml'});
  res.end(twiml.toString());
  });
  
  }
  else{
    var msg = twiml.message(`*Hey 👋*

I am a bot which summarizes WikiPedia pages to help you find quick information, right within WhatsApp.

Try it out - send me anything you want to know about`)
    res.writeHead(200, {'Content-Type': 'text/xml'});
  res.end(twiml.toString());
  }
  
});




app.get('/', function(request, response) {
  response.sendFile(__dirname + '/views/index.html');
});


var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});