Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var dialogflow = require('dialogflow');
- var nodemailer = require('nodemailer');
- var mailPassword = 'ksystem15';
- var mailSMTPSever = 'mail.cloud13.de';
- var mailAccountName = "";
- var transporter = nodemailer.createTransport({
- host: mailSMTPSever,
- port: 587,
- secure: false,
- auth: {
- user: mailAccountName,
- pass: mailPassword
- },
- tls: {
- // do not fail on invalid certs
- rejectUnauthorized: false
- }
- });
- //Google
- var sessionId = 1;
- const projectId = 'accelerator-chatbot';
- const languageCode = 'de-DE';
- const chatBotError = "\n WARNING: Chatbot not working because no GOOGLE_APPLICATION_CREDENTIALS env variable set! To fix it, run this in your command line:\n Win: set GOOGLE_APPLICATION_CREDENTIALS=Accelerator-Chatbot-b863bdff37fd.json\n Linux: GOOGLE_APPLICATION_CREDENTIALS=Accelerator-Chatbot-b863bdff37fd.json\n";
- if(!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
- console.log(chatBotError);
- }
- module.exports = {
- chat1 : function(msg, username, callback) {
- if(!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
- console.log(chatBotError);
- return;
- }
- chtext = msg.split("/cb ")[1];
- if(chtext && chtext != "") {
- var sessionId = username+(sessionId++);
- const sessionClient = new dialogflow.SessionsClient();
- var session = sessionClient.sessionPath(projectId, sessionId);
- // The text query request.
- const request = {
- session: session,
- queryInput: {
- text: {
- text: chtext,
- languageCode: languageCode,
- },
- },
- };
- // Send request and log result
- sessionClient
- .detectIntent(request)
- .then(responses => {
- console.log('Detected intent');
- const result = responses[0].queryResult;
- console.log(` Query: ${result.queryText}`);
- console.log(` Response: ${result.fulfillmentText}`);
- if(result.intent.displayName=="E-Mail versenden") {
- if(chtext.indexOf("Sendeadresse")!=-1){
- //Wie lautet die Sendeadresse?
- }else if(chtext.indexOf("klar")!=-1){
- var msgSplit = chtext.split(" ");
- if(msgSplit.length>0){
- var email = msgSplit[8];
- transporter.sendMail({
- from: mailAccountName,
- to: chtext.split("/cb ")[1],
- subject: "Accelerator Invitation",
- text: "SENDMESSAGETEXT"
- },
- function(err,response){
- if(err){
- callback("ERROR","chatbot", username, result.intent.displayName);
- }
- callback(result.fulfillmentText,"chatbot", username, result.intent.displayName);
- });
- }}}else {
- callback(result.fulfillmentText,"chatbot", username, result.intent.displayName);
- }
- if (result.intent) {
- console.log(` Intent: ${result.intent.displayName}`);
- } else {
- console.log(` No intent matched.`);
- }
- })
- .catch(err => {
- console.error('ERROR:', err);
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement