-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
46 lines (34 loc) · 1.29 KB
/
server.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
var express = require('express');
var app = express();
var request = require('request');
const bodyParser = require('body-parser');
const accountSid = process.env.ACCOUNTSID
const authToken = process.env.AUTHTOKEN
// baseUrl - 'https://api.memegen.link/images/custom/top_caption/bottom_caption/_.png?background=image_link_with_https'
const client = require('twilio')(accountSid, authToken);
const MessagingResponse = require('twilio').twiml.MessagingResponse;
app.use(express.static('public'));
app.use(bodyParser.urlencoded({
extended: false
}));
app.post('/incoming', (req, res) => {
client.messages
const twiml = new MessagingResponse()
var userMessage = req.body.Body.split('#')
try {
const topCaption = userMessage[0].replace(/ /g, '_')
const bottomCaption = userMessage[1].replace(/ /g, '_')
const imageLink = userMessage[2]
var newUrl = `https://api.memegen.link/images/custom/${topCaption}/${bottomCaption}/_.png?background=${imageLink}`
} catch (err) {
var newUrl = 'Something went wrong. Do report the error to the author 😔💔'
}
twiml.message(newUrl)
res.writeHead(200, {
'Content-Type': 'text/xml'
})
res.end(twiml.toString())
})
var listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});