Skip to content

Instantly share code, notes, and snippets.

@leoaiassistant
Last active November 4, 2020 11:41
Show Gist options
  • Save leoaiassistant/683cf6e2c10a1fc3d224842ec2ec80a7 to your computer and use it in GitHub Desktop.
Save leoaiassistant/683cf6e2c10a1fc3d224842ec2ec80a7 to your computer and use it in GitHub Desktop.
Dialogflow cloud functions for notifications and send emails through mail services.

πŸ€– DF + Mail πŸ“§

|πŸ‡§πŸ‡·| & Leo Camacho (G Suite) |πŸ‡¨πŸ‡·|

Codelab:

Let's start coding:

#1- Add library NodeMailer: "nodemailer": "6.4.6" at **package.json

#2- Create your Cloud Function in the Fulfillment: -Add in your index.js the const nodemailer

const nodemailer = require("nodemailer");

-Now, map your intent with a Handler: intentMap.set('Notify2Email', NotifyHandler);

-Handle the parameters to the Transporter: Capture dynamic values from the conversation such as email, name, etc: SMTP is the protocol that we are going to use to connect our Gmail hosting

function NotifyHandler (agent) { const {email, name} = agent.parameters; const transporter = nodemailer.createTransport({ host: 'smtp.mail.com ', port: 465, service: 'gmail', auth: { user: '[email protected]', pass: 'YourSecurePasswordHere' } }); const mailOptions = { from: "YourMailUserID", // Here insert the sender mail address to: email, // Users email receivers subject: "Bot Notification", // Here insert your Subject line html: '

Hello ${name}

' // Here insert the body of the Email };

El transporter es el que nos va a permitir: transporter is going to be an object that is able to send mail transport is the transport configuration object, connection url or a transport plugin instance defaults is an object that defines default values for mail options

transporter.sendMail(mailOptions, function (err, info) { if(err) console.log(err); else console.log(info); });

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment