-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (46 loc) · 1.69 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const express = require("express");
const app = express();
const { WebhookClient } = require("cloud-firebase");
const bodyParser = require("body-parser");
const nodemailer = require("nodemailer");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.get("/", (request, response) => {
response.sendFile(__dirname + "/views/index.html");
});
app.post("/iitkgp_prep_bot", function(request, response) {
const agent = new WebhookClient({ request: request, response: response });
var intentNumber = request.body.session;
var arr = intentNumber.split("/");
var numero_corrigido = arr[40];
var intentName = request.body.queryResult.intent.displayName;
var contextname = request.body.queryResult.outputContexts.displayName;
var data = request.body.queryResult.parameters;
var tata = request.body.queryResult.fulfillmentText;
if (intentName == "iknow") {
var nodemailer = require("nodemailer");
var transporte = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.user,
pass: process.env.pass
}
});
var email = {
from: process.env.user,
to: "[email protected]",
subject: "Chatbot Enquiry",
html: `Details:<p>${tata} </p>
`,
};
transporte.sendMail(email, function(error, info) {
if (error) console.log(error);
throw error;
console.log("sent" + info);
});
}
});
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});