71 lines
No EOL
2.1 KiB
JavaScript
71 lines
No EOL
2.1 KiB
JavaScript
module.exports = function(context, cb) {
|
|
// console.log(context);
|
|
// console.log(context.body.originalRequest.data);
|
|
var request = require('request');
|
|
var url = 'https://vong-generator.com/generate';
|
|
var IMGURL = "https://srv4.imgcdnhost.com/api/create/vong/?message=";
|
|
var bildpls = false;
|
|
var formData = {
|
|
text: context.body.result.parameters.message,
|
|
};
|
|
if ((formData.text === undefined) || (formData.text === "")) {
|
|
return cb("Missing parameter text.");
|
|
}
|
|
if ((context.body.result.parameters.bild) || (context.body.result.parameters.display)) {
|
|
bildpls = true;
|
|
}
|
|
request.post({
|
|
url: url,
|
|
formData: formData
|
|
}, function(error, response, body) {
|
|
if (error) {
|
|
return cb(error);
|
|
} else {
|
|
body = JSON.parse(body);
|
|
var data = {
|
|
"speech": body.vong,
|
|
"displayText": body.vong,
|
|
"source": "vong-generator"
|
|
}
|
|
if (bildpls) {
|
|
data = {
|
|
"messages": [
|
|
{
|
|
"speech": body.vong,
|
|
"type": 0
|
|
},
|
|
{
|
|
"imageUrl": IMGURL+encodeURI(body.vong),
|
|
"platform": "telegram",
|
|
"type": 3
|
|
},
|
|
{
|
|
"platform": "google",
|
|
"displayText": "Hier ist dein Bild",
|
|
"textToSpeech": "Hier ist dein Bild",
|
|
"type": "simple_response"
|
|
},
|
|
{
|
|
"buttons": [
|
|
{
|
|
"openUrlAction": {
|
|
"url": IMGURL+encodeURI(body.vong)
|
|
},
|
|
"title": "IMAGE-URL"
|
|
}
|
|
],
|
|
"image": {
|
|
"url": IMGURL+encodeURI(body.vong),
|
|
"accessibility_text": body.vong
|
|
},
|
|
"platform": "google",
|
|
"title": body.vong,
|
|
"type": "basic_card"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
return cb(null, data);
|
|
}
|
|
});
|
|
} |