Advertisement
Guest User

Untitled

a guest
Jan 8th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. var dialogflow = require('dialogflow');
  2. var nodemailer = require('nodemailer');
  3.  
  4. var mailPassword = 'ksystem15';
  5. var mailSMTPSever = 'mail.cloud13.de';
  6. var mailAccountName = "";
  7. var transporter = nodemailer.createTransport({
  8. host: mailSMTPSever,
  9. port: 587,
  10. secure: false,
  11. auth: {
  12. user: mailAccountName,
  13. pass: mailPassword
  14. },
  15. tls: {
  16. // do not fail on invalid certs
  17. rejectUnauthorized: false
  18. }
  19. });
  20.  
  21. //Google
  22. var sessionId = 1;
  23. const projectId = 'accelerator-chatbot';
  24. const languageCode = 'de-DE';
  25.  
  26. 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";
  27. if(!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
  28. console.log(chatBotError);
  29. }
  30.  
  31. module.exports = {
  32. chat1 : function(msg, username, callback) {
  33. if(!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
  34. console.log(chatBotError);
  35. return;
  36. }
  37. chtext = msg.split("/cb ")[1];
  38. if(chtext && chtext != "") {
  39. var sessionId = username+(sessionId++);
  40. const sessionClient = new dialogflow.SessionsClient();
  41. var session = sessionClient.sessionPath(projectId, sessionId);
  42.  
  43. // The text query request.
  44. const request = {
  45. session: session,
  46. queryInput: {
  47. text: {
  48. text: chtext,
  49. languageCode: languageCode,
  50. },
  51. },
  52. };
  53.  
  54. // Send request and log result
  55. sessionClient
  56. .detectIntent(request)
  57. .then(responses => {
  58. console.log('Detected intent');
  59. const result = responses[0].queryResult;
  60. console.log(` Query: ${result.queryText}`);
  61. console.log(` Response: ${result.fulfillmentText}`);
  62. if(result.intent.displayName=="E-Mail versenden") {
  63. if(chtext.indexOf("Sendeadresse")!=-1){
  64. //Wie lautet die Sendeadresse?
  65. }else if(chtext.indexOf("klar")!=-1){
  66. var msgSplit = chtext.split(" ");
  67. if(msgSplit.length>0){
  68. var email = msgSplit[8];
  69. transporter.sendMail({
  70. from: mailAccountName,
  71. to: chtext.split("/cb ")[1],
  72. subject: "Accelerator Invitation",
  73. text: "SENDMESSAGETEXT"
  74. },
  75. function(err,response){
  76. if(err){
  77. callback("ERROR","chatbot", username, result.intent.displayName);
  78. }
  79. callback(result.fulfillmentText,"chatbot", username, result.intent.displayName);
  80. });
  81. }}}else {
  82. callback(result.fulfillmentText,"chatbot", username, result.intent.displayName);
  83. }
  84.  
  85. if (result.intent) {
  86. console.log(` Intent: ${result.intent.displayName}`);
  87. } else {
  88. console.log(` No intent matched.`);
  89. }
  90. })
  91. .catch(err => {
  92. console.error('ERROR:', err);
  93. });
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement